diff options
author | Christian Biesinger <cbiesinger@google.com> | 2019-07-30 11:04:37 -0500 |
---|---|---|
committer | Christian Biesinger <cbiesinger@google.com> | 2019-07-30 11:04:37 -0500 |
commit | 2906593ffecef89f8d64e0f1ca21494be71d0ebd (patch) | |
tree | 8749c60aa8e9da72303e4be797345492dc3018a7 /gdb/testsuite/gdb.python | |
parent | 5c4dde850c0d4874d3bbe6dd1989bf0f7a5ed1c3 (diff) | |
download | gdb-2906593ffecef89f8d64e0f1ca21494be71d0ebd.zip gdb-2906593ffecef89f8d64e0f1ca21494be71d0ebd.tar.gz gdb-2906593ffecef89f8d64e0f1ca21494be71d0ebd.tar.bz2 |
[PR/24474] Add gdb.lookup_static_symbol to the python API
Similar to lookup_global_symbol, except that it checks the
STATIC_SCOPE.
gdb/ChangeLog:
2019-07-30 Christian Biesinger <cbiesinger@google.com>
PR/24474: Add a function to lookup static variables.
* NEWS: Mention this new function.
* python/py-symbol.c (gdbpy_lookup_static_symbol): New function.
* python/python-internal.h (gdbpy_lookup_static_symbol): New function.
* python/python.c (python_GdbMethods): Add new function.
gdb/doc/ChangeLog:
2019-07-30 Christian Biesinger <cbiesinger@google.com>
* python.texi (Symbols In Python): Document new function
gdb.lookup_static_symbol.
gdb/testsuite/ChangeLog:
2019-07-30 Christian Biesinger <cbiesinger@google.com>
* gdb.python/py-symbol.c: Add a static variable and one in an anonymous
namespace.
* gdb.python/py-symbol.exp: Test gdb.lookup_static_symbol.
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/py-symbol.c | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-symbol.exp | 24 |
2 files changed, 29 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c index f77c8c8..06a931b 100644 --- a/gdb/testsuite/gdb.python/py-symbol.c +++ b/gdb/testsuite/gdb.python/py-symbol.c @@ -32,9 +32,14 @@ class SimpleClass return i; /* Break in class. */ } }; + +namespace { + int anon = 10; +}; #endif int qq = 72; /* line of qq */ +static int rr = 42; /* line of rr */ int func (int arg) { diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp index 5b8a2be..5617f12 100644 --- a/gdb/testsuite/gdb.python/py-symbol.exp +++ b/gdb/testsuite/gdb.python/py-symbol.exp @@ -48,6 +48,25 @@ gdb_test "python print (gdb.lookup_global_symbol('qq').needs_frame)" \ "False" \ "print whether qq needs a frame" +set rr_line [gdb_get_line_number "line of rr"] +gdb_test "python print (gdb.lookup_global_symbol ('rr') is None)" "True" \ + "lookup_global_symbol for static var" + +gdb_test "python print (gdb.lookup_static_symbol ('rr').line)" "$rr_line" \ + "print line number of rr" + +gdb_test "python print (gdb.lookup_static_symbol ('rr').value ())" "42" \ + "print value of rr" + +gdb_test "python print (gdb.lookup_static_symbol ('rr').needs_frame)" \ + "False" \ + "print whether rr needs a frame" + +gdb_test "python print (gdb.lookup_static_symbol ('nonexistent') is None)" \ + "True" "lookup_static_symbol for nonexistent var" + +gdb_test "python print (gdb.lookup_static_symbol ('qq') is None)" \ + "True" "lookup_static_symbol for global var" if ![runto_main] then { fail "can't run to main" @@ -137,6 +156,11 @@ gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load ${binfile}-cxx +gdb_test "python print (gdb.lookup_global_symbol ('(anonymous namespace)::anon') is None)" \ + "True" "anon is None" +gdb_test "python print (gdb.lookup_static_symbol ('(anonymous namespace)::anon').value ())" \ + "10" "print value of anon" + if ![runto_main] then { fail "can't run to main" return 0 |