aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorDoug Evans <dje@google.com>2014-12-12 09:48:13 -0800
committerDoug Evans <dje@google.com>2014-12-12 09:48:13 -0800
commit6dddd6a5747532ef6e9703432c51680011df4e8d (patch)
tree35083e8dddfb1148d20dc1dc6808c05df7b8bb8a /gdb/testsuite
parentf161c17134bdfa5f5e72d7afb7dfccf5599a67e1 (diff)
downloadgdb-6dddd6a5747532ef6e9703432c51680011df4e8d.zip
gdb-6dddd6a5747532ef6e9703432c51680011df4e8d.tar.gz
gdb-6dddd6a5747532ef6e9703432c51680011df4e8d.tar.bz2
New python function gdb.lookup_objfile.
gdb/ChangeLog: * NEWS: Mention gdb.lookup_objfile. * python/python.c (GdbMethods): Add lookup_objfile. * python/python-internal.h (gdbpy_lookup_objfile): Declare. * python/py-objfile.c: #include "symtab.h". (objfpy_build_id_ok, objfpy_build_id_matches): New functions. (objfpy_lookup_objfile_by_name): New function. (objfpy_lookup_objfile_by_build_id): New function. (gdbpy_lookup_objfile): New function. gdb/doc/ChangeLog: * python.texi (Objfiles In Python): Document gdb.lookup_objfile. gdb/testsuite/ChangeLog: * lib/gdb-python.exp (get_python_valueof): New function. * gdb.python/py-objfile.exp: Add tests for gdb.lookup_objfile.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.python/py-objfile.exp24
-rw-r--r--gdb/testsuite/lib/gdb-python.exp21
3 files changed, 49 insertions, 1 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index b21ac45..22f3ffc 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-12 Doug Evans <dje@google.com>
+
+ * lib/gdb-python.exp (get_python_valueof): New function.
+ * gdb.python/py-objfile.exp: Add tests for gdb.lookup_objfile.
+
2014-12-12 Andreas Arnez <arnez@linux.vnet.ibm.com>
* gdb.base/completion.exp: Add test for completion of "info
diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp
index f3a8a6c..5d3c084 100644
--- a/gdb/testsuite/gdb.python/py-objfile.exp
+++ b/gdb/testsuite/gdb.python/py-objfile.exp
@@ -32,23 +32,39 @@ if ![runto_main] then {
return 0
}
+set python_error_text "Error while executing Python code\\."
+
gdb_py_test_silent_cmd "python sym = gdb.lookup_symbol(\"some_var\")" \
"Find a symbol in objfile" 1
gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
"Get backing object file" 1
-gdb_test "python print (objfile.filename)" ".*py-objfile.*" \
+gdb_test "python print (objfile.filename)" "${testfile}" \
"Get objfile file name"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \
+ "${testfile}"
+gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \
+ "Objfile not found\\.\r\n${python_error_text}"
+
set binfile_build_id [get_build_id $binfile]
if [string compare $binfile_build_id ""] {
verbose -log "binfile_build_id = $binfile_build_id"
gdb_test "python print (objfile.build_id)" "$binfile_build_id" \
"Get objfile build id"
+ gdb_test "python print (gdb.lookup_objfile (\"$binfile_build_id\", by_build_id=True).filename)" \
+ "${testfile}"
} else {
unsupported "build-id is not supported by the compiler"
}
+# Other lookup_objfile_by_build_id tests we can do, even if compiler doesn't
+# support them.
+gdb_test "python print (gdb.lookup_objfile (\"foo\", by_build_id=True))" \
+ "Not a valid build id\\.\r\n${python_error_text}"
+gdb_test "python print (gdb.lookup_objfile (\"1234abcdef\", by_build_id=True))" \
+ "Objfile not found\\.\r\n${python_error_text}"
+
gdb_test "python print (objfile.progspace)" "<gdb\.Progspace object at .*>" \
"Get objfile program space"
gdb_test "python print (objfile.is_valid())" "True" \
@@ -93,3 +109,9 @@ gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \
gdb_test "p main" "= {int \\(\\)} $hex <main>" \
"print main with debug info"
+
+# Separate debug files are not findable.
+if { [get_python_valueof "sep_objfile.build_id" "None"] != "None" } {
+ gdb_test "python print (gdb.lookup_objfile (sep_objfile.build_id, by_build_id=True))" \
+ "Objfile not found\\.\r\n${python_error_text}"
+}
diff --git a/gdb/testsuite/lib/gdb-python.exp b/gdb/testsuite/lib/gdb-python.exp
index d5e7928..eefff73 100644
--- a/gdb/testsuite/lib/gdb-python.exp
+++ b/gdb/testsuite/lib/gdb-python.exp
@@ -45,3 +45,24 @@ proc gdb_py_test_multiple { name args } {
}
return 0
}
+
+# Return the result of python expression EXPR.
+# DEFAULT is returned if there's an error.
+# This is modelled after get_integer_valueof.
+
+proc get_python_valueof { exp default } {
+ global gdb_prompt
+
+ set test "get python valueof \"${exp}\""
+ set val ${default}
+ gdb_test_multiple "python print (\"valueof: %s\" % (${exp}))" "$test" {
+ -re "valueof: (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" {
+ set val $expect_out(1,string)
+ pass "$test ($val)"
+ }
+ timeout {
+ fail "$test (timeout)"
+ }
+ }
+ return ${val}
+}