[cfe-commits] patch: emit debug info for dynamic constructors

Nick Lewycky nlewycky at google.com
Mon Jul 23 17:57:35 PDT 2012


The attached patch adds support for debug info in C++ dynamic initializers.
This is subject to -g and also __attribute__((nodebug)) which is now
permitted on variables with static storage duration.

The driving reason for this change is to get useful information in
backtraces. For instance, before:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004004de in crash () at gi.cc:3
3         char x = *ptr;
(gdb) bt
#0  0x00000000004004de in crash () at gi.cc:3
#1  0x0000000000400505 in test () at gi.cc:7
#2  0x0000000000400519 in __cxx_global_var_init () at gi.cc:8
#3  0x0000000000400569 in global constructors keyed to a ()
#4  0x0000000000400636 in __do_global_ctors_aux ()
#5  0x00000000004003bb in _init ()
#6  0x00007fffffffe528 in ?? ()
#7  0x00000000004005c5 in __libc_csu_init ()
#8  0x00007ffff7a78be0 in __libc_start_main (main=<optimized out>,
argc=<optimized out>, ubp_av=<optimized out>,
    init=0x400580 <__libc_csu_init>, fini=0x7ffff7dd8300 <initial>,
rtld_fini=0x7ffff7dec250 <_dl_fini>, stack_end=0x7fffffffe508)
    at libc-start.c:185
#9  0x0000000000400409 in _start ()

which looks fine, but pay attention to the line number info for
__cxx_global_var_init. After:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004004de in crash () at gi.cc:3
3         char x = *ptr;
(gdb) bt
#0  0x00000000004004de in crash () at gi.cc:3
#1  0x00000000004004f9 in test () at gi.cc:7
#2  0x0000000000400519 in __cxx_global_var_init () at gi.cc:11
#3  0x0000000000400559 in global constructors keyed to a ()
#4  0x0000000000400626 in __do_global_ctors_aux ()
#5  0x00000000004003bb in _init ()
#6  0x00007fffffffe528 in ?? ()
#7  0x00000000004005b5 in __libc_csu_init ()
#8  0x00007ffff7a78be0 in __libc_start_main (main=<optimized out>,
argc=<optimized out>, ubp_av=<optimized out>,
    init=0x400570 <__libc_csu_init>, fini=0x7ffff7dd8300 <initial>,
rtld_fini=0x7ffff7dec250 <_dl_fini>, stack_end=0x7fffffffe508)
    at libc-start.c:185
#9  0x0000000000400409 in _start ()

The before line was wrong. Here's the code for that program.

      1 void crash() {
      2   volatile char *ptr = 0;
      3   char x = *ptr;
      4 }
      5
      6 int test() {
      7   crash();
      8   return 1;
      9 }
     10
     11 static int i = test();
     12 __attribute__((nodebug)) static int j = test();
     13
     14 int main(void) {}

It's more common to see __cxx_global_var_init given as location foo.cc:0 in
the backtrace, but I wanted to show an example where that doesn't happen.

This patch includes a small cleanup to SemaDeclAttr.cpp. Tabs to spaces.
"!isa<FunctionDecl>(D) && !isa<FunctionTemplateDecl>(D)" became
"!isFunctionOrMethod(D)" because that's what the author actually meant.
Richard Smith suggested that I change the "no address safety" attribute to
use the same logic as nodebug (permitted on certain variables) but that
turns out to be difficult to implement and should be in a separate patch.

Please review!

Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120723/0c345d8e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gv-debuginfo-1.patch
Type: application/octet-stream
Size: 14602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120723/0c345d8e/attachment.obj>


More information about the cfe-commits mailing list