This is the mail archive of the gdb@sourceware.org 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]
Other format: [Raw text]

Re: break $function in coff/pe doesn't break exactly before the first statement?


I've digged a bit deeper on this.

Could it be that the problem is that in coff targets there is a call to __gccmain or __main that is inserted
right after main's prologue, and gdb is using the .loc that is pointing to that?
On elf, there is no need for __gccmain, so we don't see this happening.


Look at what happen currently on c++:

$cat main.cpp
class Global
{
public:
  Global()
  {
        a = 1;
  }
  int a;
};

Global global;

int
main (int argc, char** argv)
{
 return 0;
}


$g++ main.cpp -g -O3 -o main.exe
$gdb main.exe
GNU gdb 6.5.50.20060706-cvs (cygwin-special)
Copyright (C) 2006 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.
This GDB was configured as "i686-pc-cygwin"...
(gdb) b main
Breakpoint 1 at 0x40105b: file main.cpp, line 15.
(gdb) r
Starting program: /cygdrive/d/cegccsf/cegcc/cegcc/src/build-gdb_server/gdb/test/main.exe
Loaded symbols for /cygdrive/c/WINDOWS/system32/ntdll.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/kernel32.dll
Loaded symbols for /usr/bin/cygwin1.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/advapi32.dll
Loaded symbols for /cygdrive/c/WINDOWS/system32/rpcrt4.dll


Breakpoint 1, main (argc=1, argv=0x662f90) at main.cpp:15
15      {
(gdb) p global.a
$1 = 0
(gdb) n
17      }
(gdb) p global.a
$2 = 1
(gdb)

Outch! Unless the user types 'next', the c++ global constructors haven't ran yet.


Here is the relevant output from g++ main.cpp -g -gdwarf-2 -O3 -o main.s -S :


.globl _main
.def _main; .scl 2; .type 32; .endef


_main:
LFB5:
    .file 1 "main.cpp"
    .loc 1 15 0
    pushl     %ebp
LCFI0:
    movl $16, %eax
    movl %esp, %ebp
LCFI1:
    subl $8, %esp
LCFI2:
    .loc 1 15 0
    andl $-16, %esp
    call __alloca
    call ___main
    .loc 1 17 0
    leave
    xorl %eax, %eax
    ret
LFE5:

What do you think could be done to fix this?
Is it the .loc directives that are being output wrong? Or is it gdb's prologue reader
(if there is such a thing) that is missing the fact that __main is not user code?


Can anyone confirm this still
hasn't been fixed gcc higher than 4.1.0, and/or trunk?
Unfortunately, my laptop is getting pretty much without any harddrive space for another gcc :( (60MB free, Oh joy!)


Cheers,
Pedro Alves



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