Re: KGDB stack traces in the kernel.

From: John Baldwin <jhb_at_freebsd.org>
Date: Wed, 6 Apr 2011 08:45:11 -0400
On Tuesday, April 05, 2011 4:35:44 pm Navdeep Parhar wrote:
> On Tue, Apr 5, 2011 at 1:33 PM, Julian Elischer <julian_at_freebsd.org> wrote:
> > On 4/4/11 6:04 PM, Justin Hibbits wrote:
> >>
> >> On Apr 4, 2011, at 6:57 PM, Julian Elischer wrote:
> >>>
> >>> is there anyone here with enough gdb/kgdb source experience to know what
> >>> we would need to put on the stack at fork_exit() to make it stop when it
> >>> gets there?
> >>>
> >>> not only is it annoying but it slows down debugging because kgdb and the
> >>> ddd
> >>> front end ask for stacks a LOT. sometimes it actually just hangs as the
> >>> stack
> >>> goes into a loop and never ends.
> >>>
> >>> I had a quick look but didn't spot how gdb decides it has reached the 
end
> >>> of a stack.
> >>>
> >>> Julian
> >>
> >> From my experience, it checks for a NULL stack chain pointer.  Once that
> >> reaches NULL, it's the end of the stack.
> >>
> >> - Justin
> >>
> > I'll try adding NULL when we build the intial stack up.
> > :-)
> 
> What does ddb do?  It always seems to get this stuff correct.

ddb knows to stop when it gets to a non-kernel address, and it uses string
compares on function names to identify trap frames.  For example in 
sys/amd64/amd64/db_trace.c:


                if (strcmp(name, "calltrap") == 0 ||
                    strcmp(name, "fork_trampoline") == 0 ||
                    strcmp(name, "nmi_calltrap") == 0 ||
                    strcmp(name, "Xdblfault") == 0)
                        frame_type = TRAP;

Hah, kgdb just needs to be updated (this is from trgt_amd64.c):

const struct frame_unwind *
kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame)
{
        char *pname;
        CORE_ADDR pc;

        pc = frame_pc_unwind(next_frame);
        pname = NULL;
        find_pc_partial_function(pc, &pname, NULL, NULL);
        if (pname == NULL)
                return (NULL);
        if (strcmp(pname, "calltrap") == 0 ||
            strcmp(pname, "nmi_calltrap") == 0 ||
            (pname[0] == 'X' && pname[1] != '_'))
                return (&kgdb_trgt_trapframe_unwind);
        /* printf("%s: %lx =%s\n", __func__, pc, pname); */
        return (NULL);
}

Can probably just add 'fork_trampoline' to that conditional.  I think i386 
needs a similar fix in kgdb.  Not sure about other architectures:

Index: trgt_amd64.c
===================================================================
--- trgt_amd64.c	(revision 220190)
+++ trgt_amd64.c	(working copy)
_at__at_ -184,6 +184,7 _at__at_
 	if (pname == NULL)
 		return (NULL);
 	if (strcmp(pname, "calltrap") == 0 ||
+	    strcmp(pname, "fork_trampoline") == 0 ||
 	    strcmp(pname, "nmi_calltrap") == 0 ||
 	    (pname[0] == 'X' && pname[1] != '_'))
 		return (&kgdb_trgt_trapframe_unwind);
Index: trgt_i386.c
===================================================================
--- trgt_i386.c	(revision 220190)
+++ trgt_i386.c	(working copy)
_at__at_ -374,6 +374,7 _at__at_
 	if (strcmp(pname, "dblfault_handler") == 0)
 		return (&kgdb_trgt_dblfault_unwind);
 	if (strcmp(pname, "calltrap") == 0 ||
+	    strcmp(pname, "fork_trampoline") == 0 ||
 	    (pname[0] == 'X' && pname[1] != '_'))
 		return (&kgdb_trgt_trapframe_unwind);
 	/* printf("%s: %llx =%s\n", __func__, pc, pname); */

-- 
John Baldwin
Received on Wed Apr 06 2011 - 10:45:14 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:13 UTC