Skip to content

Commit

Permalink
Don't close the kernel bfd object during startup. Instead, leave it open
Browse files Browse the repository at this point in the history
and build a section table from the kernel file so that 'info files' output
for kgdb now matches the usage of gdb on a regular file with the exception
that we don't list sections for memory in the crash dump.
  • Loading branch information
bsdjhb committed Jan 29, 2008
1 parent c989eb0 commit d6022a0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions gnu/usr.bin/gdb/kgdb/kgdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct thread_info;

extern kvm_t *kvm;
extern char *kernel;
extern bfd *kern_bfd;

struct kthr {
struct kthr *next;
Expand Down
2 changes: 0 additions & 2 deletions gnu/usr.bin/gdb/kgdb/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ static void
kgdb_init_target(void)
{
CORE_ADDR bufp;
bfd *kern_bfd;
int size, rseq, wseq;
int kern_desc;
char c;
Expand All @@ -228,7 +227,6 @@ kgdb_init_target(void)
}

set_gdbarch_from_file (kern_bfd);
bfd_close(kern_bfd);

symbol_file_add_main (kernel, 0);
if (remote)
Expand Down
17 changes: 12 additions & 5 deletions gnu/usr.bin/gdb/kgdb/trgt.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#include <err.h>
#include <kvm.h>

#include <defs.h>
#include <command.h>
#include <exec.h>
#include <frame-unwind.h>
#include <gdbthread.h>
#include <inferior.h>
Expand All @@ -45,6 +47,8 @@ __FBSDID("$FreeBSD$");

static struct target_ops kgdb_trgt_ops;

bfd *kern_bfd;

#define KERNOFF (kgdb_kernbase ())
#define INKERNEL(x) ((x) >= KERNOFF)

Expand Down Expand Up @@ -81,11 +85,8 @@ kgdb_trgt_extra_thread_info(struct thread_info *ti)
static void
kgdb_trgt_files_info(struct target_ops *target)
{
struct target_ops *tb;

tb = find_target_beneath(target);
if (tb->to_files_info != NULL)
tb->to_files_info(tb);
print_section_info(target, kern_bfd);
}

static void
Expand Down Expand Up @@ -207,7 +208,7 @@ kgdb_target(void)

kgdb_trgt_ops.to_magic = OPS_MAGIC;
kgdb_trgt_ops.to_shortname = "kernel";
kgdb_trgt_ops.to_longname = "kernel core files.";
kgdb_trgt_ops.to_longname = "kernel core files";
kgdb_trgt_ops.to_doc = "Kernel core files.";
kgdb_trgt_ops.to_stratum = thread_stratum;
kgdb_trgt_ops.to_has_memory = 1;
Expand All @@ -222,6 +223,12 @@ kgdb_target(void)
kgdb_trgt_ops.to_store_registers = kgdb_trgt_store_registers;
kgdb_trgt_ops.to_thread_alive = kgdb_trgt_thread_alive;
kgdb_trgt_ops.to_xfer_memory = kgdb_trgt_xfer_memory;

if (build_section_table(kern_bfd, &kgdb_trgt_ops.to_sections,
&kgdb_trgt_ops.to_sections_end) != 0)
errx(1, "\"%s\": can't find the file sections: %s",
kernel, bfd_errmsg(bfd_get_error()));

add_target(&kgdb_trgt_ops);
push_target(&kgdb_trgt_ops);

Expand Down

0 comments on commit d6022a0

Please sign in to comment.