aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/relocate.exp
diff options
context:
space:
mode:
authorPetr Tesarik <ptesarik@suse.cz>2018-06-28 08:33:17 +0200
committerPetr Tesarik <ptesarik@suse.cz>2018-06-28 08:35:34 +0200
commit291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f (patch)
tree4318a3a5a93f7f82ada7a658b214783a334098fe /gdb/testsuite/gdb.base/relocate.exp
parentd81a3eaff36b41ed67758a119a6864b50f60a60d (diff)
downloadgdb-291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f.zip
gdb-291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f.tar.gz
gdb-291f9a9643f87fa4eb6a7c280eaa3877c11e3a1f.tar.bz2
Add an optional offset option to the "add-symbol-file" command
If all sections of a symbol file are loaded with a fixed offset, it is easier to specify that offset than listing all sections explicitly. There is also a similar option for "symbol-file". gdb/ChangeLog: 2018-06-28 Petr Tesarik <ptesarik@suse.cz> * symfile.c (add_symbol_file_command, _initialize_symfile): Add option "-o" to add-symbol-file-load to add an offset to each section's load address. * symfile.c (set_objfile_default_section_offset): New function. gdb/doc/ChangeLog: 2018-06-28 Petr Tesarik <ptesarik@suse.cz> * gdb.texinfo (Files): Document "add-symbol-file -o offset". gdb/testsuite/ChangeLog: 2018-06-28 Petr Tesarik <ptesarik@suse.cz> * gdb.base/relocate.exp: Add test for "add-symbol-file -o ".
Diffstat (limited to 'gdb/testsuite/gdb.base/relocate.exp')
-rw-r--r--gdb/testsuite/gdb.base/relocate.exp56
1 files changed, 56 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/relocate.exp b/gdb/testsuite/gdb.base/relocate.exp
index 2b4c4a7..b6f18d9 100644
--- a/gdb/testsuite/gdb.base/relocate.exp
+++ b/gdb/testsuite/gdb.base/relocate.exp
@@ -235,6 +235,62 @@ set new_function_foo_addr [get_var_address function_foo]
gdb_assert {${new_function_foo_addr} == ${function_foo_addr} + $offset} \
"function foo is moved by offset"
+# Load the object using add-symbol-file with an offset and check that
+# all addresses are moved by that offset.
+
+set offset 0x10000
+clean_restart
+gdb_test "add-symbol-file -o $offset $binfile" \
+ "Reading symbols from ${binfile}\.\.\.done\." \
+ "add-symbol-file with offset" \
+ "add symbol table from file \".*${testfile}\\.o\" with all sections offset by $offset\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+# Make sure the address of a static variable is moved by offset.
+set new_static_foo_addr [get_var_address static_foo]
+gdb_assert { ${new_static_foo_addr} == ${static_foo_addr} + $offset } \
+ "static variable foo is moved by offset"
+
+# Make sure the address of a global variable is moved by offset.
+set new_global_foo_addr [get_var_address global_foo]
+gdb_assert { ${new_global_foo_addr} == ${global_foo_addr} + $offset } \
+ "global variable foo is moved by offset"
+
+# Make sure the address of a function is moved by offset.
+set new_function_foo_addr [get_var_address function_foo]
+gdb_assert { ${new_function_foo_addr} == ${function_foo_addr} + $offset } \
+ "function foo is moved by offset"
+
+# Re-load the object giving an explicit address for .text
+
+set text [ format "0x%x" [expr ${function_foo_addr} + 0x20000] ]
+clean_restart
+gdb_test "add-symbol-file $binfile -o $offset $text" \
+ "Reading symbols from ${binfile}\.\.\.done\." \
+ "add-symbol-file with offset, text address given" \
+ "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = ${text}\[\r\n\]+with other sections offset by ${offset}\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+# Make sure function has a different addresses now.
+set function_foo_addr [get_var_address function_foo]
+gdb_assert { ${function_foo_addr} != ${new_function_foo_addr} } \
+ "function foo has a different address"
+
+# Re-load the object giving an explicit address for .data
+
+set data [ format "0x%x" [expr ${global_foo_addr} + 0x20000] ]
+clean_restart
+gdb_test "add-symbol-file $binfile -o $offset -s .data $data" \
+ "Reading symbols from ${binfile}\.\.\.done\." \
+ "add-symbol-file with offset, data address given" \
+ "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.data_addr = ${data}\[\r\n\]+with other sections offset by ${offset}\[\r\n\]+\\(y or n\\) " \
+ "y"
+
+# Make sure variable has a different addresses now.
+set global_foo_addr [get_var_address global_foo]
+gdb_assert { ${global_foo_addr} != ${new_global_foo_addr} } \
+ "global variable foo has a different address"
+
# Now try loading the object as an exec-file; we should be able to print
# the values of variables after we do this.