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.
This commit is contained in:
Gary Benson
2020-10-12 10:35:23 +01:00
parent 8a6e98c4a3
commit 71e1b6b0ac
15 changed files with 36 additions and 19 deletions

View 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

View 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)
{
}

View 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)
{
}

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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"

View 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. */

View 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 ()

View 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 ()

View 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)

View 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)
{