Changeset View
Changeset View
Standalone View
Standalone View
devel/gdb/files/kgdb/fbsd-kld.c
Show All 18 Lines | |||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | |||||
#include "defs.h" | #include "defs.h" | ||||
#include "command.h" | #include "command.h" | ||||
#include "completer.h" | #include "completer.h" | ||||
#include "environ.h" | #include "environ.h" | ||||
#include "exec.h" | #include "exec.h" | ||||
#include "frame-unwind.h" | #include "frame-unwind.h" | ||||
#include "inferior.h" | #include "inferior.h" | ||||
#include "objfiles.h" | #include "objfiles.h" | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Try to find the path for a kld by looking in the kernel's directory and | * Try to find the path for a kld by looking in the kernel's directory and | ||||
* in the various paths in the module path. | * in the various paths in the module path. | ||||
*/ | */ | ||||
static gdb::optional<std::string> | static gdb::optional<std::string> | ||||
find_kld_path (const char *filename) | find_kld_path (const char *filename) | ||||
{ | { | ||||
if (exec_bfd) | bfd *exec_bfd = current_program_space->exec_bfd (); | ||||
if (exec_bfd != nullptr) | |||||
{ | { | ||||
std::string kernel_dir = ldirname (bfd_get_filename (exec_bfd)); | std::string kernel_dir = ldirname (bfd_get_filename (exec_bfd)); | ||||
if (!kernel_dir.empty ()) | if (!kernel_dir.empty ()) | ||||
{ | { | ||||
std::string path = string_printf("%s/%s", kernel_dir.c_str (), | std::string path = string_printf("%s/%s", kernel_dir.c_str (), | ||||
filename); | filename); | ||||
if (check_kld_path (path)) | if (check_kld_path (path)) | ||||
return path; | return path; | ||||
Show All 27 Lines | |||||
*/ | */ | ||||
static CORE_ADDR | static CORE_ADDR | ||||
read_pointer (CORE_ADDR address) | read_pointer (CORE_ADDR address) | ||||
{ | { | ||||
struct type *ptr_type; | struct type *ptr_type; | ||||
gdb_byte ptr_buf[8]; | gdb_byte ptr_buf[8]; | ||||
int arch_size; | int arch_size; | ||||
arch_size = bfd_get_arch_size (exec_bfd); | arch_size = bfd_get_arch_size (current_program_space->exec_bfd ()); | ||||
if (arch_size == -1) | if (arch_size == -1) | ||||
return (0); | return (0); | ||||
ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr; | ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr; | ||||
if (target_read_memory(address, ptr_buf, arch_size / 8) != 0) | if (target_read_memory(address, ptr_buf, arch_size / 8) != 0) | ||||
return (0); | return (0); | ||||
return (extract_typed_address (ptr_buf, ptr_type)); | return (extract_typed_address (ptr_buf, ptr_type)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | adjust_section_address (struct target_section *sec, CORE_ADDR *curr_base) | ||||
sec->addr = *curr_base; | sec->addr = *curr_base; | ||||
sec->endaddr = sec->addr + bfd_section_size(asect); | sec->endaddr = sec->addr + bfd_section_size(asect); | ||||
*curr_base = sec->endaddr; | *curr_base = sec->endaddr; | ||||
} | } | ||||
static void | static void | ||||
load_kld (const char *path, CORE_ADDR base_addr, int from_tty) | load_kld (const char *path, CORE_ADDR base_addr, int from_tty) | ||||
{ | { | ||||
struct target_section *sections = NULL, *sections_end = NULL, *s; | |||||
gdb_bfd_ref_ptr bfd; | |||||
CORE_ADDR curr_addr; | |||||
symfile_add_flags add_flags; | |||||
int i; | |||||
/* Open the kld. */ | /* Open the kld. */ | ||||
bfd = gdb_bfd_openr(path, gnutarget); | gdb_bfd_ref_ptr 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)) | target_section_table sections = build_section_table (bfd.get()); | ||||
error("\"%s\": can't find file sections", path); | CORE_ADDR curr_addr = base_addr; | ||||
curr_addr = base_addr; | for (target_section &s : sections) | ||||
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); | |||||
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 (const other_sections &s : sap) | ||||
printf_unfiltered("\t%s_addr = %s\n", sap[i].name.c_str(), | printf_unfiltered("\t%s_addr = %s\n", s.name.c_str(), | ||||
paddress(target_gdbarch(), sap[i].addr)); | paddress(target_gdbarch(), s.addr)); | ||||
if (from_tty && (!query("%s", ""))) | if (from_tty && (!query("%s", ""))) | ||||
error("Not confirmed."); | error("Not confirmed."); | ||||
add_flags = 0; | symfile_add_flags 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); | ||||
} | } | ||||
static void | static void | ||||
kgdb_add_kld_cmd (const char *arg, int from_tty) | kgdb_add_kld_cmd (const char *arg, int from_tty) | ||||
{ | { | ||||
CORE_ADDR base_addr; | CORE_ADDR base_addr; | ||||
if (!exec_bfd) | if (current_program_space->exec_bfd () == nullptr) | ||||
error("No kernel symbol file"); | error("No kernel symbol file"); | ||||
/* Try to open the raw path to handle absolute paths first. */ | /* Try to open the raw path to handle absolute paths first. */ | ||||
std::string path (arg); | std::string path (arg); | ||||
if (!check_kld_path(path)) { | if (!check_kld_path(path)) { | ||||
/* | /* | ||||
* If that didn't work, look in the various possible | * If that didn't work, look in the various possible | ||||
Show All 18 Lines | |||||
} | } | ||||
static void | static void | ||||
kld_relocate_section_addresses (struct so_list *so, struct target_section *sec) | kld_relocate_section_addresses (struct so_list *so, struct target_section *sec) | ||||
{ | { | ||||
lm_info_kld *li = (lm_info_kld *) so->lm_info; | lm_info_kld *li = (lm_info_kld *) so->lm_info; | ||||
static CORE_ADDR curr_addr; | static CORE_ADDR curr_addr; | ||||
if (sec == so->sections) | if (sec == &so->sections->front()) | ||||
curr_addr = li->base_address; | curr_addr = li->base_address; | ||||
adjust_section_address(sec, &curr_addr); | adjust_section_address(sec, &curr_addr); | ||||
} | } | ||||
static void | static void | ||||
kld_free_so (struct so_list *so) | kld_free_so (struct so_list *so) | ||||
{ | { | ||||
Show All 22 Lines | |||||
} | } | ||||
static void | static void | ||||
kld_solib_create_inferior_hook (int from_tty) | 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. | * symbols. | ||||
*/ | */ | ||||
try { | try { | ||||
info->off_address = parse_and_eval_long("kld_off_address"); | info->off_address = parse_and_eval_long("kld_off_address"); | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | if (!found) { | ||||
return (-1); | return (-1); | ||||
} | } | ||||
int fd = open(found->c_str (), o_flags, 0); | int fd = open(found->c_str (), o_flags, 0); | ||||
if (fd >= 0) | if (fd >= 0) | ||||
temp_pathname->reset (xstrdup (found->c_str ())); | temp_pathname->reset (xstrdup (found->c_str ())); | ||||
return (fd); | return (fd); | ||||
} | } | ||||
void _initialize_kld_target(void); | void _initialize_kld_target (); | ||||
void | void | ||||
_initialize_kld_target(void) | _initialize_kld_target () | ||||
{ | { | ||||
struct cmd_list_element *c; | struct cmd_list_element *c; | ||||
kld_so_ops.relocate_section_addresses = kld_relocate_section_addresses; | kld_so_ops.relocate_section_addresses = kld_relocate_section_addresses; | ||||
kld_so_ops.free_so = kld_free_so; | kld_so_ops.free_so = kld_free_so; | ||||
kld_so_ops.clear_so = kld_clear_so; | kld_so_ops.clear_so = kld_clear_so; | ||||
kld_so_ops.clear_solib = kld_clear_solib; | kld_so_ops.clear_solib = kld_clear_solib; | ||||
kld_so_ops.solib_create_inferior_hook = kld_solib_create_inferior_hook; | kld_so_ops.solib_create_inferior_hook = kld_solib_create_inferior_hook; | ||||
Show All 14 Lines |