Skip to content

Conversation

@Michael137
Copy link

This patch adds a new option --child-tags (-t for short), which
makes dwarfdump only dump children whose DWARF tag is in the list of
tags specified by the user.

Motivating examples are:

  • dumping all global variables in a CU
  • dumping all non-static data members of a structure
  • dumping all module import declarations of a CU
  • etc.

For tags not known to dwarfdump, we pretend that the tag wasn't
specified.

Note, this flag only takes effect when --show-children is set (either
explicitly or implicitly). We error out when trying to use the flag
without dumping children.

Example:

$ builds/release/bin/llvm-dwarfdump -t DW_TAG_structure_type a.out.dSYM
...
0x0000000c: DW_TAG_compile_unit
              DW_AT_producer    ("clang version)")
              DW_AT_language    (DW_LANG_C11)
              ...
0x0000002a:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_byte_size (0x20)

0x00000067:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_name      ("__block_descriptor")
                DW_AT_byte_size (0x10)
...
$ builds/release/bin/llvm-dwarfdump -t DW_TAG_structure_type -t DW_TAG_member a.out.dSYM
...
0x0000000c: DW_TAG_compile_unit
              DW_AT_producer    ("clang version)")
              DW_AT_language    (DW_LANG_C11)
              DW_AT_name        ("macro.c")
              ...
0x0000002a:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_byte_size (0x20)

0x0000002c:     DW_TAG_member
                  DW_AT_name    ("__isa")
                  DW_AT_type    (0x00000051 "void *")
                  DW_AT_data_member_location    (0x00)

0x00000033:     DW_TAG_member
                  DW_AT_name    ("__flags")
                  DW_AT_type    (0x00000052 "int")
                  DW_AT_data_member_location    (0x08)

0x0000003a:     DW_TAG_member
                  DW_AT_name    ("__reserved")
                  DW_AT_type    (0x00000052 "int")
                  DW_AT_data_member_location    (0x0c)

0x00000041:     DW_TAG_member
                  DW_AT_name    ("__FuncPtr")
                  DW_AT_type    (0x00000056 "void (*)(int)")
                  DW_AT_data_member_location    (0x10)

0x00000048:     DW_TAG_member
                  DW_AT_name    ("__descriptor")
                  DW_AT_type    (0x00000062 "__block_descriptor *")
                  DW_AT_alignment       (8)
                  DW_AT_data_member_location    (0x18)

0x00000067:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_name      ("__block_descriptor")
                DW_AT_byte_size (0x10)

0x0000006a:     DW_TAG_member
                  DW_AT_name    ("reserved")
                  DW_AT_type    (0x00000079 "unsigned long")
                  DW_AT_data_member_location    (0x00)

0x00000071:     DW_TAG_member
                  DW_AT_name    ("Size")
                  DW_AT_type    (0x00000079 "unsigned long")
                  DW_AT_data_member_location    (0x08)
...

(cherry picked from commit f8656ed)

@Michael137
Copy link
Author

@swift-ci test

@Michael137
Copy link
Author

@swift-ci test llvm

…vm#165720)

This patch adds a new option `--child-tags` (`-t` for short), which
makes dwarfdump only dump children whose DWARF tag is in the list of
tags specified by the user.

Motivating examples are:
* dumping all global variables in a CU
* dumping all non-static data members of a structure
* dumping all module import declarations of a CU
* etc.

For tags not known to dwarfdump, we pretend that the tag wasn't
specified.

Note, this flag only takes effect when `--show-children` is set (either
explicitly or implicitly). We error out when trying to use the flag
without dumping children.

Example:
```
$ builds/release/bin/llvm-dwarfdump -t DW_TAG_structure_type a.out.dSYM
...
0x0000000c: DW_TAG_compile_unit
              DW_AT_producer    ("clang version 22.0.0git (git@github.com:Michael137/llvm-project.git 737da33)")
              DW_AT_language    (DW_LANG_C11)
              ...
0x0000002a:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_byte_size (0x20)

0x00000067:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_name      ("__block_descriptor")
                DW_AT_byte_size (0x10)
...
```

```
$ builds/release/bin/llvm-dwarfdump -t DW_TAG_structure_type -t DW_TAG_member a.out.dSYM
...
0x0000000c: DW_TAG_compile_unit
              DW_AT_producer    ("clang version 22.0.0git (git@github.com:Michael137/llvm-project.git 737da33)")
              DW_AT_language    (DW_LANG_C11)
              DW_AT_name        ("macro.c")
              ...
0x0000002a:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_byte_size (0x20)

0x0000002c:     DW_TAG_member
                  DW_AT_name    ("__isa")
                  DW_AT_type    (0x00000051 "void *")
                  DW_AT_data_member_location    (0x00)

0x00000033:     DW_TAG_member
                  DW_AT_name    ("__flags")
                  DW_AT_type    (0x00000052 "int")
                  DW_AT_data_member_location    (0x08)

0x0000003a:     DW_TAG_member
                  DW_AT_name    ("__reserved")
                  DW_AT_type    (0x00000052 "int")
                  DW_AT_data_member_location    (0x0c)

0x00000041:     DW_TAG_member
                  DW_AT_name    ("__FuncPtr")
                  DW_AT_type    (0x00000056 "void (*)(int)")
                  DW_AT_data_member_location    (0x10)

0x00000048:     DW_TAG_member
                  DW_AT_name    ("__descriptor")
                  DW_AT_type    (0x00000062 "__block_descriptor *")
                  DW_AT_alignment       (8)
                  DW_AT_data_member_location    (0x18)

0x00000067:   DW_TAG_structure_type
                DW_AT_APPLE_block       (true)
                DW_AT_name      ("__block_descriptor")
                DW_AT_byte_size (0x10)

0x0000006a:     DW_TAG_member
                  DW_AT_name    ("reserved")
                  DW_AT_type    (0x00000079 "unsigned long")
                  DW_AT_data_member_location    (0x00)

0x00000071:     DW_TAG_member
                  DW_AT_name    ("Size")
                  DW_AT_type    (0x00000079 "unsigned long")
                  DW_AT_data_member_location    (0x08)
...
```

(cherry picked from commit f8656ed)
In llvm#165720 we started using a
DWARF API (`llvm::dwarf::getTag`) from `BinaryFormat`. This patch makes
dwarfdump link against the necessary LLVM component.

This fixes following linker error that started occurring on some of the
bots:
```
[7758/8172] Linking CXX executable bin/llvm-dwarfdump
FAILED: bin/llvm-dwarfdump
: && /usr/bin/c++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-array-bounds -Wno-stringop-overread -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -Wl,-rpath-link,/home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/./lib  -Wl,--gc-sections tools/llvm-dwarfdump/CMakeFiles/llvm-dwarfdump.dir/SectionSizes.cpp.o tools/llvm-dwarfdump/CMakeFiles/llvm-dwarfdump.dir/Statistics.cpp.o tools/llvm-dwarfdump/CMakeFiles/llvm-dwarfdump.dir/llvm-dwarfdump.cpp.o -o bin/llvm-dwarfdump  -Wl,-rpath,"\$ORIGIN/../lib:/home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib:"  lib/libLLVMAMDGPUDesc.so.22.0git  lib/libLLVMSPIRVDesc.so.22.0git  lib/libLLVMX86Desc.so.22.0git  lib/libLLVMAMDGPUInfo.so.22.0git  lib/libLLVMSPIRVInfo.so.22.0git  lib/libLLVMX86Info.so.22.0git  lib/libLLVMDebugInfoDWARF.so.22.0git  lib/libLLVMObject.so.22.0git  lib/libLLVMMC.so.22.0git  lib/libLLVMDebugInfoDWARFLowLevel.so.22.0git  lib/libLLVMTargetParser.so.22.0git  lib/libLLVMSupport.so.22.0git  -Wl,-rpath-link,/home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/lib && :
/usr/bin/ld: tools/llvm-dwarfdump/CMakeFiles/llvm-dwarfdump.dir/llvm-dwarfdump.cpp.o: undefined reference to symbol '_ZN4llvm5dwarf6getTagENS_9StringRefE'
/usr/bin/ld: /home/botworker/bbot/amdgpu-offload-ubuntu-22-cmake-build-only/build/./lib/libLLVMBinaryFormat.so.22.0git: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

```

(cherry picked from commit f771f1e)
@Michael137 Michael137 force-pushed the llvm/dwarfdump-tag-filter-to-21.x branch from 2cdd85d to f39a564 Compare November 5, 2025 08:11
@Michael137
Copy link
Author

@swift-ci test

@Michael137
Copy link
Author

@swift-ci test llvm

@Michael137
Copy link
Author

@swift-ci test Windows

@Michael137 Michael137 merged commit 81c6606 into stable/21.x Nov 5, 2025
5 checks passed
@Michael137 Michael137 deleted the llvm/dwarfdump-tag-filter-to-21.x branch November 5, 2025 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants