[gdb/testsuite] Reduce errors after gdb exit in default_gdb_start
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / code_elim.exp
index cc625e01edae42df7e9f065e5e08da692ba4bdfa..3d49c558ff1a5f90997c7d7ad554034f877d6d1e 100644 (file)
@@ -1,5 +1,4 @@
-# Copyright 2002, 2003, 2005, 2007, 2008, 2009, 2010
-# Free Software Foundation, Inc.
+# Copyright 2002-2020 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
 # code_elim.exp -- tests that GDB can handle executables where some data/code
 #                  has been eliminated by the linker.
 
-if $tracelevel then {
-    strace $tracelevel
-}
-
 set testfile1 code_elim1
 set testfile2 code_elim2
 set srcfile1 ${testfile1}.c
 set srcfile2 ${testfile2}.c
-set binfile1 ${objdir}/${subdir}/${testfile1}
-set binfile2 ${objdir}/${subdir}/${testfile2}
+set binfile1 [standard_output_file ${testfile1}]
+set binfile2 [standard_output_file ${testfile2}]
 set opts [list debug]
 lappend opts "additional_flags=-ffunction-sections"
 lappend opts "additional_flags=-fdata-sections"
 lappend opts "additional_flags=-Wl,-gc-sections"
 lappend opts "additional_flags=-Wl,-e,main"
 
+# Place variables in .data instead of .sdata.
+if {[istarget "riscv*-*-*"]} {
+   lappend opts "additional_flags=-msmall-data-limit=0"
+}
+
 remote_exec build "rm -f ${binfile1}"
 remote_exec build "rm -f ${binfile2}"
 
 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable $opts] != "" } {
-     untested code_elim.exp
+     untested "failed to compile"
      return -1
 }
 
 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $opts] != "" } {
-     untested code_elim.exp
+     untested "failed to compile"
      return -1
 }
 
-proc get_var_address { var } {
-    global gdb_prompt hex
-
-    # Match output like:
-    # $1 = (int *) 0x0
-    # $5 = (int (*)()) 0
-    # $6 = (int (*)()) 0x24 <function_bar>
-
-    gdb_test_multiple "print &${var}" "get address of ${var}" {
-       -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
-           pass "get address of ${var}"
-           if { $expect_out(1,string) == "0" } {
-               return "0x0"
-           } else {
-               return $expect_out(1,string)
-           }
-       }
-    }
-    return ""
-}
-
 proc not_null_var_address { var } {
 
     # Same as get_var_address, expect that it reports a failure if a null
@@ -100,16 +79,16 @@ proc test_eliminated_var { var } {
 gdb_exit
 gdb_start
 
-gdb_test "add-symbol-file ${binfile1} 0x100000" \
-       "Reading symbols from .*${testfile1}\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
-       "add-symbol-file ${testfile1} 0x100000" \
-       "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
-       "y"
+gdb_test "symbol-file ${binfile1}" \
+       "Reading symbols from .*${testfile1}\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
+       "symbol-file ${testfile1}"
 
-test_eliminated_var my_global_symbol
-test_eliminated_var my_static_symbol
-test_eliminated_var my_global_func
-not_null_var_address main
+with_test_prefix "single psymtabs" {
+    test_eliminated_var my_global_symbol
+    test_eliminated_var my_static_symbol
+    test_eliminated_var my_global_func
+    not_null_var_address main
+}
 
 # Same thing for symtabs
 
@@ -120,10 +99,12 @@ set GDBFLAGS "$GDBFLAGS --readnow $binfile1"
 gdb_start
 set GDBFLAGS $saved_gdbflags
 
-test_eliminated_var my_global_symbol
-test_eliminated_var my_static_symbol
-test_eliminated_var my_global_func
-not_null_var_address main
+with_test_prefix "single symtabs" {
+    test_eliminated_var my_global_symbol
+    test_eliminated_var my_static_symbol
+    test_eliminated_var my_global_func
+    not_null_var_address main
+}
 
 # binfile2 contains the symbols that have been eliminated in binfile1. Check
 # the eliminated symbols does not hide these valid ones.
@@ -131,43 +112,45 @@ not_null_var_address main
 gdb_exit
 gdb_start
 
-gdb_test "add-symbol-file ${binfile1} 0x100000" \
-       "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
-       "add-symbol-file ${testfile1} 0x100000" \
-       "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
-       "y"
-
-gdb_test "add-symbol-file ${binfile2} 0x200000" \
-       "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
-       "add-symbol-file ${testfile2} 0x200000" \
-       "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
-       "y"
-
-not_null_var_address my_global_symbol
-not_null_var_address my_static_symbol
-not_null_var_address my_global_func
-not_null_var_address main
+with_test_prefix "order1" {
+    gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \
+           "Reading symbols from .*${testfile1}\\.\\.\\." \
+           "add-symbol-file ${testfile1} 0x100000" \
+           "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \
+           "y"
+
+    gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \
+           "Reading symbols from .*${testfile2}\\.\\.\\." \
+           "add-symbol-file ${testfile2} 0x200000" \
+           "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \
+           "y"
+
+    not_null_var_address my_global_symbol
+    not_null_var_address my_static_symbol
+    not_null_var_address my_global_func
+    not_null_var_address main
+}
 
 # Same thing, but loading binfile2 before binfile1.
 
 gdb_exit
 gdb_start
 
-gdb_test "add-symbol-file ${binfile2} 0x200000" \
-       "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
-       "add-symbol-file ${testfile2} 0x200000" \
-       "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
-       "y"
-
-gdb_test "add-symbol-file ${binfile1} 0x100000" \
-       "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
-       "add-symbol-file ${testfile1} 0x100000" \
-       "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
-       "y"
-
-not_null_var_address my_global_symbol
-not_null_var_address my_static_symbol
-not_null_var_address my_global_func
-not_null_var_address main
-
-
+with_test_prefix "order2" {
+    gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \
+           "Reading symbols from .*${testfile2}\\.\\.\\." \
+           "add-symbol-file ${testfile2} 0x200000" \
+           "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \
+           "y"
+
+    gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \
+           "Reading symbols from .*${testfile1}\\.\\.\\." \
+           "add-symbol-file ${testfile1} 0x100000" \
+           "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \
+           "y"
+
+    not_null_var_address my_global_symbol
+    not_null_var_address my_static_symbol
+    not_null_var_address my_global_func
+    not_null_var_address main
+}
This page took 0.042806 seconds and 4 git commands to generate.