aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-10-15 16:18:26 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-11-10 21:35:32 +0000
commit086baaf1346f07acfb6708e8c6cb79274241488b (patch)
tree0dff00a4c5da670a23ed348dd13c5475bd342289 /gdb/testsuite
parent09ff83af3c8558594bd31bfaf4ed7daadf4f707d (diff)
downloadgdb-086baaf1346f07acfb6708e8c6cb79274241488b.zip
gdb-086baaf1346f07acfb6708e8c6cb79274241488b.tar.gz
gdb-086baaf1346f07acfb6708e8c6cb79274241488b.tar.bz2
gdb/python: Introduce gdb.lookup_static_symbols
If gdb.lookup_static_symbol is going to return a single symbol then it makes sense (I think) for it to return a context sensitive choice of symbol, that is the global static symbol that would be visible to the program at that point. However, if the user of the python API wants to instead get a consistent set of global static symbols, no matter where they stop, then they have to instead consider all global static symbols with a given name - there could be many. That is what this new API function offers, it returns a list (possibly empty) of all global static symbols matching a given name (and optionally a given symbol domain). gdb/ChangeLog: * python/py-symbol.c (gdbpy_lookup_static_symbols): New function. * python/python-internal.h (gdbpy_lookup_static_symbols): Declare new function. * python/python.c (python_GdbMethods): Add gdb.lookup_static_symbols method. * NEWS: Mention gdb.lookup_static_symbols. gdb/testsuite/ChangeLog: * gdb.python/py-symbol.exp: Add test for gdb.lookup_static_symbols. gdb/doc/ChangeLog: * python.texi (Symbols In Python): Add documentation for gdb.lookup_static_symbols. Change-Id: I1153b0ae5bcbc43b3dcf139043c7a48bf791e1a3
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.python/py-symbol.exp17
2 files changed, 22 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index e170b7e..9c69443 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2019-11-10 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb.python/py-symbol.exp: Add test for
+ gdb.lookup_static_symbols.
+
+2019-11-10 Andrew Burgess <andrew.burgess@embecosm.com>
+
* gdb.python/py-symbol.c: Declare and call function from new
py-symbol-2.c file.
* gdb.python/py-symbol.exp: Compile both source files, and add new
diff --git a/gdb/testsuite/gdb.python/py-symbol.exp b/gdb/testsuite/gdb.python/py-symbol.exp
index 6196007..ea41297 100644
--- a/gdb/testsuite/gdb.python/py-symbol.exp
+++ b/gdb/testsuite/gdb.python/py-symbol.exp
@@ -29,6 +29,15 @@ if {[prepare_for_testing "failed to prepare" $testfile \
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
+# Check that we find all static symbols before the inferior has
+# started, at which point some of the symtabs might not have been
+# expanded.
+gdb_test "python print (len (gdb.lookup_static_symbols ('rr')))" \
+ "2" "print (len (gdb.lookup_static_symbols ('rr')))"
+
+# Restart so we don't have expanded symtabs after the previous test.
+clean_restart ${binfile}
+
# Test looking up a global symbol before we runto_main as this is the
# point where we don't have a current frame, and we don't want to
# require one.
@@ -108,6 +117,10 @@ gdb_breakpoint "function_in_other_file"
gdb_continue_to_breakpoint "function_in_other_file"
gdb_test "python print (gdb.lookup_static_symbol ('rr').value ())" "99" \
"print value of rr from other file"
+gdb_test "python print (gdb.lookup_static_symbols ('rr')\[0\].value ())" "99" \
+ "print value of gdb.lookup_static_symbols ('rr')\[0\], from the other file"
+gdb_test "python print (gdb.lookup_static_symbols ('rr')\[1\].value ())" "42" \
+ "print value of gdb.lookup_static_symbols ('rr')\[1\], from the other file"
# Now continue back to the first source file.
set linenum [gdb_get_line_number "Break at end."]
@@ -119,6 +132,10 @@ gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
# static symbol from the second source file.
gdb_test "python print (gdb.lookup_static_symbol ('rr').value ())" "42" \
"print value of rr from main file"
+gdb_test "python print (gdb.lookup_static_symbols ('rr')\[0\].value ())" "99" \
+ "print value of gdb.lookup_static_symbols ('rr')\[0\], from the main file"
+gdb_test "python print (gdb.lookup_static_symbols ('rr')\[1\].value ())" "42" \
+ "print value of gdb.lookup_static_symbols ('rr')\[1\], from the main file"
# Test is_variable attribute.
gdb_py_test_silent_cmd "python a = gdb.lookup_symbol(\'a\')" "Get variable a" 0