-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[llvm][dwarfdump] Add --child-tags option to filter by DWARF tags #165720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-llvm-binary-utilities @llvm/pr-subscribers-debuginfo Author: Michael Buch (Michael137) ChangesThis patch adds a new option Motivating examples are:
For tags not known to dwarfdump, we pretend that the tag wasn't specified. Note, this flag only takes effect when Example: Full diff: https://github.com/llvm/llvm-project/pull/165720.diff 3 Files Affected:
diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h
index e7e87bbfebf38..32ce4520dbca7 100644
--- a/llvm/include/llvm/DebugInfo/DIContext.h
+++ b/llvm/include/llvm/DebugInfo/DIContext.h
@@ -202,6 +202,8 @@ struct DIDumpOptions {
bool ShowAddresses = true;
bool ShowChildren = false;
bool ShowParents = false;
+ /// List of DWARF tags to filter children by.
+ llvm::SmallVector<unsigned> ChildTagsFilter;
bool ShowForm = false;
bool SummarizeTypes = false;
bool Verbose = false;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index db5cc37c93f90..7558fbda18459 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -676,7 +676,9 @@ void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
DIDumpOptions ChildDumpOpts = DumpOpts;
ChildDumpOpts.ShowParents = false;
while (Child) {
- Child.dump(OS, Indent + 2, ChildDumpOpts);
+ if (DumpOpts.ChildTagsFilter.empty() ||
+ llvm::is_contained(DumpOpts.ChildTagsFilter, Child.getTag()))
+ Child.dump(OS, Indent + 2, ChildDumpOpts);
Child = Child.getSibling();
}
}
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 79f05278c329d..eb5f8b4af95a6 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -14,6 +14,7 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVectorExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
@@ -241,6 +242,15 @@ static opt<bool>
cat(DwarfDumpCategory));
static alias ShowParentsAlias("p", desc("Alias for --show-parents."),
aliasopt(ShowParents), cl::NotHidden);
+
+static list<std::string>
+ ChildTags("child-tags",
+ desc("When --show-children is specified, show only DIEs with the "
+ "specified DWARF tags."),
+ value_desc("list of DWARF tags"), cat(DwarfDumpCategory));
+static alias TagsAlias("t", desc("Alias for --child-tags."),
+ aliasopt(ChildTags), cl::NotHidden);
+
static opt<bool>
ShowForm("show-form",
desc("Show DWARF form types after the DWARF attribute types."),
@@ -329,6 +339,13 @@ static cl::extrahelp
/// @}
//===----------------------------------------------------------------------===//
+static llvm::SmallVector<unsigned>
+makeTagVector(const list<std::string> &TagStrings) {
+ return llvm::map_to_vector(TagStrings, [](const std::string &Tag) {
+ return llvm::dwarf::getTag(Tag);
+ });
+}
+
static void error(Error Err) {
if (!Err)
return;
@@ -355,6 +372,7 @@ static DIDumpOptions getDumpOpts(DWARFContext &C) {
DumpOpts.ShowAddresses = !Diff;
DumpOpts.ShowChildren = ShowChildren;
DumpOpts.ShowParents = ShowParents;
+ DumpOpts.ChildTagsFilter = makeTagVector(ChildTags);
DumpOpts.ShowForm = ShowForm;
DumpOpts.SummarizeTypes = SummarizeTypes;
DumpOpts.Verbose = Verbose;
@@ -898,6 +916,12 @@ int main(int argc, char **argv) {
Find.empty() && !FindAllApple)
ShowChildren = true;
+ if (!ShowChildren && !ChildTags.empty()) {
+ WithColor::error()
+ << "incompatible arguments: --child-tags requires --show-children";
+ return 1;
+ }
+
// Defaults to a.out if no filenames specified.
if (InputFilenames.empty())
InputFilenames.push_back("a.out");
|
|
Seems OK to me as a feature - though I wonder if we're getting to the point of "should have an arbitrary query language" for querying DWARF at this point? (did we ever end up with the json output for dwarfdump? perhaps that's the way to do it - dump to json and use jquery?) |
i had the exact same line of thought when i initially started implementing this. What nudged me over the edge was that i prefer looking at dwarfdump output over json, though that’s admittedly a selfish reason. Ultimately i thought, if it’s not too much of a maintenance burden, might as well. Of course there’s always complexity of how various options interact, which in this case seemed ok. A more involved querying feature (like filtering by attribute value/existence), which I’d love to have, is probably not worth adding to the current infrastructure because of how complex it would be to implement (afaict). But yea, happy to hear others chime in on usefulness/if it’s acceptable maintenance-wise, and whether there is appetite for something more complete. |
|
I would have probably called it |
adrian-prantl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember how we generate the dwarfdump manpage, but can you make to update it, too? (Unless we generate it from the --help output)
| @@ -202,6 +202,8 @@ struct DIDumpOptions { | |||
| bool ShowAddresses = true; | |||
| bool ShowChildren = false; | |||
| bool ShowParents = false; | |||
| /// List of DWARF tags to filter children by. | |||
| llvm::SmallVector<unsigned> ChildTagsFilter; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is going to be empty most of the time, maybe just use a vector or a SmallVector<0 or 1>?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are multiple ones separated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like with other options, you specify the option multiple times. E.g., dwarfdump -t DW_TAG_foo -t DW_TAG_bar
Other options like --name behave the same
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.
72a3f5b to
3d92747
Compare
| /// List of DWARF tags to filter children by. | ||
| llvm::SmallVector<unsigned, 0> FilterChildTag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this list is sorted by type, so this belongs near the end, probably next to the JsonErrSummaryFile entry.
| @@ -0,0 +1,127 @@ | |||
| # Tests the --filter-child-tag (-t) option. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I don't know if this has been adopted in llvm-dwarfdump tests at all yet, but in many other LLVM binary utils and related code, we've been adopting a policy of ## for comment markers (or otherwise double-comment markers) to indicate true comments and to distinguish them from the lit/FileCheck commands. I find it really helps test readability. Example:
## Tests the --filter-child-tag (-t) option.
# RUN: ...
| @@ -0,0 +1,127 @@ | |||
| # Tests the --filter-child-tag (-t) option. | |||
| # RUN: yaml2obj %s -o %t.o | |||
| # RUN: llvm-dwarfdump %t.o --filter-child-tag=DW_TAG_structure_type | FileCheck %s --check-prefix=ONLY_STRUCT | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would find it easier to follow the test if you did something like:
# RUN: ... | FileCheck --check-prefix=APREFIX
# APREFIX: ...
# RUN: ... | FileCheck --check-prefix=ANOTHER_PREFIX
# ANOTHER_PREFIX: ...
# RUN: llvm-dwarfdump %t.o --option --option \
# RUN: --option --option | \
# RUN: FileCheck --check-prefix=LONG_PREFIX
etc.
You should also break up your longer lines over multiple lines using \ as the line continuation character (see last example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
| DWARF: | ||
| debug_abbrev: | ||
| - Table: | ||
| # 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these comments for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abbreviation codes, but mostly for myself when writing the test. Will remove them
| ShowChildren = true; | ||
|
|
||
| if (!ShowChildren && !FilterChildTag.empty()) { | ||
| WithColor::error() << "incompatible arguments: --filter-child-tag requires " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to just silently do nothing in this case, rather than emitting an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea I don't mind doing that. Other non-composable options already behave that way anyway (like --name and --debug-info=).
|
|
||
| Only dump children whose DWARF tag is one of the specified tags. | ||
| Example usage: | ||
| `llvm-dwarfdump -t DW_TAG_structure_type -t DW_TAG_member -c` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a local docs build? How does this render in the output? What it be better using .. code-block:: c?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea confirmed with the code-block it looks nicer. Fixed
jh7370
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/16635 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/206/builds/8418 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/204/builds/26874 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/26852 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/203/builds/28062 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/27804 Here is the relevant piece of the build log for the reference |
|
Link errors cause we need to link against |
In llvm#165720 we started using a DWARF API 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 ```
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/27664 Here is the relevant piece of the build log for the reference |
In #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 ```
In llvm/llvm-project#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 ```
…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 ([email protected]: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 ([email protected]: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)
…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 ([email protected]: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 ([email protected]: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)
This patch adds a new option
--child-tags(-tfor short), which makes dwarfdump only dump children whose DWARF tag is in the list of tags specified by the user.Motivating examples are:
For tags not known to dwarfdump, we pretend that the tag wasn't specified.
Note, this flag only takes effect when
--show-childrenis set (either explicitly or implicitly). We error out when trying to use the flag without dumping children.Example: