Nested functions and dwarf-2

Paul Hilfinger hilfingr@EECS.Berkeley.EDU
Sat Sep 30 00:03:00 GMT 2000

Consider the following GNU C program

    #include <stdio.h>

    main (int argc, char* argv[]) 
      int glorp (int x) { // GNU C extension
	return x;

      printf ("%d\n", glorp (15));
      exit (0);

When compiled using

     gcc -gdwarf-2 -o foo foo.c

on Linux with all the versions of gcc I've tried (up to egcs-2.91.66),
the resulting debugging data has the blocks relating to the inner
function 'glorp' nested inside ("owned by" in the dwarf reference's
terminology) one of main's lexical blocks.  The code for glorp,
however, is disjoint from that of main.  GDB does not expect this:

  (gdb) set complaints 100
  (gdb) b main
  During symbol reading, inner block not inside outer block in main.

This message (which comes from from finish_block in buildsym.c) would
merely be an annoyance, except that finish_block also takes
corrective action, forcibly setting the bounds of the errant inner
block to be within those of the outer one.  In at least one case, I
have observed (on a mips architecture running IRIX) that this
adjustment can result in such undesirable phenomona as the 'next'
command going into an infinite loop.  

What SHOULD finish_block (or the compiler?) be doing in this case?

Paul Hilfinger

More information about the Gdb mailing list