[v2,00/17] Rewrite .debug_names reader and writer

Message ID 20240117-debug-names-fix-v2-0-dbd5971a9c31@tromey.com
Headers
Series Rewrite .debug_names reader and writer |

Message

Tom Tromey Jan. 17, 2024, 4:39 p.m. UTC
  This series rewrites gdb's .debug_names reader and writer.

Currently, gdb can generate a .debug_names index, but the contents are
very wrong -- they use fully-qualified names, which is not at all what
is envisioned in the DWARF spec.

After this series, the section contents will be much closer to DWARF.
However, it's not really useful for gdb to follow DWARF exactly.

First, the DWARF spec has a few bugs affecting the generation of the
index.  GDB fixes these -- you won't see these fixes in this series,
though, as they were all handled by the new DWARF scanner.

Second, gdb likes to have some information not readily available in
the DWARF-specified contents.  You can see the new DW_IDX_* constants
patch for a list.

I've regression tested this using the default board and the
cc-with-debug-names board on x86-64 Fedora 38.

It's possible that there are regressions with cc-with-debug-names at
some intermediate points in the series -- in particular I think it
would happen after the reader is rewritten but before the writer patch
is applied.  I didn't test this situation, since I don't think it is
very important.  It could be worked around by combining the two
patches, but I thought that would make review much more difficult.

---
Changes in v2:
- Updated some tests
- Reverted change to be strict about requiring .debug_aranges
- Link to v1: https://inbox.sourceware.org/gdb-patches/20231210-debug-names-fix-v1-0-a8f6d2525018@tromey.com

---
Tom Tromey (17):
      Refactor 'maint set dwarf synchronous' handling
      Refactor quick-function installation in DWARF reader
      Remove IS_ENUM_CLASS from cooked_index_flag
      Document GDB extensions to DWARF .debug_names
      Add language to cooked_index_entry
      Move cooked_index_functions to cooked-index.h
      Do not write the index cache from an index
      Change cooked_index_worker to abstract base class
      Remove cooked_index_worker::start_reading
      Empty hash table fix in .debug_names reader
      Fix dw2-zero-range.exp when an index is in use
      Explicitly expand CUs in dw2-inline-with-lexical-scope.exp
      Remove some .debug_names tests
      Allow other results in DW_TAG_entry_point test
      Rewrite .debug_names reader
      Export dwarf5_augmentation
      Rewrite .debug_names writer

 gdb/doc/gdb.texinfo                                |  39 +
 gdb/dwarf2/cooked-index.c                          | 164 +++-
 gdb/dwarf2/cooked-index.h                          | 168 +++-
 gdb/dwarf2/index-write.c                           | 401 ++++-----
 gdb/dwarf2/mapped-index.h                          |   4 +-
 gdb/dwarf2/read-debug-names.c                      | 956 ++++++++-------------
 gdb/dwarf2/read-debug-names.h                      |   2 +
 gdb/dwarf2/read.c                                  | 341 ++------
 gdb/testsuite/gdb.dwarf2/clang-debug-names-2-foo.c |  22 -
 gdb/testsuite/gdb.dwarf2/clang-debug-names-2.c     |  27 -
 gdb/testsuite/gdb.dwarf2/clang-debug-names-2.exp   |  42 -
 gdb/testsuite/gdb.dwarf2/clang-debug-names.c       |  25 -
 gdb/testsuite/gdb.dwarf2/clang-debug-names.exp     |  42 -
 gdb/testsuite/gdb.dwarf2/clang-debug-names.exp.tcl | 121 ---
 .../gdb.dwarf2/debug-names-bad-cu-index.exp        |  20 +-
 gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp      |   5 +-
 gdb/testsuite/gdb.dwarf2/dw2-inline-param.exp      |   7 +
 .../gdb.dwarf2/dw2-inline-with-lexical-scope.exp   |   4 +
 gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.exp      |  10 +
 gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp        |  10 +-
 gdb/testsuite/lib/dwarf.exp                        |   7 +-
 21 files changed, 976 insertions(+), 1441 deletions(-)
---
base-commit: 2002c0099f9fb4d737930acd66733cfad39f68f1
change-id: 20231210-debug-names-fix-cfbaf8761ecc

Best regards,
  

Comments

Tom de Vries Jan. 18, 2024, 10:05 a.m. UTC | #1
On 1/17/24 17:39, Tom Tromey wrote:
> This series rewrites gdb's .debug_names reader and writer.
> 
> Currently, gdb can generate a .debug_names index, but the contents are
> very wrong -- they use fully-qualified names, which is not at all what
> is envisioned in the DWARF spec.
> 
> After this series, the section contents will be much closer to DWARF.
> However, it's not really useful for gdb to follow DWARF exactly.
> 
> First, the DWARF spec has a few bugs affecting the generation of the
> index.  GDB fixes these -- you won't see these fixes in this series,
> though, as they were all handled by the new DWARF scanner.
> 
> Second, gdb likes to have some information not readily available in
> the DWARF-specified contents.  You can see the new DW_IDX_* constants
> patch for a list.
> 
> I've regression tested this using the default board and the
> cc-with-debug-names board on x86-64 Fedora 38.
> 

I've applied the series and tested on x86-64 openSUSE Leap 15.4, using 
the default board and cc-with-debug-names.  No issues found, other than:
...
Running 
/data/vries/gdb/src/gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.exp ...
ERROR: tcl error sourcing 
/data/vries/gdb/src/gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.exp.
ERROR: can't read "binfile_stripped": no such variable
...

Thanks,
- Tom

> It's possible that there are regressions with cc-with-debug-names at
> some intermediate points in the series -- in particular I think it
> would happen after the reader is rewritten but before the writer patch
> is applied.  I didn't test this situation, since I don't think it is
> very important.  It could be worked around by combining the two
> patches, but I thought that would make review much more difficult.
> 
> ---
> Changes in v2:
> - Updated some tests
> - Reverted change to be strict about requiring .debug_aranges
> - Link to v1: https://inbox.sourceware.org/gdb-patches/20231210-debug-names-fix-v1-0-a8f6d2525018@tromey.com
> 
> ---
> Tom Tromey (17):
>        Refactor 'maint set dwarf synchronous' handling
>        Refactor quick-function installation in DWARF reader
>        Remove IS_ENUM_CLASS from cooked_index_flag
>        Document GDB extensions to DWARF .debug_names
>        Add language to cooked_index_entry
>        Move cooked_index_functions to cooked-index.h
>        Do not write the index cache from an index
>        Change cooked_index_worker to abstract base class
>        Remove cooked_index_worker::start_reading
>        Empty hash table fix in .debug_names reader
>        Fix dw2-zero-range.exp when an index is in use
>        Explicitly expand CUs in dw2-inline-with-lexical-scope.exp
>        Remove some .debug_names tests
>        Allow other results in DW_TAG_entry_point test
>        Rewrite .debug_names reader
>        Export dwarf5_augmentation
>        Rewrite .debug_names writer
> 
>   gdb/doc/gdb.texinfo                                |  39 +
>   gdb/dwarf2/cooked-index.c                          | 164 +++-
>   gdb/dwarf2/cooked-index.h                          | 168 +++-
>   gdb/dwarf2/index-write.c                           | 401 ++++-----
>   gdb/dwarf2/mapped-index.h                          |   4 +-
>   gdb/dwarf2/read-debug-names.c                      | 956 ++++++++-------------
>   gdb/dwarf2/read-debug-names.h                      |   2 +
>   gdb/dwarf2/read.c                                  | 341 ++------
>   gdb/testsuite/gdb.dwarf2/clang-debug-names-2-foo.c |  22 -
>   gdb/testsuite/gdb.dwarf2/clang-debug-names-2.c     |  27 -
>   gdb/testsuite/gdb.dwarf2/clang-debug-names-2.exp   |  42 -
>   gdb/testsuite/gdb.dwarf2/clang-debug-names.c       |  25 -
>   gdb/testsuite/gdb.dwarf2/clang-debug-names.exp     |  42 -
>   gdb/testsuite/gdb.dwarf2/clang-debug-names.exp.tcl | 121 ---
>   .../gdb.dwarf2/debug-names-bad-cu-index.exp        |  20 +-
>   gdb/testsuite/gdb.dwarf2/dw2-entry-points.exp      |   5 +-
>   gdb/testsuite/gdb.dwarf2/dw2-inline-param.exp      |   7 +
>   .../gdb.dwarf2/dw2-inline-with-lexical-scope.exp   |   4 +
>   gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.exp      |  10 +
>   gdb/testsuite/gdb.dwarf2/dw2-zero-range.exp        |  10 +-
>   gdb/testsuite/lib/dwarf.exp                        |   7 +-
>   21 files changed, 976 insertions(+), 1441 deletions(-)
> ---
> base-commit: 2002c0099f9fb4d737930acd66733cfad39f68f1
> change-id: 20231210-debug-names-fix-cfbaf8761ecc
> 
> Best regards,
  
Tom Tromey Jan. 18, 2024, 3:42 p.m. UTC | #2
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> I've applied the series and tested on x86-64 openSUSE Leap 15.4, using
Tom> the default board and cc-with-debug-names.  No issues found, other
Tom> than:
Tom> ...
Tom> Running
Tom> /data/vries/gdb/src/gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.exp ...
Tom> ERROR: tcl error sourcing
Tom> /data/vries/gdb/src/gdb/testsuite/gdb.dwarf2/dw2-minsym-in-cu.exp.
Tom> ERROR: can't read "binfile_stripped": no such variable
Tom> ...

Oops.
Replacing $binfile_stripped with $binfile makes this work for me.

Tom
  
Tom Tromey Jan. 18, 2024, 8:33 p.m. UTC | #3
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> Replacing $binfile_stripped with $binfile makes this work for me.

I'm checking this in now.
As always, let me know if there are problems and I will fix it.

Tom