Bug 24517 - DW_AT_main_subprogram ignored with readnow
Summary: DW_AT_main_subprogram ignored with readnow
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: symtab (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-03 11:40 UTC by Tom de Vries
Modified: 2019-06-10 07:30 UTC (History)
0 users

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 Tom de Vries 2019-05-03 11:40:41 UTC
With the main-subprogram executable (the test-case for PR16264), without -readnow we end up in mymain, as expected:
... 
$ ./gdb -batch /data/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.dwarf2/main-subprogram/main-subprogram  -ex start
Temporary breakpoint 1 at 0x4004ab

Temporary breakpoint 1, 0x00000000004004ab in mymain ()

...

But with -readnow, we end up in main instead:
...
$ ./gdb -readnow -batch /data/gdb_versions/devel/build/gdb/testsuite/outputs/gdb.dwarf2/main-subprogram/main-subprogram.stripped  -ex start
Temporary breakpoint 1 at 0x4004b6

Temporary breakpoint 1, 0x00000000004004b6 in main ()
...
Comment 1 Tom de Vries 2019-05-03 15:04:39 UTC
Tentative patch:
...
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index b0bdecf96f..229877dded 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -13741,6 +13741,10 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
   newobj->name = new_symbol (die, read_type_die (die, cu), cu,
                             (struct symbol *) templ_func);
 
+  attr = dwarf2_attr (die, DW_AT_main_subprogram, cu);
+  if (attr)
+    set_objfile_main_name (objfile, SYMBOL_LINKAGE_NAME (newobj->name), cu->language);
+
   /* If there is a location expression for DW_AT_frame_base, record
      it.  */
   attr = dwarf2_attr (die, DW_AT_frame_base, cu);
...
Comment 2 Tom de Vries 2019-05-05 10:26:10 UTC
patch submitted: https://sourceware.org/ml/gdb-patches/2019-05/msg00156.html
Comment 3 Sourceware Commits 2019-06-10 07:29:13 UTC
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=81873cc81effbd657efe5f525d369e430ce77d7a

commit 81873cc81effbd657efe5f525d369e430ce77d7a
Author: Tom de Vries <tdevries@suse.de>
Date:   Mon Jun 10 09:28:30 2019 +0200

    [gdb/symtab] Support DW_AT_main_subprogram with -readnow.
    
    DW_AT_main_subprogram is supported in normal mode in read_partial_die, but not
    in -readnow mode.
    
    Fix this by adding support for DW_AT_main_subprogram in read_func_scope.
    
    Tested on x86_64-linux with native and RFC target board readnow (
    https://sourceware.org/ml/gdb-patches/2019-05/msg00073.html ).
    
    gdb/ChangeLog:
    
    2019-06-10  Tom de Vries  <tdevries@suse.de>
    
    	PR symtab/16264
    	PR symtab/24517
    	* dwarf2read.c (read_func_scope): Handle DW_AT_main_subprogram.
Comment 4 Tom de Vries 2019-06-10 07:30:03 UTC
Patch committed.