-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[llvm-dwarfdump] Add a null-check in prettyPrintBaseTypeRef
.
#93156
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
[llvm-dwarfdump] Add a null-check in prettyPrintBaseTypeRef
.
#93156
Conversation
…lvm#93104 Prevent a crash by only printing DWARFUnit-unaware information in cases in which `DWARFUnit* U` is `nullptr`.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-debuginfo Author: None (mgschossmann) ChangesFixes #93104 Prevent a crash by only printing DWARFUnit-unaware information in cases in which Full diff: https://github.com/llvm/llvm-project/pull/93156.diff 1 Files Affected:
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 87a4fc78ceb19..0c28701360b3c 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -240,17 +240,21 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
ArrayRef<uint64_t> Operands,
unsigned Operand) {
assert(Operand < Operands.size() && "operand out of bounds");
- auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
- if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
- OS << " (";
- if (DumpOpts.Verbose)
- OS << format("0x%08" PRIx64 " -> ", Operands[Operand]);
- OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]);
- if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
- OS << " \"" << *Name << "\"";
+ if (U) {
+ auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
+ if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
+ OS << " (";
+ if (DumpOpts.Verbose)
+ OS << format("0x%08" PRIx64 " -> ", Operands[Operand]);
+ OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]);
+ if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
+ OS << " \"" << *Name << "\"";
+ } else {
+ OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
+ Operands[Operand]);
+ }
} else {
- OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
- Operands[Operand]);
+ OS << format(" <base_type ref: 0x%" PRIx64 ">", Operands[Operand]);
}
}
|
Can we add a test for this? |
I have now found a small program (https://godbolt.org/z/eKcvY6caW) that, when compiled with gcc, results in a .debug_loclists section containing such a base type reference, which currently crashes dwarfdump. I can try to add a test case which is based on this. |
Rather than a checked-in binary, could you use assembly code instead? Perhaps using the new https://llvm.org/docs/TestingGuide.html#elaborated-tests functionality |
Unfortunately, I am not aware of any way to reliably generate specific .debug_loclists contents (that include a base type reference) from within the testfile. |
Where'd you get the binary from? Could you rerun that compilation with -S to get assembly code instead, then check that in (and assemble it with llvm-mc inside the test - you can see other symbolizer tests that do this in the related directories) |
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.
Looks good, thanks!
Thanks for the approval. As I do not have write access, could you please commit it for me? |
@mgschossmann Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…93156) Fixes llvm#93104 Prevent a crash by only printing DWARFUnit-unaware information in cases in which `DWARFUnit* U` is `nullptr`. Signed-off-by: Hafidz Muzakky <[email protected]>
Fixes #93104
Prevent a crash by only printing DWARFUnit-unaware information in cases in which
DWARFUnit* U
isnullptr
.