From 71e1b6b0ac9403d7fda91890f0d2881b6d1697d6 Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Mon, 12 Oct 2020 10:35:23 +0100 Subject: [PATCH] Fix testcases with required but unreferenced functions and variables 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. --- gdb/testsuite/ChangeLog | 17 +++++++++++++++++ gdb/testsuite/gdb.base/msym-bp-2.c | 2 +- gdb/testsuite/gdb.base/msym-bp.c | 2 +- gdb/testsuite/gdb.base/msym-lang-main.c | 2 +- gdb/testsuite/gdb.base/msym-lang.c | 2 +- gdb/testsuite/gdb.base/symtab-search-order-1.c | 2 +- gdb/testsuite/gdb.guile/scm-pretty-print.c | 2 +- gdb/testsuite/gdb.mi/mi-sym-info-1.c | 2 +- gdb/testsuite/gdb.mi/mi-sym-info-2.c | 6 +++--- gdb/testsuite/gdb.mi/mi-sym-info.exp | 4 ++-- gdb/testsuite/gdb.multi/watchpoint-multi-exit.c | 2 +- gdb/testsuite/gdb.python/py-as-string.c | 4 ++-- gdb/testsuite/gdb.python/py-objfile.c | 2 +- gdb/testsuite/gdb.python/py-symbol-2.c | 2 +- gdb/testsuite/gdb.python/py-symbol.c | 4 ++-- 15 files changed, 36 insertions(+), 19 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 2e8efd93746..aefdcba937c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,20 @@ +2020-10-12 Gary Benson + + * 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 * gdb.fortran/mixed-lang-stack.exp (run_tests): Update expected diff --git a/gdb/testsuite/gdb.base/msym-bp-2.c b/gdb/testsuite/gdb.base/msym-bp-2.c index b5a399ee492..7cdf43cccf9 100644 --- a/gdb/testsuite/gdb.base/msym-bp-2.c +++ b/gdb/testsuite/gdb.base/msym-bp-2.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -void +void __attribute__ ((used)) foo (void) { } diff --git a/gdb/testsuite/gdb.base/msym-bp.c b/gdb/testsuite/gdb.base/msym-bp.c index 2257d3f7e9b..80ffef02002 100644 --- a/gdb/testsuite/gdb.base/msym-bp.c +++ b/gdb/testsuite/gdb.base/msym-bp.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -static void +static void __attribute__ ((used)) foo (void) { } diff --git a/gdb/testsuite/gdb.base/msym-lang-main.c b/gdb/testsuite/gdb.base/msym-lang-main.c index 180ba9d55ea..192047d5270 100644 --- a/gdb/testsuite/gdb.base/msym-lang-main.c +++ b/gdb/testsuite/gdb.base/msym-lang-main.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -static int +static int __attribute__ ((used)) foo (void) { return 2; diff --git a/gdb/testsuite/gdb.base/msym-lang.c b/gdb/testsuite/gdb.base/msym-lang.c index 5820e0dcf92..38e969d5e79 100644 --- a/gdb/testsuite/gdb.base/msym-lang.c +++ b/gdb/testsuite/gdb.base/msym-lang.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -static int +static int __attribute__ ((used)) foo (void) { return 1; diff --git a/gdb/testsuite/gdb.base/symtab-search-order-1.c b/gdb/testsuite/gdb.base/symtab-search-order-1.c index 09e100621c0..a71d5f76612 100644 --- a/gdb/testsuite/gdb.base/symtab-search-order-1.c +++ b/gdb/testsuite/gdb.base/symtab-search-order-1.c @@ -15,4 +15,4 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -static int static_global = 23; +static int __attribute__ ((used)) static_global = 23; diff --git a/gdb/testsuite/gdb.guile/scm-pretty-print.c b/gdb/testsuite/gdb.guile/scm-pretty-print.c index 7072f2686bd..7b453ff20b3 100644 --- a/gdb/testsuite/gdb.guile/scm-pretty-print.c +++ b/gdb/testsuite/gdb.guile/scm-pretty-print.c @@ -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; diff --git a/gdb/testsuite/gdb.mi/mi-sym-info-1.c b/gdb/testsuite/gdb.mi/mi-sym-info-1.c index c96a6bef2f3..33d355bc1d6 100644 --- a/gdb/testsuite/gdb.mi/mi-sym-info-1.c +++ b/gdb/testsuite/gdb.mi/mi-sym-info-1.c @@ -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; diff --git a/gdb/testsuite/gdb.mi/mi-sym-info-2.c b/gdb/testsuite/gdb.mi/mi-sym-info-2.c index f514e426d5e..8b17029de36 100644 --- a/gdb/testsuite/gdb.mi/mi-sym-info-2.c +++ b/gdb/testsuite/gdb.mi/mi-sym-info-2.c @@ -16,7 +16,7 @@ along with this program. If not, see . */ 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; diff --git a/gdb/testsuite/gdb.mi/mi-sym-info.exp b/gdb/testsuite/gdb.mi/mi-sym-info.exp index 859dabd040e..152a186e02c 100644 --- a/gdb/testsuite/gdb.mi/mi-sym-info.exp +++ b/gdb/testsuite/gdb.mi/mi-sym-info.exp @@ -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" diff --git a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.c b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.c index 3231b70b988..fb9a1f62147 100644 --- a/gdb/testsuite/gdb.multi/watchpoint-multi-exit.c +++ b/gdb/testsuite/gdb.multi/watchpoint-multi-exit.c @@ -21,7 +21,7 @@ #include /* 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. */ diff --git a/gdb/testsuite/gdb.python/py-as-string.c b/gdb/testsuite/gdb.python/py-as-string.c index 245bcb286bd..02563361b26 100644 --- a/gdb/testsuite/gdb.python/py-as-string.c +++ b/gdb/testsuite/gdb.python/py-as-string.c @@ -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 () diff --git a/gdb/testsuite/gdb.python/py-objfile.c b/gdb/testsuite/gdb.python/py-objfile.c index e8b9e831c56..326d9a04217 100644 --- a/gdb/testsuite/gdb.python/py-objfile.c +++ b/gdb/testsuite/gdb.python/py-objfile.c @@ -16,7 +16,7 @@ along with this program. If not, see . */ int global_var = 42; -static int static_var = 50; +static int __attribute__ ((used)) static_var = 50; int main () diff --git a/gdb/testsuite/gdb.python/py-symbol-2.c b/gdb/testsuite/gdb.python/py-symbol-2.c index 8bc78b9ea16..fdc4efd28c8 100644 --- a/gdb/testsuite/gdb.python/py-symbol-2.c +++ b/gdb/testsuite/gdb.python/py-symbol-2.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -static int rr = 99; /* line of other rr */ +static int __attribute__ ((used)) rr = 99; /* line of other rr */ void function_in_other_file (void) diff --git a/gdb/testsuite/gdb.python/py-symbol.c b/gdb/testsuite/gdb.python/py-symbol.c index 44f87bc1556..e04f6b89fc7 100644 --- a/gdb/testsuite/gdb.python/py-symbol.c +++ b/gdb/testsuite/gdb.python/py-symbol.c @@ -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) { -- 2.30.2