summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
diff options
context:
space:
mode:
authorAlex Langford <alangford@apple.com>2024-05-03 11:05:11 -0700
committerGitHub <noreply@github.com>2024-05-03 11:05:11 -0700
commite2b3e4ea9f2d0cb34d197439cfbc5090cdacb124 (patch)
tree4688345bbc1b710c059f777e1d5e0c3293814fcf /lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
parent401ecb4ccc2a319e55155b6a8558aa3478e5405e (diff)
[lldb][NFCI] Unify DW_TAG -> string conversions (#90657)
The high level goal is to have 1 way of converting a DW_TAG value into a human-readable string. There are 3 ways this change accomplishes that: 1.) Changing DW_TAG_value_to_name to not create custom error strings. The way it was doing this is error-prone: Specifically, it was using a function-local static char buffer and handing out a pointer to it. Initialization of this is thread-safe, but mutating it is definitely not. Multiple threads that want to call this function could step on each others toes. The implementation in this patch sidesteps the issue by just returning a StringRef with no mention of the tag value in it. 2.) Changing all uses of DW_TAG_value_to_name to log the value of the tag since the function doesn't create a string with the value in it anymore. 3.) Removing `DWARFBaseDIE::GetTagAsCString()`. Callers should call DW_TAG_value_to_name on the tag directly.
Diffstat (limited to 'lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp')
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp16
1 files changed, 5 insertions, 11 deletions
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
index 9a88aed85e97..1f0e10ef2701 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.cpp
@@ -15,18 +15,12 @@
namespace lldb_private::plugin {
namespace dwarf {
-const char *DW_TAG_value_to_name(uint32_t val) {
- static char invalid[100];
-
- if (val == 0)
- return "NULL";
+llvm::StringRef DW_TAG_value_to_name(dw_tag_t tag) {
+ static constexpr llvm::StringLiteral s_unknown_tag_name("<unknown DW_TAG>");
+ if (llvm::StringRef tag_name = llvm::dwarf::TagString(tag); !tag_name.empty())
+ return tag_name;
- llvm::StringRef llvmstr = llvm::dwarf::TagString(val);
- if (llvmstr.empty()) {
- snprintf(invalid, sizeof(invalid), "Unknown DW_TAG constant: 0x%x", val);
- return invalid;
- }
- return llvmstr.data();
+ return s_unknown_tag_name;
}
const char *DW_AT_value_to_name(uint32_t val) {