Changeset View
Changeset View
Standalone View
Standalone View
head/devel/gdb/files/kgdb/fbsd-kld.c
Show All 21 Lines | |||||
* 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 <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <fcntl.h> | #include "defs.h" | ||||
#include <libgen.h> | #include "command.h" | ||||
#include "completer.h" | |||||
#include <defs.h> | #include "environ.h" | ||||
#include <command.h> | #include "exec.h" | ||||
#include <completer.h> | #include "frame-unwind.h" | ||||
#include <environ.h> | #include "inferior.h" | ||||
#include <exec.h> | #include "objfiles.h" | ||||
#include <frame-unwind.h> | #include "gdbcore.h" | ||||
#include <inferior.h> | #include "language.h" | ||||
#include <objfiles.h> | |||||
#include <gdbcore.h> | |||||
#include <language.h> | |||||
#include "solib.h" | #include "solib.h" | ||||
#include <solist.h> | #include "solist.h" | ||||
#include "kgdb.h" | #include "kgdb.h" | ||||
struct lm_info { | struct lm_info_kld : public lm_info_base { | ||||
CORE_ADDR base_address; | CORE_ADDR base_address; | ||||
}; | }; | ||||
struct kld_info { | struct kld_info { | ||||
/* Offsets of fields in linker_file structure. */ | /* Offsets of fields in linker_file structure. */ | ||||
CORE_ADDR off_address, off_filename, off_pathname, off_next; | CORE_ADDR off_address, off_filename, off_pathname, off_next; | ||||
/* KVA of 'linker_path' which corresponds to the kern.module_path sysctl .*/ | /* KVA of 'linker_path' which corresponds to the kern.module_path sysctl .*/ | ||||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | 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)); | ||||
} | } | ||||
/* | /* | ||||
* Try to find this kld in the kernel linker's list of linker files. | * Try to find this kld in the kernel linker's list of linker files. | ||||
*/ | */ | ||||
static int | static int | ||||
find_kld_address (char *arg, CORE_ADDR *address) | find_kld_address (const char *arg, CORE_ADDR *address) | ||||
{ | { | ||||
struct kld_info *info; | struct kld_info *info; | ||||
CORE_ADDR kld; | CORE_ADDR kld; | ||||
char *kld_filename; | char *kld_filename; | ||||
const char *filename; | const char *filename; | ||||
int error; | int error; | ||||
info = get_kld_info(); | info = get_kld_info(); | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | 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); | do_cleanups(cleanup); | ||||
} | } | ||||
static void | static void | ||||
kgdb_add_kld_cmd (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; | ||||
if (!exec_bfd) | if (!exec_bfd) | ||||
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. */ | ||||
Show All 18 Lines | kgdb_add_kld_cmd (const char *arg, int from_tty) | ||||
load_kld(path, base_addr, from_tty); | load_kld(path, base_addr, from_tty); | ||||
reinit_frame_cache(); | reinit_frame_cache(); | ||||
} | } | ||||
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; | |||||
static CORE_ADDR curr_addr; | static CORE_ADDR curr_addr; | ||||
if (sec == so->sections) | if (sec == so->sections) | ||||
curr_addr = so->lm_info->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) | ||||
{ | { | ||||
lm_info_kld *li = (lm_info_kld *) so->lm_info; | |||||
xfree(so->lm_info); | delete li; | ||||
} | } | ||||
static void | static void | ||||
kld_clear_so (struct so_list *so) | kld_clear_so (struct so_list *so) | ||||
{ | { | ||||
if (so->lm_info != NULL) | lm_info_kld *li = (lm_info_kld *) so->lm_info; | ||||
so->lm_info->base_address = 0; | |||||
if (li != NULL) | |||||
li->base_address = 0; | |||||
} | } | ||||
static void | static void | ||||
kld_clear_solib (void) | kld_clear_solib (void) | ||||
{ | { | ||||
struct kld_info *info; | struct kld_info *info; | ||||
info = get_kld_info(); | info = get_kld_info(); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | kld_current_sos (void) | ||||
for (kld = read_pointer(info->linker_files_addr); kld != 0; | for (kld = read_pointer(info->linker_files_addr); kld != 0; | ||||
kld = read_pointer(kld + info->off_next)) { | kld = read_pointer(kld + info->off_next)) { | ||||
/* Skip the main kernel file. */ | /* Skip the main kernel file. */ | ||||
if (kld == kernel) | if (kld == kernel) | ||||
continue; | continue; | ||||
newobj = XCNEW (struct so_list); | newobj = XCNEW (struct so_list); | ||||
newobj->lm_info = XNEW (struct lm_info); | lm_info_kld *li = new lm_info_kld; | ||||
newobj->lm_info->base_address = 0; | li->base_address = 0; | ||||
newobj->lm_info = li; | |||||
/* Read the base filename and store it in so_original_name. */ | /* Read the base filename and store it in so_original_name. */ | ||||
target_read_string(read_pointer(kld + info->off_filename), | target_read_string(read_pointer(kld + info->off_filename), | ||||
&path, sizeof(newobj->so_original_name), &error); | &path, sizeof(newobj->so_original_name), &error); | ||||
if (error != 0) { | if (error != 0) { | ||||
warning("kld_current_sos: Can't read filename: %s\n", | warning("kld_current_sos: Can't read filename: %s\n", | ||||
safe_strerror(error)); | safe_strerror(error)); | ||||
free_so(newobj); | free_so(newobj); | ||||
continue; | continue; | ||||
Show All 25 Lines | if (find_kld_path(newobj->so_original_name, newobj->so_name, | ||||
sizeof(newobj->so_name)); | sizeof(newobj->so_name)); | ||||
xfree(path); | xfree(path); | ||||
} | } | ||||
} else | } else | ||||
strlcpy(newobj->so_name, newobj->so_original_name, | strlcpy(newobj->so_name, newobj->so_original_name, | ||||
sizeof(newobj->so_name)); | sizeof(newobj->so_name)); | ||||
/* Read this kld's base address. */ | /* Read this kld's base address. */ | ||||
newobj->lm_info->base_address = read_pointer(kld + | li->base_address = read_pointer(kld + info->off_address); | ||||
info->off_address); | if (li->base_address == 0) { | ||||
if (newobj->lm_info->base_address == 0) { | |||||
warning( | warning( | ||||
"kld_current_sos: Invalid address for kld \"%s\"", | "kld_current_sos: Invalid address for kld \"%s\"", | ||||
newobj->so_original_name); | newobj->so_original_name); | ||||
free_so(newobj); | free_so(newobj); | ||||
continue; | continue; | ||||
} | } | ||||
/* Append to the list. */ | /* Append to the list. */ | ||||
*prev = newobj; | *prev = newobj; | ||||
prev = &newobj->next; | prev = &newobj->next; | ||||
} | } | ||||
return (head); | return (head); | ||||
} | } | ||||
static int | static int | ||||
kld_open_symbol_file_object (void *from_ttyp) | kld_open_symbol_file_object (int from_tty) | ||||
{ | { | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
kld_in_dynsym_resolve_code (CORE_ADDR pc) | kld_in_dynsym_resolve_code (CORE_ADDR pc) | ||||
{ | { | ||||
Show All 13 Lines | if (!find_kld_path(solib, path, sizeof(path))) { | ||||
errno = ENOENT; | errno = ENOENT; | ||||
return (-1); | return (-1); | ||||
} | } | ||||
fd = open(path, o_flags, 0); | fd = open(path, o_flags, 0); | ||||
if (fd >= 0) | if (fd >= 0) | ||||
*temp_pathname = xstrdup(path); | *temp_pathname = xstrdup(path); | ||||
return (fd); | return (fd); | ||||
} | } | ||||
void _initialize_kld_target(void); | |||||
void | void | ||||
_initialize_kld_target(void) | _initialize_kld_target(void) | ||||
{ | { | ||||
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; | ||||
Show All 17 Lines |