Skip to content

Commit e64ce7d

Browse files
committed
fixup! make mangled name last component in label; remove need for splitting helper
1 parent 494b490 commit e64ce7d

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

lldb/include/lldb/Expression/Expression.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,11 @@ class Expression {
102102
///
103103
/// The format being:
104104
///
105-
/// <prefix>:<mangled name>:<module uid>:<symbol uid>
105+
/// <prefix>:<module uid>:<symbol uid>:<mangled name>
106106
///
107107
/// The label string needs to stay valid for the entire lifetime
108108
/// of this object.
109109
struct FunctionCallLabel {
110-
/// Name to use when searching for the function symbol in
111-
/// \c module_id. For most function calls this will be a
112-
/// mangled name. In cases where a mangled name can't be used,
113-
/// this will be the function name.
114-
llvm::StringRef lookup_name;
115-
116110
/// Unique identifier of the lldb_private::Module
117111
/// which contains the symbol identified by \c symbol_id.
118112
lldb::user_id_t module_id;
@@ -122,14 +116,23 @@ struct FunctionCallLabel {
122116
/// be the DIE UID.
123117
lldb::user_id_t symbol_id;
124118

119+
/// Name to use when searching for the function symbol in
120+
/// \c module_id. For most function calls this will be a
121+
/// mangled name. In cases where a mangled name can't be used,
122+
/// this will be the function name.
123+
///
124+
/// NOTE: kept as last element so we don't have to worry about
125+
/// ':' in the mangled name when parsing the label.
126+
llvm::StringRef lookup_name;
127+
125128
/// Decodes the specified function \c label into a \c FunctionCallLabel.
126129
static llvm::Expected<FunctionCallLabel> fromString(llvm::StringRef label);
127130

128131
/// Encode this FunctionCallLabel into it's string representation.
129132
///
130133
/// The representation roundtrips through \c fromString:
131134
/// \code{.cpp}
132-
/// llvm::StringRef encoded = "$__lldb_func:_Z3foov:0x0:0x0";
135+
/// llvm::StringRef encoded = "$__lldb_func:0x0:0x0:_Z3foov";
133136
/// FunctionCallLabel label = *fromString(label);
134137
///
135138
/// assert (label.toString() == encoded);
@@ -142,13 +145,6 @@ struct FunctionCallLabel {
142145
/// from JITted expressions.
143146
inline constexpr llvm::StringRef FunctionCallLabelPrefix = "$__lldb_func";
144147

145-
/// Returns the components of the specified function call label.
146-
///
147-
/// The format of \c label is described in \c FunctionCallLabel.
148-
/// The label prefix is not one of the components.
149-
llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
150-
splitFunctionCallLabel(llvm::StringRef label);
151-
152148
} // namespace lldb_private
153149

154150
#endif // LLDB_EXPRESSION_EXPRESSION_H

lldb/source/Expression/Expression.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ Expression::Expression(ExecutionContextScope &exe_scope)
3131
assert(m_target_wp.lock());
3232
}
3333

34-
llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
35-
lldb_private::splitFunctionCallLabel(llvm::StringRef label) {
34+
/// Returns the components of the specified function call label.
35+
///
36+
/// The format of \c label is described in \c FunctionCallLabel.
37+
/// The label prefix is not one of the components.
38+
static llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
39+
splitFunctionCallLabel(llvm::StringRef label) {
3640
if (!label.consume_front(FunctionCallLabelPrefix))
3741
return llvm::createStringError(
3842
"expected function call label prefix not found in %s", label.data());
@@ -60,25 +64,26 @@ lldb_private::FunctionCallLabel::fromString(llvm::StringRef label) {
6064

6165
const auto &components = *components_or_err;
6266

63-
llvm::StringRef module_label = components[1];
64-
llvm::StringRef die_label = components[2];
67+
llvm::StringRef module_label = components[0];
68+
llvm::StringRef die_label = components[1];
6569

6670
lldb::user_id_t module_id = 0;
6771
if (module_label.consumeInteger(0, module_id))
6872
return llvm::createStringError(
69-
llvm::formatv("failed to parse module ID from '{0}'.", components[1]));
73+
llvm::formatv("failed to parse module ID from '{0}'.", components[0]));
7074

7175
lldb::user_id_t die_id;
7276
if (die_label.consumeInteger(/*Radix=*/0, die_id))
7377
return llvm::createStringError(
74-
llvm::formatv("failed to parse DIE ID from '{0}'.", components[2]));
78+
llvm::formatv("failed to parse DIE ID from '{0}'.", components[1]));
7579

76-
return FunctionCallLabel{/*.lookup_name=*/components[0],
77-
/*.module_id=*/module_id, /*.symbol_id=*/die_id};
80+
return FunctionCallLabel{/*.module_id=*/module_id,
81+
/*.symbol_id=*/die_id,
82+
/*.lookup_name=*/components[2]};
7883
}
7984

8085
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)
86+
return llvm::formatv("{0}:{1:x}:{2:x}:{3}", FunctionCallLabelPrefix,
87+
module_id, symbol_id, lookup_name)
8388
.str();
8489
}

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

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

270-
return FunctionCallLabel{/*.lookup_name=*/name,
271-
/*module_id=*/module_id,
272-
/*symbol_id=*/die_id}
270+
return FunctionCallLabel{
271+
/*module_id=*/module_id,
272+
/*symbol_id=*/die_id,
273+
/*.lookup_name=*/name
274+
}
273275
.toString();
274276
}
275277

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9044,13 +9044,13 @@ ConstString TypeSystemClang::DeclGetName(void *opaque_decl) {
90449044

90459045
static ConstString
90469046
ExtractMangledNameFromFunctionCallLabel(llvm::StringRef label) {
9047-
auto components_or_err = splitFunctionCallLabel(label);
9048-
if (!components_or_err) {
9049-
llvm::consumeError(components_or_err.takeError());
9047+
auto label_or_err = FunctionCallLabel::fromString(label);
9048+
if (!label_or_err) {
9049+
llvm::consumeError(label_or_err.takeError());
90509050
return {};
90519051
}
90529052

9053-
llvm::StringRef mangled = (*components_or_err)[0];
9053+
llvm::StringRef mangled = label_or_err->lookup_name;
90549054
if (Mangled::IsMangledName(mangled))
90559055
return ConstString(mangled);
90569056

0 commit comments

Comments
 (0)