Make '{add-,}symbol-file' not care about the position of command line arguments
[external/binutils.git] / gdb / testsuite / gdb.base / relocate.exp
index 6eef15f..d0a839a 100644 (file)
@@ -37,6 +37,92 @@ foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
        "add-symbol-file: unknown option $word"
 }
 
+# Check that we can pass parameters using any position in the command
+# line.
+set test "add-symbol-file positionless -readnow"
+gdb_test_multiple "add-symbol-file -readnow $binfile 0x100 -s .bss 0x3" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
+# When we use -s as the first argument, the section will be printed
+# first as well.
+set test "add-symbol-file positionless -s"
+gdb_test_multiple "add-symbol-file -s .bss 0x3 -readnow $binfile 0x100" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
+set test "add-symbol-file positionless -s, no -readnow"
+gdb_test_multiple "add-symbol-file $binfile 0x100 -s .bss 0x3" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
+# Check that passing "-s .text", no matter the position, always has
+# the same result.
+set test "add-symbol-file different -s .text, after file"
+gdb_test_multiple "add-symbol-file $binfile 0x100 -s .text 0x200" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
+set test "add-symbol-file different -s .text, before file"
+gdb_test_multiple "add-symbol-file -s .text 0x200 $binfile 0x100" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
+# Test that passing "--" disables option processing.
+gdb_test "add-symbol-file -- $binfile 0x100 -s .bss 0x3" \
+    "Unrecognized argument \"-s\"" \
+    "add-symbol-file with -- disables option processing"
+set test "add-symbol-file with -- disables option processing, non-existent filename"
+gdb_test_multiple "add-symbol-file -- -non-existent-file 0x100" $test {
+    -re "add symbol table from file \"-non-existent-file\" at\r\n\t\.text_addr = 0x100\r\n\\(y or n\\) " {
+       gdb_test "y" "-non-existent-file: No such file or directory\." $test
+    }
+}
+# Test that passing the wrong number of arguments to '-s' leads to an
+# error.
+gdb_test "add-symbol-file $binfile -s" \
+    "Missing section name after \"-s\"" \
+    "add-symbol-file with -s without section name"
+gdb_test "add-symbol-file $binfile -s .bss" \
+    "Missing section address after \"-s\"" \
+    "add-symbol-file with -s without section address"
+# Test that '-s' accepts section names with '-'
+set test "add-symbol-file with -s using section name starting with dash"
+gdb_test_multiple "add-symbol-file -s -section-name 0x200 $binfile 0x100" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\-section-name_addr = 0x200\r\n\\(y or n\\) " {
+       gdb_test "n" "Not confirmed\." $test
+    }
+}
+# Since we're here, might as well test the 'symbol-file' command and
+# if its arguments can also be passed at any position.
+gdb_test "symbol-file -readnow $binfile" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow first"
+clean_restart
+gdb_test "symbol-file $binfile -readnow" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow second"
+gdb_test "symbol-file -readnow" \
+    "no symbol file name was specified" \
+    "symbol-file without filename"
+gdb_test "symbol-file -- -non-existent-file" \
+    "-non-existent-file: No such file or directory\." \
+    "symbol-file with -- disables option processing"
+clean_restart
+gdb_test "symbol-file -readnow -- $binfile" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -- and -readnow"
+gdb_test "symbol-file -- $binfile -readnow" \
+    "Unrecognized argument \"-readnow\"" \
+    "symbol-file with -- and -readnow, invalid option"
+
+clean_restart
+
 gdb_test "add-symbol-file ${binfile} 0 -s" \
     "Missing section name after .-s." \
     "add-symbol-file bare -s"