diff options
| author | Pavel Labath <labath@google.com> | 2018-05-03 10:57:16 +0000 |
|---|---|---|
| committer | Pavel Labath <labath@google.com> | 2018-05-03 10:57:16 +0000 |
| commit | 90b0a53499c98ec3b4903f1f4f0c7b404c236ab3 (patch) | |
| tree | 69e67d49295dc4a660d7680659a27e32f1361e69 /lldb/lit/SymbolFile | |
| parent | 39196a1dd387cdd55d3ee6c9269c43524aeb3ed3 (diff) | |
| download | bcm5719-llvm-90b0a53499c98ec3b4903f1f4f0c7b404c236ab3.tar.gz bcm5719-llvm-90b0a53499c98ec3b4903f1f4f0c7b404c236ab3.zip | |
lldb-test symbols: Add ability to do name-based lookup
Summary:
lldb-test already had the ability to dump all symbol information in a
module. This is interesting, but it can be too verbose, and it also does
not use the same APIs that lldb uses to query symbol information. The
last part is interesting to me now, because I am about to add DWARF v5
debug_names support, which needs to implement these APIs.
This patch adds a set of arguments to lldb-test, which modify it's
behavior from dumping all symbols to dumping only the requested
information:
- --find={function,namespace,type,variable} - search for the given
kind of objects.
- --name - the name to search for.
- --regex - whether to treat the "name" as a regular expression. This is
not available for all lookup types (we do not have the required APIs
for namespaces and types).
- --context - specifies the context, which can be used to restrict the
search. This argument takes a variable name (which must be defined and
be unique), and we then use the context that this variable is defined
in as the search context.
- --function-flags={auto,full,base,method,selector} - a set of flags to
further restrict the search for function symbols.
Together, these flags and their combinations cover the main SymbolFile
entry points which I will need to modify for the accelerator table
support, and so I plan to do most of the regression testing this way.
(I've also found this a useful tool for exploration of what the given
APIs are supposed to do.)
I add a couple of tests to demonstrate the usage of the usage of the
various options, and also an xfailed test which demonstrates a bug I
found while playing with this. The only requirement for these tests is
the presence of lld -- the should run on any platform which is able to
build lldb.
These tests use c++ code as input, but this isn't a requirement. It is also
possible to use IR, assembly or json to create the test module.
Reviewers: davide, zturner, asmith, JDevlieghere, clayborg, alexshap
Subscribers: mgorny, aprantl, lldb-commits
Differential Revision: https://reviews.llvm.org/D46318
llvm-svn: 331447
Diffstat (limited to 'lldb/lit/SymbolFile')
| -rw-r--r-- | lldb/lit/SymbolFile/DWARF/find-basic-function.cpp | 67 | ||||
| -rw-r--r-- | lldb/lit/SymbolFile/DWARF/find-basic-namespace.cpp | 29 | ||||
| -rw-r--r-- | lldb/lit/SymbolFile/DWARF/find-basic-type.cpp | 38 | ||||
| -rw-r--r-- | lldb/lit/SymbolFile/DWARF/find-basic-variable.cpp | 55 | ||||
| -rw-r--r-- | lldb/lit/SymbolFile/DWARF/find-type-in-function.cpp | 24 | ||||
| -rw-r--r-- | lldb/lit/SymbolFile/DWARF/lit.local.cfg | 1 |
6 files changed, 214 insertions, 0 deletions
diff --git a/lldb/lit/SymbolFile/DWARF/find-basic-function.cpp b/lldb/lit/SymbolFile/DWARF/find-basic-function.cpp new file mode 100644 index 00000000000..39d81ae7eb3 --- /dev/null +++ b/lldb/lit/SymbolFile/DWARF/find-basic-function.cpp @@ -0,0 +1,67 @@ +// REQUIRES: lld + +// RUN: clang %s -g -c -o %t.o --target=x86_64-pc-linux +// RUN: ld.lld %t.o -o %t +// RUN: lldb-test symbols --name=foo --find=function --function-flags=base %t | \ +// RUN: FileCheck --check-prefix=BASE %s +// RUN: lldb-test symbols --name=foo --find=function --function-flags=method %t | \ +// RUN: FileCheck --check-prefix=METHOD %s +// RUN: lldb-test symbols --name=foo --find=function --function-flags=full %t | \ +// RUN: FileCheck --check-prefix=FULL %s +// RUN: lldb-test symbols --name=foo --context=context --find=function --function-flags=base %t | \ +// RUN: FileCheck --check-prefix=CONTEXT %s +// RUN: lldb-test symbols --name=not_there --find=function %t | \ +// RUN: FileCheck --check-prefix=EMPTY %s + +// BASE: Found 4 functions: +// BASE-DAG: name = "foo()", mangled = "_Z3foov" +// BASE-DAG: name = "foo(int)", mangled = "_Z3fooi" +// BASE-DAG: name = "bar::foo()", mangled = "_ZN3bar3fooEv" +// BASE-DAG: name = "bar::baz::foo()", mangled = "_ZN3bar3baz3fooEv" + +// METHOD: Found 3 functions: +// METHOD-DAG: name = "sbar::foo()", mangled = "_ZN4sbar3fooEv" +// METHOD-DAG: name = "sbar::foo(int)", mangled = "_ZN4sbar3fooEi" +// METHOD-DAG: name = "ffbar()::sbar::foo()", mangled = "_ZZ5ffbarvEN4sbar3fooEv" + +// FULL: Found 2 functions: +// FULL-DAG: name = "foo()", mangled = "_Z3foov" +// FULL-DAG: name = "foo(int)", mangled = "_Z3fooi" + +// CONTEXT: Found 1 functions: +// CONTEXT-DAG: name = "bar::foo()", mangled = "_ZN3bar3fooEv" + +// EMPTY: Found 0 functions: + +void foo() {} +void foo(int) {} + +namespace bar { +int context; +void foo() {} +namespace baz { +void foo() {} +} // namespace baz +} // namespace bar + +struct foo {}; +void fbar(struct foo) {} + +void Foo() {} + +struct sbar { + void foo(); + static void foo(int); +}; +void sbar::foo() {} +void sbar::foo(int) {} + +void ffbar() { + struct sbar { + void foo() {} + }; + sbar a; + a.foo(); +} + +extern "C" void _start() {} diff --git a/lldb/lit/SymbolFile/DWARF/find-basic-namespace.cpp b/lldb/lit/SymbolFile/DWARF/find-basic-namespace.cpp new file mode 100644 index 00000000000..393cc7eab76 --- /dev/null +++ b/lldb/lit/SymbolFile/DWARF/find-basic-namespace.cpp @@ -0,0 +1,29 @@ +// REQUIRES: lld + +// RUN: clang %s -g -c -o %t.o --target=x86_64-pc-linux +// RUN: ld.lld %t.o -o %t +// RUN: lldb-test symbols --name=foo --find=namespace %t | \ +// RUN: FileCheck --check-prefix=FOO %s +// RUN: lldb-test symbols --name=foo --find=namespace --context=context %t | \ +// RUN: FileCheck --check-prefix=CONTEXT %s +// RUN: lldb-test symbols --name=not_there --find=namespace %t | \ +// RUN: FileCheck --check-prefix=EMPTY %s + +// FOO: Found namespace: foo + +// CONTEXT: Found namespace: bar::foo + +// EMPTY: Namespace not found. + +namespace foo { +int X; +} + +namespace bar { +int context; +namespace foo { +int X; +} +} // namespace bar + +extern "C" void _start() {} diff --git a/lldb/lit/SymbolFile/DWARF/find-basic-type.cpp b/lldb/lit/SymbolFile/DWARF/find-basic-type.cpp new file mode 100644 index 00000000000..b67ef60b7e9 --- /dev/null +++ b/lldb/lit/SymbolFile/DWARF/find-basic-type.cpp @@ -0,0 +1,38 @@ +// REQUIRES: lld + +// RUN: clang %s -g -c -o %t.o --target=x86_64-pc-linux +// RUN: ld.lld %t.o -o %t +// RUN: lldb-test symbols --name=foo --find=type %t | \ +// RUN: FileCheck --check-prefix=NAME %s +// RUN: lldb-test symbols --name=foo --context=context --find=type %t | \ +// RUN: FileCheck --check-prefix=CONTEXT %s +// RUN: lldb-test symbols --name=not_there --find=type %t | \ +// RUN: FileCheck --check-prefix=EMPTY %s + +// EMPTY: Found 0 types: +// NAME: Found 4 types: +// CONTEXT: Found 1 types: +struct foo { }; +// NAME-DAG: name = "foo", {{.*}} decl = find-basic-type.cpp:[[@LINE-1]] + +namespace bar { +int context; +struct foo {}; +// NAME-DAG: name = "foo", {{.*}} decl = find-basic-type.cpp:[[@LINE-1]] +// CONTEXT-DAG: name = "foo", {{.*}} decl = find-basic-type.cpp:[[@LINE-2]] +namespace baz { +struct foo {}; +// NAME-DAG: name = "foo", {{.*}} decl = find-basic-type.cpp:[[@LINE-1]] +} +} + +struct sbar { + struct foo {}; +// NAME-DAG: name = "foo", {{.*}} decl = find-basic-type.cpp:[[@LINE-1]] +}; + +struct foobar {}; + +struct Foo {}; + +extern "C" void _start(foo, bar::foo, bar::baz::foo, sbar::foo, foobar, Foo) {} diff --git a/lldb/lit/SymbolFile/DWARF/find-basic-variable.cpp b/lldb/lit/SymbolFile/DWARF/find-basic-variable.cpp new file mode 100644 index 00000000000..729d493cca7 --- /dev/null +++ b/lldb/lit/SymbolFile/DWARF/find-basic-variable.cpp @@ -0,0 +1,55 @@ +// REQUIRES: lld + +// RUN: clang %s -g -c -o %t.o --target=x86_64-pc-linux +// RUN: ld.lld %t.o -o %t +// RUN: lldb-test symbols --name=foo --find=variable --context=context %t | \ +// RUN: FileCheck --check-prefix=CONTEXT %s +// RUN: lldb-test symbols --name=foo --find=variable %t | \ +// RUN: FileCheck --check-prefix=NAME %s +// RUN: lldb-test symbols --regex --name=foo --find=variable %t | \ +// RUN: FileCheck --check-prefix=REGEX %s +// RUN: lldb-test symbols --name=not_there --find=variable %t | \ +// RUN: FileCheck --check-prefix=EMPTY %s + +// EMPTY: Found 0 variables: +// NAME: Found 4 variables: +// CONTEXT: Found 1 variables: +// REGEX: Found 5 variables: +int foo; +// NAME-DAG: name = "foo", type = {{.*}} (int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-1]] +// REGEX-DAG: name = "foo", type = {{.*}} (int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-2]] +namespace bar { +int context; +long foo; +// NAME-DAG: name = "foo", type = {{.*}} (long int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-1]] +// CONTEXT-DAG: name = "foo", type = {{.*}} (long int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-2]] +// REGEX-DAG: name = "foo", type = {{.*}} (long int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-3]] +namespace baz { +static short foo; +// NAME-DAG: name = "foo", type = {{.*}} (short), {{.*}} decl = find-basic-variable.cpp:[[@LINE-1]] +// REGEX-DAG: name = "foo", type = {{.*}} (short), {{.*}} decl = find-basic-variable.cpp:[[@LINE-2]] +} +} + +struct sbar { + static int foo; +// NAME-DAG: name = "foo", type = {{.*}} (int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-1]] +// REGEX-DAG: name = "foo", type = {{.*}} (int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-2]] +}; +int sbar::foo; + +int foobar; +// REGEX-DAG: name = "foobar", type = {{.*}} (int), {{.*}} decl = find-basic-variable.cpp:[[@LINE-1]] + +int fbar() { + static int foo; + return foo + bar::baz::foo; +} + +int Foo; + +struct ssbar { + int foo; +}; + +extern "C" void _start(sbar, ssbar) {} diff --git a/lldb/lit/SymbolFile/DWARF/find-type-in-function.cpp b/lldb/lit/SymbolFile/DWARF/find-type-in-function.cpp new file mode 100644 index 00000000000..a0894284fa2 --- /dev/null +++ b/lldb/lit/SymbolFile/DWARF/find-type-in-function.cpp @@ -0,0 +1,24 @@ +// REQUIRES: lld + +// XFAIL: * + +// RUN: clang %s -g -c -o %t.o --target=x86_64-pc-linux +// RUN: ld.lld %t.o -o %t +// RUN: lldb-test symbols --name=foo --find=type %t | \ +// RUN: FileCheck --check-prefix=NAME %s + +// Lookup for "foo" should find either both "struct foo" types or just the +// global one. Right now, it finds the definition inside bar(), which is +// definitely wrong. + +// NAME: Found 2 types: +struct foo {}; +// NAME-DAG: name = "foo", {{.*}} decl = find-type-in-function.cpp:[[@LINE-1]] + +void bar() { + struct foo {}; +// NAME-DAG: name = "foo", {{.*}} decl = find-type-in-function.cpp:[[@LINE-1]] + foo a; +} + +extern "C" void _start(foo) {} diff --git a/lldb/lit/SymbolFile/DWARF/lit.local.cfg b/lldb/lit/SymbolFile/DWARF/lit.local.cfg new file mode 100644 index 00000000000..159c376beed --- /dev/null +++ b/lldb/lit/SymbolFile/DWARF/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = ['.cpp'] |

