[pushed] Fix gdb.base/share-env-with-gdbserver.exp with Clang

Message ID 20200913203540.14520-1-pedro@palves.net
State New
Headers show
Series
  • [pushed] Fix gdb.base/share-env-with-gdbserver.exp with Clang
Related show

Commit Message

Pedro Alves Sept. 13, 2020, 8:35 p.m.
The testcase has GDB call my_getenv in the inferior, and that fails
with Clang, because Clang optimizes out my_getenv completely, since it
isn't called anywhere (in the program).

This commit fixes it.

gdb/testsuite/ChangeLog:

	* gdb.base/share-env-with-gdbserver.c (main): Call my_getenv
	instead of getenv.
---
 gdb/testsuite/gdb.base/share-env-with-gdbserver.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)


base-commit: 2f4b83cd51953fdf9626dc7a198b35505d1f5472
-- 
2.14.5

Patch

diff --git a/gdb/testsuite/gdb.base/share-env-with-gdbserver.c b/gdb/testsuite/gdb.base/share-env-with-gdbserver.c
index 740bfdcc43c..17e95756a0a 100644
--- a/gdb/testsuite/gdb.base/share-env-with-gdbserver.c
+++ b/gdb/testsuite/gdb.base/share-env-with-gdbserver.c
@@ -31,7 +31,9 @@  main (int argc, char *argv[])
 {
   /* Call malloc to ensure it is linked in.  */
   char *tmp = malloc (1);
-  const char *myvar = getenv ("GDB_TEST_VAR");
+  /* Similarly call my_getenv instead of getenv directly to make sure
+     the former isn't optimized out.  my_getenv is called by GDB.  */
+  const char *myvar = my_getenv ("GDB_TEST_VAR");
 
   if (myvar != NULL)
     printf ("It worked!  myvar = '%s'\n", myvar);