Bug 27494 - Handle DW_MACRO_define_strp in version 4 .debug_macro.dwo
Summary: Handle DW_MACRO_define_strp in version 4 .debug_macro.dwo
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-01 15:47 UTC by Tom de Vries
Modified: 2021-04-14 13:24 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 2021-03-01 15:47:11 UTC
[ See gcc PR https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99319 . ]

Consider:
...
$ gcc -ggdb3 -g hello.c -gsplit-dwarf 
$ gdb -q -batch -readnow a.out
DW_FORM_strp pointing outside of .debug_str section [in module /home/vries/hello/a.out]
...

When reading a version 4 .debug_macro.dwo section we should expect the second operand of DW_MACRO_define_strp to be a uleb128.
Comment 1 Tom de Vries 2021-04-14 13:24:45 UTC
This patch fixes the error message:
...
diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c
index 2ecebe6173c..b8d5676c63b 100644
--- a/gdb/dwarf2/macro.c
+++ b/gdb/dwarf2/macro.c
@@ -502,8 +502,17 @@ dwarf_decode_macro_bytes (dwarf2_per_objfile *per_objfile,
              {
                LONGEST str_offset;
 
-               str_offset = read_offset (abfd, mac_ptr, offset_size);
-               mac_ptr += offset_size;
+               if (DW_MACRO_define_strp == macinfo_type
+                   && strcmp (section->s.section->name, ".debug_macro.dwo") == 0)
+                 {
+                   str_offset = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+                   mac_ptr += bytes_read;
+                 }
+               else
+                 {
+                   str_offset = read_offset (abfd, mac_ptr, offset_size);
+                   mac_ptr += offset_size;
+                 }
 
                if (macinfo_type == DW_MACRO_define_sup
                    || macinfo_type == DW_MACRO_undef_sup
@@ -866,7 +875,14 @@ dwarf_decode_macros (dwarf2_per_objfile *per_objfile,
 
            read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
            mac_ptr += bytes_read;
-           mac_ptr += offset_size;
+           if (DW_MACRO_define_strp == macinfo_type
+               && strcmp (section->s.section->name, ".debug_macro.dwo") == 0)
+             {
+               read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+               mac_ptr += bytes_read;
+             }
+           else
+             mac_ptr += offset_size;
          }
          break;
        case DW_MACRO_define_strx:
...

But a simple example still doesn't work:
...
$ cat test.c          
#include <stdio.h>

#define BLA "hello"

int
main (void)
{
  printf (BLA "\n");
  return 0;
}
$ gcc-10 test.c -ggdb3
$ gdb -q -batch a.out -ex start -ex "info macro BLA"
Temporary breakpoint 1 at 0x40050a: file test.c, line 8.

Temporary breakpoint 1, main () at test.c:8
8         printf (BLA "\n");
Defined at /home/vries/test.c:3
#define BLA "hello"
$ gcc-10 test.c -ggdb3 -gsplit-dwarf
$ gdb -q -batch a.out -ex start -ex "info macro BLA"
Temporary breakpoint 1 at 0x40050a: file test.c, line 8.

Temporary breakpoint 1, main () at test.c:8
8         printf (BLA "\n");
The symbol `BLA' has no definition as a C/C++ preprocessor macro
at <user-defined>:-1
...