Skip to content

Commit 494b490

Browse files
committed
fixup! move label encoding/decoding into FunctionCallLabel structure
1 parent 07c22ed commit 494b490

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

lldb/include/lldb/Expression/Expression.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ struct FunctionCallLabel {
121121
/// perform the function call. For example, for DWARF this would
122122
/// be the DIE UID.
123123
lldb::user_id_t symbol_id;
124+
125+
/// Decodes the specified function \c label into a \c FunctionCallLabel.
126+
static llvm::Expected<FunctionCallLabel> fromString(llvm::StringRef label);
127+
128+
/// Encode this FunctionCallLabel into it's string representation.
129+
///
130+
/// The representation roundtrips through \c fromString:
131+
/// \code{.cpp}
132+
/// llvm::StringRef encoded = "$__lldb_func:_Z3foov:0x0:0x0";
133+
/// FunctionCallLabel label = *fromString(label);
134+
///
135+
/// assert (label.toString() == encoded);
136+
/// assert (*fromString(label.toString()) == label);
137+
/// \endcode
138+
std::string toString() const;
124139
};
125140

126141
/// LLDB attaches this prefix to mangled names of functions that it get called
@@ -134,10 +149,6 @@ inline constexpr llvm::StringRef FunctionCallLabelPrefix = "$__lldb_func";
134149
llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
135150
splitFunctionCallLabel(llvm::StringRef label);
136151

137-
// Decodes the function label into a \c FunctionCallLabel.
138-
llvm::Expected<FunctionCallLabel>
139-
makeFunctionCallLabel(llvm::StringRef label);
140-
141152
} // namespace lldb_private
142153

143154
#endif // LLDB_EXPRESSION_EXPRESSION_H

lldb/source/Expression/Expression.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ lldb_private::splitFunctionCallLabel(llvm::StringRef label) {
5151
}
5252

5353
llvm::Expected<FunctionCallLabel>
54-
lldb_private::makeFunctionCallLabel(llvm::StringRef label) {
54+
lldb_private::FunctionCallLabel::fromString(llvm::StringRef label) {
5555
auto components_or_err = splitFunctionCallLabel(label);
5656
if (!components_or_err)
5757
return llvm::joinErrors(
@@ -76,3 +76,9 @@ lldb_private::makeFunctionCallLabel(llvm::StringRef label) {
7676
return FunctionCallLabel{/*.lookup_name=*/components[0],
7777
/*.module_id=*/module_id, /*.symbol_id=*/die_id};
7878
}
79+
80+
std::string lldb_private::FunctionCallLabel::toString() const {
81+
return llvm::formatv("{0}:{1}:{2:x}:{3:x}", FunctionCallLabelPrefix,
82+
lookup_name, module_id, symbol_id)
83+
.str();
84+
}

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ ResolveFunctionCallLabel(llvm::StringRef name,
790790
if (!sc.target_sp)
791791
return llvm::createStringError("target not available.");
792792

793-
auto label_or_err = makeFunctionCallLabel(name);
793+
auto label_or_err = FunctionCallLabel::fromString(name);
794794
if (!label_or_err)
795795
return llvm::joinErrors(
796796
llvm::createStringError("failed to create FunctionCallLabel from: %s",

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,10 @@ static std::optional<std::string> MakeLLDBFuncAsmLabel(const DWARFDIE &die) {
267267
if (die_id == LLDB_INVALID_UID)
268268
return std::nullopt;
269269

270-
return llvm::formatv("{0}:{1}:{2:x}:{3:x}", FunctionCallLabelPrefix, name,
271-
module_id, die_id)
272-
.str();
270+
return FunctionCallLabel{/*.lookup_name=*/name,
271+
/*module_id=*/module_id,
272+
/*symbol_id=*/die_id}
273+
.toString();
273274
}
274275

275276
TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,

0 commit comments

Comments
 (0)