Bug 12568 - GDB inserts breakpoint on constructor at location 0
Summary: GDB inserts breakpoint on constructor at location 0
Status: RESOLVED DUPLICATE of bug 12528
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-11 06:19 UTC by Paul Pluzhnikov
Modified: 2011-03-11 08:11 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2011-03-11 06:19:06 UTC
When using virtual inheritance, GCC emits in-charge (C1) and not-in-charge (C2) constructors, at the same source file:line

One of these ctors could be garbage-collected by the linker, causing its line table to start at location 0.

GDB does not ignore that line table, sets a breakpoint on 0, then gets:

Cannot insert breakpoint 1.
Error accessing memory address 0x0: Input/output error.

The problem reproduces with GDB 7.2.50.20110311-cvs and GCC
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3

The problem does *not* reproduce with g++ (GCC) 4.6.0 20110219 (experimental),
because in that version C1 ctor calls C2, preventing C2 from being GCd by the linker.

Repro steps:

/// --- foo.c
struct Foo
{
  Foo(int z) { x = z; }
  int x;
};

struct Bar: virtual public Foo
{
  Bar(int x) : Foo(x) { }
};

int
main(int argc, char *argv[])
{
  Foo f(42);
  return f.x + argc;
}

// Calls C2 ctor, but is GCd by linker
void
deadfn()
{
  Bar b(12);
}
/// --- foo.c


g++ -g foo.c -fno-inline -ffunction-sections -Wl,--gc-sections
nm a.out | grep Foo
0000000000400622 W _ZN3FooC1Ei   ### Note: only C1 constructor present!

gdb ./a.out
GNU gdb (GDB) 7.2.50.20110311-cvs
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /tmp/a.out...done.
(gdb) b Foo::Foo
Breakpoint 1 at 0x0: file foo.c, line 3. (3 locations)
(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   <MULTIPLE>         
1.1                         y     0x0000000000000000 foo.c:3
1.2                         y     0x000000000000000b foo.c:3
1.3                         y     0x000000000040062d in Foo::Foo(int) at foo.c:3
(gdb) r
Warning:
Cannot insert breakpoint 1.
Error accessing memory address 0x0: Input/output error.
Cannot insert breakpoint 1.
Error accessing memory address 0xb: Input/output error.

(gdb) q
Comment 1 dje 2011-03-11 08:11:32 UTC
Marking as dup.

*** This bug has been marked as a duplicate of bug 12528 ***