This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Add backtrace to gdb ...


... of GDB debugging gdb.

Hello,

The attatched is a quick hack to tweek internal_error() giving the behavour:

(gdb) maint internal-error
/home/scratch/PENDING/stack-dump/src/gdb/maint.c:119: 
gdb-internal-error: internal maintenance
An internal GDB error was detected.  This may make further
debugging unreliable.  Continue this debugging session? (y or n) n

Create a core file containing the current state of GDB? (y or n) n

Produce a back-trace? (y or n) y

GNU gdb 2001-09-27-cvs (MI_OUT)
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain 
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
( echo set prompt ; echo attach 20618 ; echo bt ) | gdb -nw -nx --quiet 
./gdb/gdb
(gdb) Attaching to program 
`/home/scratch/PENDING/stack-dump/native/./gdb/gdb', process 20618
Reading symbols from /usr/libexec/ld.elf_so...done.
Reading symbols from /usr/lib/libtermcap.so.0...done.
Reading symbols from /usr/lib/libm.so.0...done.
Reading symbols from /usr/lib/libc.so.12...done.
0x41b2437c in ?? () from /usr/lib/libc.so.12
#0  0x41b2437c in ?? () from /usr/lib/libc.so.12
Detaching from program: 
/home/scratch/PENDING/stack-dump/native/./gdb/gdb process 20618

Just a shame that this GDB couldn't back-trace from libc.

Anyway, any comments on the idea of adding something like this to GDB? 
(Just not this exact patch).

As for the origins of the idea, came across it in a UNIX faq.

Andrew
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.12
diff -p -r1.12 main.c
*** main.c	2001/07/14 18:59:07	1.12
--- main.c	2001/09/27 05:41:34
*************** extern int gdbtk_test (char *);
*** 707,716 ****
--- 707,719 ----
    /* No exit -- exit is through quit_command.  */
  }
  
+ char *global_argv0_hack;
+ 
  int
  main (int argc, char **argv)
  {
    struct captured_main_args args;
+   global_argv0_hack = argv[0];
    args.argc = argc;
    args.argv = argv;
    catch_errors (captured_main, &args, "", RETURN_MASK_ALL);
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.47
diff -p -r1.47 utils.c
*** utils.c	2001/08/01 18:39:23	1.47
--- utils.c	2001/09/27 05:41:35
***************
*** 25,30 ****
--- 25,31 ----
  #include <ctype.h>
  #include "gdb_string.h"
  #include "event-top.h"
+ #include "top.h"		/* for gdb_print_version () */
  
  #ifdef HAVE_CURSES_H
  #include <curses.h>
*************** internal_verror (const char *file, int l
*** 692,697 ****
--- 693,699 ----
    static int dejavu = 0;
    int continue_p;
    int dump_core_p;
+   int backtrace_p;
  
    /* don't allow infinite error recursion. */
    switch (dejavu)
*************** debugging unreliable.  Continue this deb
*** 725,730 ****
--- 727,751 ----
       leaving random core files around. */
    dump_core_p = query ("\
  Create a core file containing the current state of GDB? ");
+ 
+   /* Default (no case) is to not produce a stack dump.  May not work
+      anyway.  */
+   backtrace_p = query ("Produce a back-trace? ");
+ 
+   if (backtrace_p)
+     {
+       extern char *global_argv0_hack;
+       char *cmd;
+       xasprintf (&cmd, "( echo set prompt ; echo attach %d ; echo bt ) | gdb -nw -nx --quiet %s",
+ 		 getpid (), global_argv0_hack);
+       printf_unfiltered ("\n");
+       print_gdb_version (gdb_stdout);
+       printf_unfiltered ("\n");
+       printf_unfiltered ("%s\n", cmd);
+       system (cmd);
+       xfree (cmd);
+       printf_unfiltered ("\n");
+     }
  
    if (continue_p)
      {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]