-# Copyright (C) 2011-2018 Free Software Foundation, Inc.
+# Copyright (C) 2011-2021 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
if { [skip_python_tests] } { continue }
if ![runto_main] then {
- fail "can't run to main"
return 0
}
gdb_test "python print (objfile.username)" "${testfile}" \
"Get objfile user name"
+gdb_test "python print (objfile)" \
+ "<gdb.Objfile filename=.*${testfile}.*>"
+
gdb_test_no_output "python dir(objfile)"
gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \
gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \
"Objfile not found\\.\r\n${python_error_text}"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_global_symbol (\"global_var\").name)" \
+ "global_var" "lookup_global_symbol finds a valid symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_global_symbol (\"static_var\") is None)" \
+ "True" "lookup_global_symbol does not find static symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_global_symbol (\"stdout\"))" \
+ "None" "lookup_global_symbol doesn't find symbol in other objfile"
+
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_static_symbol (\"static_var\").name)" \
+ "static_var" "lookup_static_symbol finds a valid symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_static_symbol (\"global_var\") is None)" \
+ "True" "lookup_static_symbol does not find global symbol"
+gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").lookup_static_symbol (\"nonexistent\"))" \
+ "None" "lookup_static_symbol can handle nonexistent symbol"
+
set binfile_build_id [get_build_id $binfile]
if [string compare $binfile_build_id ""] {
verbose -log "binfile_build_id = $binfile_build_id"
}
if ![runto_main] {
- fail "can't run to main"
return 0
}
# An objfile that was a symlink to a differently named file is still
# findable with its original name.
-set symlink_binary [standard_output_file "symlink-binary"]
-remote_exec host "rm -f ${symlink_binary}"
-remote_exec host "ln -sf ${testfile} ${symlink_binary}"
-if [remote_file host exists "${symlink_binary}"] {
- clean_restart "${symlink_binary}"
- gdb_test "python print (gdb.lookup_objfile (\"${symlink_binary}\").filename)" \
- "${testfile}" "gdb.lookup_objfile of symlinked binary"
+# On Windows we don't have proper symlinks, so skip this.
+if ![ishost *-*-mingw*] {
+ set symlink_binary [standard_output_file "symlink-binary"]
+ remote_exec host "rm -f ${symlink_binary}"
+ remote_exec host "ln -sf ${testfile} ${symlink_binary}"
+ if [remote_file host exists "${symlink_binary}"] {
+ clean_restart "${symlink_binary}"
+ gdb_test "python print (gdb.lookup_objfile (\"${symlink_binary}\").filename)" \
+ "${testfile}" "gdb.lookup_objfile of symlinked binary"
+ }
}
+
+# Test printing an Objfile object that is no longer valid.
+gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \
+ "get first objfile" 1
+gdb_file_cmd ${binfile}
+gdb_test "python print(objfile)" "<gdb.Objfile \\\(invalid\\\)>"