summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-03-08 18:33:40 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-03-08 18:33:40 +0000
commit3b0a54e138ba2603230f77fafd49aa4dd16cfbd6 (patch)
tree7aed21e88f3d309e15cffad2b6360ee3dd2ec643
parent84e571ce751dd02b31a1178b3bd358b238e6a7f0 (diff)
downloadbcm5719-llvm-3b0a54e138ba2603230f77fafd49aa4dd16cfbd6.tar.gz
bcm5719-llvm-3b0a54e138ba2603230f77fafd49aa4dd16cfbd6.zip
[lldb-instr] Support LLDB_RECORD_DUMMY
Extend lldb-instr to insert LLDB_RECORD_DUMMY macros for currently unsupported signatures (void and function pointers). llvm-svn: 355710
-rw-r--r--lldb/lit/tools/lldb-instr/Inputs/foo.cpp1
-rw-r--r--lldb/lit/tools/lldb-instr/Inputs/foo.h1
-rw-r--r--lldb/lit/tools/lldb-instr/TestInstrumentationRecord.test2
-rw-r--r--lldb/lit/tools/lldb-instr/TestInstrumentationRegister.test1
-rw-r--r--lldb/tools/lldb-instr/Instrument.cpp42
5 files changed, 34 insertions, 13 deletions
diff --git a/lldb/lit/tools/lldb-instr/Inputs/foo.cpp b/lldb/lit/tools/lldb-instr/Inputs/foo.cpp
index bef01dc60a6..36a73236a42 100644
--- a/lldb/lit/tools/lldb-instr/Inputs/foo.cpp
+++ b/lldb/lit/tools/lldb-instr/Inputs/foo.cpp
@@ -15,3 +15,4 @@ void Foo::G(const char *fmt...) {}
Foo Foo::H() { return Foo(); }
void Foo::I() const { MACRO_FOO; }
Bar Foo::J() const { return MACRO_BAR(Bar()); }
+Bar Foo::K(void *v) const { return Bar(); }
diff --git a/lldb/lit/tools/lldb-instr/Inputs/foo.h b/lldb/lit/tools/lldb-instr/Inputs/foo.h
index 95c0c0015d6..9e2608e2b9e 100644
--- a/lldb/lit/tools/lldb-instr/Inputs/foo.h
+++ b/lldb/lit/tools/lldb-instr/Inputs/foo.h
@@ -13,4 +13,5 @@ struct Foo {
static Foo H();
void I() const;
Bar J() const;
+ Bar K(void *v) const;
};
diff --git a/lldb/lit/tools/lldb-instr/TestInstrumentationRecord.test b/lldb/lit/tools/lldb-instr/TestInstrumentationRecord.test
index af33df0ab83..cd294140172 100644
--- a/lldb/lit/tools/lldb-instr/TestInstrumentationRecord.test
+++ b/lldb/lit/tools/lldb-instr/TestInstrumentationRecord.test
@@ -18,3 +18,5 @@
# CHECK-NOT: LLDB_RECORD_METHOD_CONST_NO_ARGS(void, Foo, I);
# CHECK: LLDB_RECORD_METHOD_CONST_NO_ARGS(Bar, Foo, J);
# CHECK-NOT: LLDB_RECORD_RESULT(Bar());
+# CHECK: LLDB_RECORD_DUMMY(Bar, Foo, K, (void *), v);
+# CHECK-NOT: LLDB_RECORD_RESULT(Bar());
diff --git a/lldb/lit/tools/lldb-instr/TestInstrumentationRegister.test b/lldb/lit/tools/lldb-instr/TestInstrumentationRegister.test
index 651880c4a50..0b15944a9a7 100644
--- a/lldb/lit/tools/lldb-instr/TestInstrumentationRegister.test
+++ b/lldb/lit/tools/lldb-instr/TestInstrumentationRegister.test
@@ -13,4 +13,5 @@
# CHECK: LLDB_REGISTER_STATIC_METHOD(int, Foo, F, (int));
# CHECK-NOT: LLDB_REGISTER_STATIC_METHOD(void, Foo, G
# CHECK-NOT: LLDB_REGISTER_METHOD_CONST(void, Foo, I, ());
+# CHECK-NOT: LLDB_REGISTER_METHOD_CONST(Bar, Foo, K, (void*));
# CHECK: }
diff --git a/lldb/tools/lldb-instr/Instrument.cpp b/lldb/tools/lldb-instr/Instrument.cpp
index 476b5e6a4bb..c46afb45673 100644
--- a/lldb/tools/lldb-instr/Instrument.cpp
+++ b/lldb/tools/lldb-instr/Instrument.cpp
@@ -100,6 +100,19 @@ static std::string GetRecordConstructorMacro(StringRef Class,
return OS.str();
}
+static std::string GetRecordDummyMacro(StringRef Result, StringRef Class,
+ StringRef Method, StringRef Signature,
+ StringRef Values) {
+ assert(!Values.empty());
+ std::string Macro;
+ llvm::raw_string_ostream OS(Macro);
+
+ OS << "LLDB_RECORD_DUMMY(" << Result << ", " << Class << ", " << Method;
+ OS << ", (" << Signature << "), " << Values << ");\n\n";
+
+ return OS.str();
+}
+
static std::string GetRegisterConstructorMacro(StringRef Class,
StringRef Signature) {
std::string Macro;
@@ -170,24 +183,21 @@ public:
PrintingPolicy Policy(Context.getLangOpts());
Policy.Bool = true;
+ // Unsupported signatures get a dummy macro.
+ bool ShouldInsertDummy = false;
+
// Collect the functions parameter types and names.
std::vector<std::string> ParamTypes;
std::vector<std::string> ParamNames;
for (auto *P : Decl->parameters()) {
QualType T = P->getType();
-
- // Currently we don't support functions that have function pointers as an
- // argument.
- if (T->isFunctionPointerType())
- return false;
-
- // Currently we don't support functions that have void pointers as an
- // argument.
- if (T->isVoidPointerType())
- return false;
-
ParamTypes.push_back(T.getAsString(Policy));
ParamNames.push_back(P->getNameAsString());
+
+ // Currently we don't support functions that have void pointers or
+ // function pointers as an argument, in which case we insert a dummy
+ // macro.
+ ShouldInsertDummy |= T->isFunctionPointerType() || T->isVoidPointerType();
}
// Convert the two lists to string for the macros.
@@ -199,7 +209,13 @@ public:
// Construct the macros.
std::string Macro;
- if (isa<CXXConstructorDecl>(Decl)) {
+ if (ShouldInsertDummy) {
+ // Don't insert a register call for dummy macros.
+ Macro = GetRecordDummyMacro(
+ ReturnType.getAsString(Policy), Record->getNameAsString(),
+ Decl->getNameAsString(), ParamTypesStr, ParamNamesStr);
+
+ } else if (isa<CXXConstructorDecl>(Decl)) {
llvm::outs() << GetRegisterConstructorMacro(Record->getNameAsString(),
ParamTypesStr);
@@ -229,7 +245,7 @@ public:
// If the function returns a class or struct, we need to wrap its return
// statement(s).
- if (ReturnType->isStructureOrClassType()) {
+ if (!ShouldInsertDummy && ReturnType->isStructureOrClassType()) {
SBReturnVisitor Visitor(MyRewriter);
Visitor.TraverseDecl(Decl);
}
OpenPOWER on IntegriCloud