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

Pedro Alves pedro@palves.net
Sun Sep 13 20:35:40 GMT 2020


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

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

base-commit: 2f4b83cd51953fdf9626dc7a198b35505d1f5472
-- 
2.14.5



More information about the Gdb-patches mailing list