mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-14 10:09:48 +00:00
o As mentioned in the previous commit: make the KVM error buffer
static. o Register a function with atexit(3) to close the KVM object if we have one open. o Show the unread portion of the kernel's message buffer before presenting the prompt. It's bound to provide some useful info. o Don't call kgdb_target() twice. It results in having all threads listed twice. MFC after: 1 week
This commit is contained in:
parent
6ae4f72691
commit
9ca14a4113
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=148801
@ -66,6 +66,7 @@ extern void symbol_file_add_main (char *args, int from_tty);
|
||||
#include "kgdb.h"
|
||||
|
||||
kvm_t *kvm;
|
||||
static char kvm_err[_POSIX2_LINE_MAX];
|
||||
|
||||
static int dumpnr;
|
||||
static int verbose;
|
||||
@ -77,6 +78,13 @@ static char *vmcore;
|
||||
|
||||
static void (*kgdb_new_objfile_chain)(struct objfile * objfile);
|
||||
|
||||
static void
|
||||
kgdb_atexit(void)
|
||||
{
|
||||
if (kvm != NULL)
|
||||
kvm_close(kvm);
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
@ -167,11 +175,33 @@ kgdb_new_objfile(struct objfile *objfile)
|
||||
kgdb_new_objfile_chain(objfile);
|
||||
}
|
||||
|
||||
static CORE_ADDR
|
||||
kgdb_parse(const char *exp)
|
||||
{
|
||||
struct cleanup *old_chain;
|
||||
struct expression *expr;
|
||||
struct value *val;
|
||||
char *s;
|
||||
CORE_ADDR n;
|
||||
|
||||
s = strdup(exp);
|
||||
old_chain = make_cleanup(free_current_contents, &expr);
|
||||
expr = parse_expression(s);
|
||||
val = (expr != NULL) ? evaluate_expression(expr) : NULL;
|
||||
n = (val != NULL) ? value_as_address(val) : 0;
|
||||
do_cleanups(old_chain);
|
||||
free(s);
|
||||
return (n);
|
||||
}
|
||||
|
||||
static void
|
||||
kgdb_init_target(void)
|
||||
{
|
||||
CORE_ADDR bufp;
|
||||
bfd *kern_bfd;
|
||||
int size, rseq, wseq;
|
||||
int kern_desc;
|
||||
char c;
|
||||
|
||||
kern_desc = open(kernel, O_RDONLY);
|
||||
if (kern_desc == -1)
|
||||
@ -199,6 +229,29 @@ kgdb_init_target(void)
|
||||
push_remote_target (remote, 0);
|
||||
else
|
||||
kgdb_target();
|
||||
|
||||
/*
|
||||
* Display the unread portion of the message buffer. This gives the
|
||||
* user a some initial data to work from.
|
||||
*/
|
||||
bufp = kgdb_parse("msgbufp->msg_ptr");
|
||||
size = (int)kgdb_parse("msgbufp->msg_size");
|
||||
rseq = (int)kgdb_parse("msgbufp->msg_rseq");
|
||||
wseq = (int)kgdb_parse("msgbufp->msg_wseq");
|
||||
if (bufp == 0 || size == 0 || rseq == wseq)
|
||||
return;
|
||||
|
||||
printf("\nUnread portion of the kernel message buffer:\n");
|
||||
while (rseq < wseq) {
|
||||
read_memory(bufp + rseq, &c, 1);
|
||||
putchar(c);
|
||||
rseq++;
|
||||
if (rseq == size)
|
||||
rseq = 0;
|
||||
}
|
||||
if (c != '\n')
|
||||
putchar('\n');
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
static void
|
||||
@ -209,9 +262,8 @@ kgdb_interp_command_loop(void *data)
|
||||
if (!once) {
|
||||
once = 1;
|
||||
kgdb_init_target();
|
||||
kgdb_target();
|
||||
print_stack_frame (get_selected_frame (),
|
||||
frame_relative_level (get_selected_frame ()), 1);
|
||||
print_stack_frame(get_selected_frame(),
|
||||
frame_relative_level(get_selected_frame()), 1);
|
||||
}
|
||||
command_loop();
|
||||
}
|
||||
@ -405,10 +457,10 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (remote == NULL) {
|
||||
s = malloc(_POSIX2_LINE_MAX);
|
||||
kvm = kvm_openfiles(kernel, vmcore, NULL, O_RDONLY, s);
|
||||
kvm = kvm_openfiles(kernel, vmcore, NULL, O_RDONLY, kvm_err);
|
||||
if (kvm == NULL)
|
||||
errx(1, s);
|
||||
errx(1, kvm_err);
|
||||
atexit(kgdb_atexit);
|
||||
kgdb_thr_init();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user