Patchwork Ensure captured_main has unique address

mail settings
Submitter Tom de Vries
Date June 12, 2018, 3:06 p.m.
Message ID <20180612150620.wloegrt5dgpdugi2@localhost.localdomain>
Download mbox | patch
Permalink /patch/27752/
State New
Headers show


Tom de Vries - June 12, 2018, 3:06 p.m.

atm selftest.exp fails for me.

One of the reasons is that after setting a breakpoint in captured_main, we
stop at:
Breakpoint 1, captured_main_1 (context=<optimized out>) at src/gdb/main.c:492
while selftest_setup expects to stop at captured_main.

The problem is that captured_main_1 has been inlined into captured_main, and
captured_main has been inlined into gdb_main:
$ nm ./build/gdb/gdb | egrep ' [tT] .*captured_main|gdb_main' | c++filt
000000000061b950 T gdb_main(captured_main_args*)

The reason that we seem to be stopping at inline function captured_main_1 has
probably something to do with commit "Don't elide all inlined frames", which
shows us the frames of inlined functions as if they were not inlined.  Indeed,
the two inlined functions show up in the backtrace:
(gdb) bt
#0  captured_main_1 (context=<optimized out>) at main.c:492
#1  captured_main (data=<optimized out>) at main.c:1147
#2  gdb_main (args=args@entry=0x7fffffffdb80) at main.c:1173
#3  0x000000000040fea5 in main (argc=<optimized out>, argv=<optimized out>)
    at gdb.c:32

[ For contrast, If I use my distro gdb to debug build/gdb/gdb instead, we just
Breakpoint 1, gdb_main (args=args@entry=0x7fffffffdb80)
    at src/gdb/main.c:1173
1173          captured_main (args);

Either way, this patch fixes the problem by ensuring that captured_main has a
unique address:
$ nm ./build/gdb/gdb | egrep ' [tT] .*captured_main|gdb_main' | c++filt
000000000061ca20 T gdb_main(captured_main_args*)
000000000061c980 t captured_main(void*)
000000000061b950 t captured_main_1(captured_main_args*)

Tested selftest.exp (with two other selftest.exp related fixes applied).

OK for trunk?

- Tom

[gdb] Ensure captured_main has unique address

2018-06-12  Tom de Vries  <>

	* main.c (captured_main, captured_main_1): Add

 gdb/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


diff --git a/gdb/main.c b/gdb/main.c
index 9694af2426..f35dffd428 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -447,7 +447,7 @@  struct cmdarg
   char *string;
-static void
+static void __attribute__((noinline))
 captured_main_1 (struct captured_main_args *context)
   int argc = context->argc;
@@ -1139,7 +1139,7 @@  captured_main_1 (struct captured_main_args *context)
-static void
+static void __attribute__((noinline))
 captured_main (void *data)
   struct captured_main_args *context = (struct captured_main_args *) data;