Skip to content

Commit 377ba31

Browse files
committed
fixup! move FunctionCallLabel APIs into Expression component
1 parent 71b0eab commit 377ba31

File tree

6 files changed

+64
-78
lines changed

6 files changed

+64
-78
lines changed

lldb/include/lldb/Expression/Expression.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ struct FunctionCallLabel {
127127
/// from JITted expressions.
128128
inline constexpr llvm::StringRef FunctionCallLabelPrefix = "$__lldb_func";
129129

130+
/// Returns the components of the specified function call label.
131+
///
132+
/// The format of \c label is described in \c FunctionCallLabel.
133+
/// The label prefix is not one of the components.
134+
llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
135+
splitFunctionCallLabel(llvm::StringRef label);
136+
137+
// Decodes the function label into a \c FunctionCallLabel.
138+
llvm::Expected<FunctionCallLabel>
139+
makeFunctionCallLabel(llvm::StringRef label);
140+
130141
} // namespace lldb_private
131142

132143
#endif // LLDB_EXPRESSION_EXPRESSION_H

lldb/include/lldb/Symbol/TypeSystem.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -549,21 +549,6 @@ class TypeSystem : public PluginInterface,
549549
return m_has_forcefully_completed_types;
550550
}
551551

552-
/// Returns the components of the specified function call label.
553-
///
554-
/// The format of \c label is described in \c FunctionCallLabel.
555-
/// The label prefix is not one of the components.
556-
virtual llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
557-
splitFunctionCallLabel(llvm::StringRef label) const {
558-
return llvm::createStringError("Not implemented.");
559-
}
560-
561-
// Decodes the function label into a \c FunctionCallLabel.
562-
virtual llvm::Expected<FunctionCallLabel>
563-
makeFunctionCallLabel(llvm::StringRef label) const {
564-
return llvm::createStringError("Not implemented.");
565-
}
566-
567552
protected:
568553
SymbolFile *m_sym_file = nullptr;
569554
/// Used for reporting statistics.

lldb/source/Expression/Expression.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include "lldb/Target/ExecutionContextScope.h"
1111
#include "lldb/Target/Target.h"
1212

13+
#include "llvm/ADT/StringRef.h"
14+
#include "llvm/ADT/SmallVector.h"
15+
#include "llvm/Support/Error.h"
16+
1317
using namespace lldb_private;
1418

1519
Expression::Expression(Target &target)
@@ -26,3 +30,49 @@ Expression::Expression(ExecutionContextScope &exe_scope)
2630
m_jit_end_addr(LLDB_INVALID_ADDRESS) {
2731
assert(m_target_wp.lock());
2832
}
33+
34+
llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
35+
lldb_private::splitFunctionCallLabel(llvm::StringRef label) {
36+
if (!label.consume_front(FunctionCallLabelPrefix))
37+
return llvm::createStringError(
38+
"expected function call label prefix not found in %s", label.data());
39+
if (!label.consume_front(":"))
40+
return llvm::createStringError(
41+
"incorrect format: expected ':' as the first character.");
42+
43+
llvm::SmallVector<llvm::StringRef, 3> components;
44+
label.split(components, ":");
45+
46+
if (components.size() != 3)
47+
return llvm::createStringError(
48+
"incorrect format: too many label subcomponents.");
49+
50+
return components;
51+
}
52+
53+
llvm::Expected<FunctionCallLabel>
54+
lldb_private::makeFunctionCallLabel(llvm::StringRef label) {
55+
auto components_or_err = splitFunctionCallLabel(label);
56+
if (!components_or_err)
57+
return llvm::joinErrors(
58+
llvm::createStringError("Failed to decode function call label"),
59+
components_or_err.takeError());
60+
61+
const auto &components = *components_or_err;
62+
63+
llvm::StringRef module_label = components[1];
64+
llvm::StringRef die_label = components[2];
65+
66+
lldb::user_id_t module_id = 0;
67+
if (module_label.consumeInteger(0, module_id))
68+
return llvm::createStringError(
69+
llvm::formatv("failed to parse module ID from '{0}'.", components[1]));
70+
71+
lldb::user_id_t die_id;
72+
if (die_label.consumeInteger(/*Radix=*/0, die_id))
73+
return llvm::createStringError(
74+
llvm::formatv("failed to parse DIE ID from '{0}'.", components[2]));
75+
76+
return FunctionCallLabel{/*.lookup_name=*/components[0],
77+
/*.module_id=*/module_id, /*.symbol_id=*/die_id};
78+
}

lldb/source/Expression/IRExecutionUnit.cpp

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

793-
auto ts_or_err = sc.target_sp->GetScratchTypeSystemForLanguage(
794-
lldb::eLanguageTypeC_plus_plus);
795-
if (!ts_or_err || !*ts_or_err)
796-
return llvm::joinErrors(
797-
llvm::createStringError(
798-
"failed to find scratch C++ TypeSystem for current target."),
799-
ts_or_err.takeError());
800-
801-
auto ts_sp = *ts_or_err;
802-
803-
auto label_or_err = ts_sp->makeFunctionCallLabel(name);
793+
auto label_or_err = makeFunctionCallLabel(name);
804794
if (!label_or_err)
805795
return llvm::joinErrors(
806796
llvm::createStringError("failed to create FunctionCallLabel from: %s",

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

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9053,6 +9053,8 @@ ConstString TypeSystemClang::DeclGetMangledName(void *opaque_decl) {
90539053
if (!mc || !mc->shouldMangleCXXName(nd))
90549054
return {};
90559055

9056+
// We have a LLDB FunctionCallLabel instead of an ordinary mangled name.
9057+
// Extract the mangled name out of this label.
90569058
if (const auto *label = nd->getAttr<AsmLabelAttr>()) {
90579059
if (auto components_or_err = splitFunctionCallLabel(label->getLabel()))
90589060
return ConstString((*components_or_err)[0]);
@@ -9782,49 +9784,3 @@ void TypeSystemClang::LogCreation() const {
97829784
LLDB_LOG(log, "Created new TypeSystem for (ASTContext*){0:x} '{1}'",
97839785
&getASTContext(), getDisplayName());
97849786
}
9785-
9786-
llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
9787-
TypeSystemClang::splitFunctionCallLabel(llvm::StringRef label) const {
9788-
if (!label.consume_front(FunctionCallLabelPrefix))
9789-
return llvm::createStringError(
9790-
"expected function call label prefix not found in %s", label.data());
9791-
if (!label.consume_front(":"))
9792-
return llvm::createStringError(
9793-
"incorrect format: expected ':' as the first character.");
9794-
9795-
llvm::SmallVector<llvm::StringRef, 3> components;
9796-
label.split(components, ":");
9797-
9798-
if (components.size() != 3)
9799-
return llvm::createStringError(
9800-
"incorrect format: too many label subcomponents.");
9801-
9802-
return components;
9803-
}
9804-
9805-
llvm::Expected<FunctionCallLabel>
9806-
TypeSystemClang::makeFunctionCallLabel(llvm::StringRef label) const {
9807-
auto components_or_err = splitFunctionCallLabel(label);
9808-
if (!components_or_err)
9809-
return llvm::joinErrors(
9810-
llvm::createStringError("Failed to decode function call label"),
9811-
components_or_err.takeError());
9812-
9813-
const auto &components = *components_or_err;
9814-
9815-
llvm::StringRef module_label = components[1];
9816-
llvm::StringRef die_label = components[2];
9817-
9818-
lldb::user_id_t module_id = 0;
9819-
if (module_label.consumeInteger(0, module_id))
9820-
return llvm::createStringError(
9821-
llvm::formatv("failed to parse module ID from '{0}'.", components[1]));
9822-
9823-
lldb::user_id_t die_id;
9824-
if (die_label.consumeInteger(/*Radix=*/0, die_id))
9825-
return llvm::createStringError(
9826-
llvm::formatv("failed to parse DIE ID from '{0}'.", components[2]));
9827-
9828-
return FunctionCallLabel{/*.lookup_name=*/components[0],
9829-
/*.module_id=*/module_id, /*.symbol_id=*/die_id};
9830-
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,6 @@ class TypeSystemClang : public TypeSystem {
10991099
lldb::opaque_compiler_type_t type, Stream &s,
11001100
lldb::DescriptionLevel level = lldb::eDescriptionLevelFull) override;
11011101

1102-
llvm::Expected<llvm::SmallVector<llvm::StringRef, 3>>
1103-
splitFunctionCallLabel(llvm::StringRef label) const override;
1104-
1105-
llvm::Expected<FunctionCallLabel>
1106-
makeFunctionCallLabel(llvm::StringRef label) const override;
1107-
11081102
static void DumpTypeName(const CompilerType &type);
11091103

11101104
static clang::EnumDecl *GetAsEnumDecl(const CompilerType &type);

0 commit comments

Comments
 (0)