aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
diff options
context:
space:
mode:
authorZequan Wu <zequanwu@google.com>2025-03-17 14:01:06 -0700
committerGitHub <noreply@github.com>2025-03-17 17:01:06 -0400
commit6dbe82f061bf494bc91ed458726c8080269f64f6 (patch)
tree710e0b4f89f82ab1e93a357ab737858d6286d0d3 /llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
parent2e6402ca2c6c33ccf41d74383a8e3afb82489410 (diff)
downloadllvm-6dbe82f061bf494bc91ed458726c8080269f64f6.zip
llvm-6dbe82f061bf494bc91ed458726c8080269f64f6.tar.gz
llvm-6dbe82f061bf494bc91ed458726c8080269f64f6.tar.bz2
[NFC][DebugInfo] Wrap DILineInfo return type with std::optional to handle missing debug info. (#129792)
Currently, `DIContext::getLineInfoForAddress` and `DIContext::getLineInfoForDataAddress` returns empty DILineInfo when the debug info is missing for the given address. This is not differentiable with the case when debug info is found for the given address but the debug info is default value (filename:linenum is <invalid>:0). This change wraps the return types of `DIContext::getLineInfoForAddress` and `DIContext::getLineInfoForDataAddress` with `std::optional`.
Diffstat (limited to 'llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp')
-rw-r--r--llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index f099bf5..82dda93 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -565,9 +565,13 @@ static bool lookup(ObjectFile &Obj, DWARFContext &DICtx, uint64_t Address,
// TODO: it is neccessary to set proper SectionIndex here.
// object::SectionedAddress::UndefSection works for only absolute addresses.
- if (DILineInfo LineInfo = DICtx.getLineInfoForAddress(
- {Lookup, object::SectionedAddress::UndefSection}))
+ if (DILineInfo LineInfo =
+ DICtx
+ .getLineInfoForAddress(
+ {Lookup, object::SectionedAddress::UndefSection})
+ .value_or(DILineInfo())) {
LineInfo.dump(OS);
+ }
return true;
}