]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix testcases with required but unreferenced functions and variables
authorGary Benson <gbenson@redhat.com>
Mon, 12 Oct 2020 09:35:23 +0000 (10:35 +0100)
committerGary Benson <gbenson@redhat.com>
Mon, 12 Oct 2020 09:35:23 +0000 (10:35 +0100)
A number of testcases define variables and/or functions which are
referenced by GDB during the test, but which are not referenced from
within the test executable.  Clang correctly recognizes that these
variables and functions are unused, and optimizes them out, causing
the testcases in question to fail.  This commit adds __attribute__
((used)) in various places to prevent this.

gdb/testsuite/ChangeLog:

* gdb.base/msym-bp.c (foo): Add __attribute__ ((used)).
* gdb.base/msym-bp-2.c (foo): Likewise.
* gdb.base/msym-lang.c (foo): Likewise.
* gdb.base/msym-lang-main.c (foo): Likewise.
* gdb.base/symtab-search-order-1.c (static_global): Likewise.
* gdb.guile/scm-pretty-print.c (eval_func): Likewise.
* gdb.mi/mi-sym-info-1.c (global_f1): Likewise.
* gdb.mi/mi-sym-info-2.c (global_f1, var1, var2): Likewise.
* gdb.multi/watchpoint-multi-exit.c (globalvar): Likewise.
* gdb.python/py-as-string.c (enum_valid, enum_invalid): Likewise.
* gdb.python/py-objfile.c (static_var): Likewise.
* gdb.python/py-symbol.c (rr): Likewise.
* gdb.python/py-symbol-2.c (anon, rr): Likewise.
* gdb.mi/mi-sym-info.exp (lineno1, lineno2): Updated.

15 files changed:
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/msym-bp-2.c
gdb/testsuite/gdb.base/msym-bp.c
gdb/testsuite/gdb.base/msym-lang-main.c
gdb/testsuite/gdb.base/msym-lang.c
gdb/testsuite/gdb.base/symtab-search-order-1.c
gdb/testsuite/gdb.guile/scm-pretty-print.c
gdb/testsuite/gdb.mi/mi-sym-info-1.c
gdb/testsuite/gdb.mi/mi-sym-info-2.c
gdb/testsuite/gdb.mi/mi-sym-info.exp
gdb/testsuite/gdb.multi/watchpoint-multi-exit.c
gdb/testsuite/gdb.python/py-as-string.c
gdb/testsuite/gdb.python/py-objfile.c
gdb/testsuite/gdb.python/py-symbol-2.c
gdb/testsuite/gdb.python/py-symbol.c

index 2e8efd9374683eb45a0bda328aae8b68fca47490..aefdcba937c29b2244228991e8db3b7734c63ffd 100644 (file)
@@ -1,3 +1,20 @@
+2020-10-12  Gary Benson <gbenson@redhat.com>
+
+       * gdb.base/msym-bp.c (foo): Add __attribute__ ((used)).
+       * gdb.base/msym-bp-2.c (foo): Likewise.
+       * gdb.base/msym-lang.c (foo): Likewise.
+       * gdb.base/msym-lang-main.c (foo): Likewise.
+       * gdb.base/symtab-search-order-1.c (static_global): Likewise.
+       * gdb.guile/scm-pretty-print.c (eval_func): Likewise.
+       * gdb.mi/mi-sym-info-1.c (global_f1): Likewise.
+       * gdb.mi/mi-sym-info-2.c (global_f1, var1, var2): Likewise.
+       * gdb.multi/watchpoint-multi-exit.c (globalvar): Likewise.
+       * gdb.python/py-as-string.c (enum_valid, enum_invalid): Likewise.
+       * gdb.python/py-objfile.c (static_var): Likewise.
+       * gdb.python/py-symbol.c (rr): Likewise.
+       * gdb.python/py-symbol-2.c (anon, rr): Likewise.
+       * gdb.mi/mi-sym-info.exp (lineno1, lineno2): Updated.
+
 2020-10-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.fortran/mixed-lang-stack.exp (run_tests): Update expected
index b5a399ee49239beb38c9bf1ca17a7fe7848c0abc..7cdf43cccf960f944e4d20ce90b5ab8a4fcebc80 100644 (file)
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-void
+void __attribute__ ((used))
 foo (void)
 {
 }
index 2257d3f7e9b6c55d5cd27f869f977eb58759eb72..80ffef02002def841558adc39a1f6ee9b2c490b6 100644 (file)
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-static void
+static void __attribute__ ((used))
 foo (void)
 {
 }
index 180ba9d55eabe334fac37fb18b09cf2bef4abc7f..192047d52704753953cf55c4eae31a2ca524fbb4 100644 (file)
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-static int
+static int __attribute__ ((used))
 foo (void)
 {
   return 2;
index 5820e0dcf9243bfb54d240814e959c590fb9a128..38e969d5e79898466a5210e5354a2be5f121013b 100644 (file)
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-static int
+static int __attribute__ ((used))
 foo (void)
 {
   return 1;
index 09e100621c07a978220e8c6b91fe65e66bf168d7..a71d5f76612694af3aea2479aef5b930fa1a55b2 100644 (file)
@@ -15,4 +15,4 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-static int static_global = 23;
+static int __attribute__ ((used)) static_global = 23;
index 7072f2686bd71427afe5d189daa6beea2b9fdeec..7b453ff20b35ab5acb8b674a8f2c0d6669fd313e 100644 (file)
@@ -230,7 +230,7 @@ struct nullstr
 struct string_repr string_1 = { { "one" } };
 struct string_repr string_2 = { { "two" } };
 
-static int
+static int __attribute__ ((used))
 eval_func (int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8)
 {
   return p1;
index c96a6bef2f3ebf32edd7848e971191c11faa2b7e..33d355bc1d644ec8b1bad243d0225337f382686d 100644 (file)
@@ -22,7 +22,7 @@ extern int global_i2;
 extern float global_f2;
 
 static int global_i1;
-static float global_f1;
+static float __attribute__ ((used)) global_f1;
 
 typedef int my_int_t;
 
index f514e426d5e28580778ffaf870c74c3032f7ffff..8b17029de36bcfe4b6537fe586ca2f653bfac8ab 100644 (file)
@@ -16,7 +16,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 static int global_i1;
-static float global_f1;
+static float __attribute__ ((used)) global_f1;
 int global_i2;
 int global_f2;
 
@@ -44,5 +44,5 @@ f3 (another_int_t arg)
 typedef char another_char_t;
 typedef short another_short_t;
 
-static another_char_t var1;
-static another_short_t var2;
+static another_char_t __attribute__ ((used)) var1;
+static another_short_t __attribute__ ((used)) var2;
index 859dabd040ed65438df9c744afdb55bce663d1b7..152a186e02c9ee5d6b59cb9d4b58faf14e119dc8 100644 (file)
@@ -236,8 +236,8 @@ mi_gdb_test "118-symbol-info-variables --name global_f2" \
     "118\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"21\",name=\"global_f2\",type=\"int\",description=\"int global_f2;\"\}\\\]\}\\\]\}" \
     "List all variables matching pattern global_f2"
 
-set lineno1 [gdb_get_line_number "static float global_f1;" ${srcfile}]
-set lineno2 [gdb_get_line_number "static float global_f1;" ${srcfile2}]
+set lineno1 [gdb_get_line_number "static float __attribute__ ((used)) global_f1;" ${srcfile}]
+set lineno2 [gdb_get_line_number "static float __attribute__ ((used)) global_f1;" ${srcfile2}]
 mi_gdb_test "119-symbol-info-variables --type float --name ^global_" \
     "119\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]*$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"25\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}\\\]\},\{filename=\"\[^\"\]*$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"19\",name=\"global_f1\",type=\"float\",description=\"static float global_f1;\"\}\\\]\}\\\]\}" \
     "List all variables matching type float"
index 3231b70b988e66a1749004bd9a4b0a51a5a2b2b3..fb9a1f62147a46fe85b60f9e65fdde91c84f0b9c 100644 (file)
@@ -21,7 +21,7 @@
 #include <sys/wait.h>
 
 /* GDB sets watchpoint here.  */
-static volatile int globalvar;
+static volatile int __attribute__ ((used)) globalvar;
 
 /* Whether it's expected that the child exits with a signal, vs
    exiting normally.  GDB sets this.  */
index 245bcb286bd3c714095896dd843fe78f9b16173e..02563361b265a5b194d02dc6263b7ff5122dde11 100644 (file)
@@ -22,8 +22,8 @@ enum EnumType {
   ENUM_VALUE_D,
 };
 
-static enum EnumType enum_valid = ENUM_VALUE_B;
-static enum EnumType enum_invalid = (enum EnumType) 20;
+static enum EnumType __attribute__ ((used)) enum_valid = ENUM_VALUE_B;
+static enum EnumType __attribute__ ((used)) enum_invalid = (enum EnumType) 20;
 
 int
 main ()
index e8b9e831c564baecaf8210e82dfdab2eef4d9639..326d9a042174e19ac46cfa6693db6f2ce0531729 100644 (file)
@@ -16,7 +16,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 int global_var = 42;
-static int static_var = 50;
+static int __attribute__ ((used)) static_var = 50;
 
 int
 main ()
index 8bc78b9ea161cb2db414be849cf1c22d103b0ed1..fdc4efd28c8ca476f1fa7a2dc6d6ede6069c6743 100644 (file)
@@ -15,7 +15,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see  <http://www.gnu.org/licenses/>.  */
 
-static int rr = 99;            /* line of other rr */
+static int __attribute__ ((used)) rr = 99;     /* line of other rr */
 
 void
 function_in_other_file (void)
index 44f87bc15565a167629a8b97b65da665556891b7..e04f6b89fc783e44d82afb217c8dd3269ab6105d 100644 (file)
@@ -34,7 +34,7 @@ class SimpleClass
 };
 
 namespace {
-  int anon = 10;
+  int __attribute__ ((used)) anon = 10;
 };
 #endif
 
@@ -43,7 +43,7 @@ extern void function_in_other_file (void);
 #endif
 
 int qq = 72;                   /* line of qq */
-static int rr = 42;            /* line of rr */
+static int __attribute__ ((used)) rr = 42;     /* line of rr */
 
 int func (int arg)
 {