public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* RE: [PING*2][PATCH] gdb-Fix-macro-info-lookup-for-binaries-containing-DWARFv5
@ 2021-04-14 16:24 Tomar, Sourabh Singh
  0 siblings, 0 replies; only message in thread
From: Tomar, Sourabh Singh @ 2021-04-14 16:24 UTC (permalink / raw)
  To: Tomar, Sourabh Singh via Gdb-patches
  Cc: George, Jini Susan, Sharma, Alok Kumar, Kumar N, Bhuvanendra,
	Achra, Nitika

[AMD Public Use]

Gentle PING*2!

-----Original Message-----
From: Tomar, Sourabh Singh 
Sent: Saturday, April 3, 2021 12:20 PM
To: 'Tomar, Sourabh Singh via Gdb-patches' <gdb-patches@sourceware.org>
Cc: George, Jini Susan <JiniSusan.George@amd.com>; Sharma, Alok Kumar <AlokKumar.Sharma@amd.com>; Kumar N, Bhuvanendra <Bhuvanendra.KumarN@amd.com>
Subject: RE: [PATCH] gdb-Fix-macro-info-lookup-for-binaries-containing-DWARFv5

[AMD Public Use]

Gentle PING!

-----Original Message-----
From: Tomar, Sourabh Singh 
Sent: Friday, March 26, 2021 8:43 PM
To: Tomar, Sourabh Singh via Gdb-patches <gdb-patches@sourceware.org>
Cc: George, Jini Susan <JiniSusan.George@amd.com>; Sharma, Alok Kumar <AlokKumar.Sharma@amd.com>; Kumar N, Bhuvanendra <Bhuvanendra.KumarN@amd.com>; Achra, Nitika <Nitika.Achra@amd.com>; E, Nagajyothi <Nagajyothi.E@amd.com>
Subject: [PATCH] gdb-Fix-macro-info-lookup-for-binaries-containing-DWARFv5

[AMD Public Use]

Hello Everyone,

Requesting review on this patch, Please have a look.

Problem Description/Summary:
- clang emits DWARFv5 conformant line tables(ie. .debug_line section) which makes 2 things explicitly:
1. The current directory is explicitly present in the directories field and has index 0.
2. The current compilation filename is explicitly present and has index 0.

This leads to a subtle issue in GDB while accessing macro information:
Consider the following program:
```
#define OUT 4
int main() { int a = OUT;}
```
Compiled as `clang -gdwarf-5 -fdebug-macro test.c` GDB session:
```
$gdb a.out -q
....
2       int main() { int a = OUT;}
(gdb) info macro OUT
The symbol `OUT' has no definition as a C/C++ preprocessor macro at /home/test.c:-1 ```

This issue cannot be reproduced using GCC compiler as GCC doesnot emit DWARFv5 compliant tables even At `-gdwarf-5` flag.

Issue is stemming from line-header.c. When performing a file name lookup for macro filename GDB mistakenly appends FULL path after checking following condition, which as **one may notice** for directory index `0` will always evaluates `true` for DWARv5 line tables and `false` for DWARFv4 line tables.
```
If (dir != NULL)
return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
                                                          fe->name,
                                                          (char *) NULL)); ``` Result of this, macro `filename` getting populated with fullname. Eventually macro lookup
results in failure due to mismatch in `main_file->filename` and   `sal.symtab->filename`.

This patch attempts to fix above problem by extending the check for file `0`, i.e for file `0` do not append the fullname.

Testing:
- NO regressions in GDB testsuite before and after the fix.

We also tried add a test case for this fix, but was unsuccessful.
GDB test suite uses full path to the test files and this specific problem is not reproducible when user specifies full path. i.e Not reproducible cases:
1. `clang -gdwarf-5 -fdebug-macro ./test.c` // macro visible inside GDB 2. `clang -gdwarf-5 -fdebug-macro /ABSOLUTE_PATH/test.c` // macro visible inside GDB

Reproducible:
1. `clang -gdwarf-5 -fdebug-macro test.c` //log shown above.

gdb/ChangeLog
2021-03-26  Sourabh Singh Tomar  <SourabhSingh.Tomar@amd.com>

       * dwarf2/line-header.c: Updated the comment and extended
       check in function `line_header::file_file_name` for
       DWARFv5 line tables.

Thank You,
Sourabh.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-14 16:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 16:24 [PING*2][PATCH] gdb-Fix-macro-info-lookup-for-binaries-containing-DWARFv5 Tomar, Sourabh Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).