Changeset View
Changeset View
Standalone View
Standalone View
head/devel/gdb/files/kgdb/fbsd-kld.c
Show First 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | adjust_section_address (struct target_section *sec, CORE_ADDR *curr_base) | ||||
if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) { | if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0) { | ||||
sec->addr += *curr_base; | sec->addr += *curr_base; | ||||
sec->endaddr += *curr_base; | sec->endaddr += *curr_base; | ||||
return; | return; | ||||
} | } | ||||
*curr_base = align_power(*curr_base, | *curr_base = align_power(*curr_base, | ||||
bfd_get_section_alignment(abfd, asect)); | bfd_section_alignment(asect)); | ||||
sec->addr = *curr_base; | sec->addr = *curr_base; | ||||
sec->endaddr = sec->addr + bfd_section_size(abfd, asect); | sec->endaddr = sec->addr + bfd_section_size(asect); | ||||
*curr_base = sec->endaddr; | *curr_base = sec->endaddr; | ||||
} | } | ||||
static void | static void | ||||
load_kld (char *path, CORE_ADDR base_addr, int from_tty) | load_kld (char *path, CORE_ADDR base_addr, int from_tty) | ||||
{ | { | ||||
struct target_section *sections = NULL, *sections_end = NULL, *s; | struct target_section *sections = NULL, *sections_end = NULL, *s; | ||||
struct cleanup *cleanup; | |||||
gdb_bfd_ref_ptr bfd; | gdb_bfd_ref_ptr bfd; | ||||
CORE_ADDR curr_addr; | CORE_ADDR curr_addr; | ||||
symfile_add_flags add_flags; | symfile_add_flags add_flags; | ||||
int i; | int i; | ||||
/* Open the kld. */ | /* Open the kld. */ | ||||
bfd = gdb_bfd_openr(path, gnutarget); | bfd = gdb_bfd_openr(path, gnutarget); | ||||
if (bfd == NULL) | if (bfd == NULL) | ||||
error("\"%s\": can't open: %s", path, | error("\"%s\": can't open: %s", path, | ||||
bfd_errmsg(bfd_get_error())); | bfd_errmsg(bfd_get_error())); | ||||
if (!bfd_check_format(bfd.get(), bfd_object)) | if (!bfd_check_format(bfd.get(), bfd_object)) | ||||
error("\%s\": not an object file", path); | error("\%s\": not an object file", path); | ||||
/* Make sure we have a .text section. */ | /* Make sure we have a .text section. */ | ||||
if (bfd_get_section_by_name (bfd.get(), ".text") == NULL) | if (bfd_get_section_by_name (bfd.get(), ".text") == NULL) | ||||
error("\"%s\": can't find text section", path); | error("\"%s\": can't find text section", path); | ||||
/* Build a section table from the bfd and relocate the sections. */ | /* Build a section table from the bfd and relocate the sections. */ | ||||
if (build_section_table (bfd.get(), §ions, §ions_end)) | if (build_section_table (bfd.get(), §ions, §ions_end)) | ||||
error("\"%s\": can't find file sections", path); | error("\"%s\": can't find file sections", path); | ||||
cleanup = make_cleanup(xfree, sections); | |||||
curr_addr = base_addr; | curr_addr = base_addr; | ||||
for (s = sections; s < sections_end; s++) | for (s = sections; s < sections_end; s++) | ||||
adjust_section_address(s, &curr_addr); | adjust_section_address(s, &curr_addr); | ||||
/* Build a section addr info to pass to symbol_file_add(). */ | /* Build a section addr info to pass to symbol_file_add(). */ | ||||
section_addr_info sap | section_addr_info sap | ||||
= build_section_addr_info_from_section_table (sections, | = build_section_addr_info_from_section_table (sections, | ||||
sections_end); | sections_end); | ||||
xfree(sections); | |||||
printf_unfiltered("add symbol table from file \"%s\" at\n", path); | printf_unfiltered("add symbol table from file \"%s\" at\n", path); | ||||
for (i = 0; i < sap.size(); i++) | for (i = 0; i < sap.size(); i++) | ||||
printf_unfiltered("\t%s_addr = %s\n", sap[i].name.c_str(), | printf_unfiltered("\t%s_addr = %s\n", sap[i].name.c_str(), | ||||
paddress(target_gdbarch(), sap[i].addr)); | paddress(target_gdbarch(), sap[i].addr)); | ||||
if (from_tty && (!query("%s", ""))) | if (from_tty && (!query("%s", ""))) | ||||
error("Not confirmed."); | error("Not confirmed."); | ||||
add_flags = 0; | add_flags = 0; | ||||
if (from_tty) | if (from_tty) | ||||
add_flags |= SYMFILE_VERBOSE; | add_flags |= SYMFILE_VERBOSE; | ||||
symbol_file_add_from_bfd(bfd.get(), path, add_flags, &sap, | symbol_file_add_from_bfd(bfd.get(), path, add_flags, &sap, | ||||
OBJF_USERLOADED, NULL); | OBJF_USERLOADED, NULL); | ||||
do_cleanups(cleanup); | |||||
} | } | ||||
static void | static void | ||||
kgdb_add_kld_cmd (const char *arg, int from_tty) | kgdb_add_kld_cmd (const char *arg, int from_tty) | ||||
{ | { | ||||
char path[PATH_MAX]; | char path[PATH_MAX]; | ||||
CORE_ADDR base_addr; | CORE_ADDR base_addr; | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | kld_solib_create_inferior_hook (int from_tty) | ||||
struct kld_info *info; | struct kld_info *info; | ||||
info = get_kld_info(); | info = get_kld_info(); | ||||
/* | /* | ||||
* Compute offsets of relevant members in struct linker_file | * Compute offsets of relevant members in struct linker_file | ||||
* and the addresses of global variables. Newer kernels | * and the addresses of global variables. Newer kernels | ||||
* include constants we can use without requiring debug | * include constants we can use without requiring debug | ||||
* symbols. If those aren't present, fall back to using | * symbols. | ||||
* home-grown offsetof() equivalents. | |||||
*/ | */ | ||||
TRY { | try { | ||||
info->off_address = parse_and_eval_long("kld_off_address"); | info->off_address = parse_and_eval_long("kld_off_address"); | ||||
info->off_filename = parse_and_eval_long("kld_off_filename"); | info->off_filename = parse_and_eval_long("kld_off_filename"); | ||||
info->off_pathname = parse_and_eval_long("kld_off_pathname"); | info->off_pathname = parse_and_eval_long("kld_off_pathname"); | ||||
info->off_next = parse_and_eval_long("kld_off_next"); | info->off_next = parse_and_eval_long("kld_off_next"); | ||||
} CATCH(e, RETURN_MASK_ERROR) { | } catch (const gdb_exception_error &e) { | ||||
TRY { | try { | ||||
info->off_address = parse_and_eval_address( | struct symbol *linker_file_sym = | ||||
"&((struct linker_file *)0)->address"); | lookup_symbol_in_language ("struct linker_file", | ||||
info->off_filename = parse_and_eval_address( | NULL, STRUCT_DOMAIN, language_c, NULL).symbol; | ||||
"&((struct linker_file *)0)->filename"); | if (linker_file_sym == NULL) | ||||
info->off_pathname = parse_and_eval_address( | error (_( | ||||
"&((struct linker_file *)0)->pathname"); | "Unable to find struct linker_file symbol")); | ||||
info->off_next = parse_and_eval_address( | |||||
"&((struct linker_file *)0)->link.tqe_next"); | info->off_address = | ||||
} CATCH(e2, RETURN_MASK_ERROR) { | lookup_struct_elt (SYMBOL_TYPE (linker_file_sym), | ||||
"address", 0).offset / 8; | |||||
info->off_filename = | |||||
lookup_struct_elt (SYMBOL_TYPE (linker_file_sym), | |||||
"filename", 0).offset / 8; | |||||
info->off_pathname = | |||||
lookup_struct_elt (SYMBOL_TYPE (linker_file_sym), | |||||
"pathname", 0).offset / 8; | |||||
struct type *link_type = | |||||
lookup_struct_elt_type (SYMBOL_TYPE (linker_file_sym), | |||||
"link", 0); | |||||
if (link_type == NULL) | |||||
error (_("Unable to find link type")); | |||||
info->off_next = | |||||
lookup_struct_elt (link_type, "tqe_next", | |||||
0).offset / 8; | |||||
} catch (const gdb_exception_error &e2) { | |||||
return; | return; | ||||
} | } | ||||
END_CATCH | |||||
} | } | ||||
END_CATCH | |||||
TRY { | try { | ||||
info->module_path_addr = parse_and_eval_address("linker_path"); | info->module_path_addr = parse_and_eval_address("linker_path"); | ||||
info->linker_files_addr = kgdb_lookup("linker_files"); | info->linker_files_addr = kgdb_lookup("linker_files"); | ||||
info->kernel_file_addr = kgdb_lookup("linker_kernel_file"); | info->kernel_file_addr = kgdb_lookup("linker_kernel_file"); | ||||
} CATCH(e, RETURN_MASK_ERROR) { | } catch (const gdb_exception_error &e) { | ||||
return; | return; | ||||
} | } | ||||
END_CATCH | |||||
solib_add(NULL, from_tty, auto_solib_add); | solib_add(NULL, from_tty, auto_solib_add); | ||||
} | } | ||||
static struct so_list * | static struct so_list * | ||||
kld_current_sos (void) | kld_current_sos (void) | ||||
{ | { | ||||
struct so_list *head, **prev, *newobj; | struct so_list *head, **prev, *newobj; | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |