[gdb/testsuite] Handle for loop initial decl with gcc 4.8.5
authorTom de Vries <tdevries@suse.de>
Mon, 3 Jan 2022 14:36:36 +0000 (15:36 +0100)
committerTom de Vries <tdevries@suse.de>
Mon, 3 Jan 2022 14:36:36 +0000 (15:36 +0100)
When running test-case gdb.threads/schedlock-thread-exit.exp on a system with
system compiler gcc 4.8.5, I run into:
...
src/gdb/testsuite/gdb.threads/schedlock-thread-exit.c:33:3: error: \
  'for' loop initial declarations are only allowed in C99 mode
...

Fix this by:
- using -std=c99, or
- using -std=gnu99, in case that's required, or
- in the case of the jit test-cases, rewriting the for loops.

Tested on x86_64-linux, both with gcc 4.8.5 and gcc 7.5.0.

gdb/testsuite/gdb.base/inferior-args.exp
gdb/testsuite/gdb.base/jit-elf-util.h
gdb/testsuite/gdb.base/run-attach-while-running.exp
gdb/testsuite/gdb.mi/interrupt-thread-group.exp
gdb/testsuite/gdb.python/py-format-string.exp
gdb/testsuite/gdb.threads/multiple-successive-infcall.exp
gdb/testsuite/gdb.threads/schedlock-thread-exit.exp

index 4a894d7ecf80ef5a8305ee5685d3bc8f4b31787f..691ce0ae8843e6d9854277d054be53249df526a4 100644 (file)
@@ -23,7 +23,8 @@ if [target_info exists noargs] then {
 
 standard_testfile .c
 
-if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
+if {[build_executable "failed to prepare" $testfile $srcfile \
+        {debug additional_flags=-std=c99}] == -1} {
     return
 }
 
index 80dfd0c4024e8522bd7461aea9781e3bddae6bb0..419a781f86590698836701fbce17aba7ddd18a58 100644 (file)
@@ -54,8 +54,8 @@ load_symbol (void *addr, const char *sym_name)
   ElfW (Addr) sym_new_addr = 0;
 
   /* Find `func_name` in symbol_table and return its address.  */
-
-  for (int i = 0; i < ehdr->e_shnum; ++i)
+  int i;
+  for (i = 0; i < ehdr->e_shnum; ++i)
     {
       if (shdr[i].sh_type == SHT_SYMTAB)
        {
@@ -65,7 +65,8 @@ load_symbol (void *addr, const char *sym_name)
          char *const strtab
              = (char *) (addr + shdr[shdr[i].sh_link].sh_offset);
 
-         for (ElfW (Sym) *p = symtab; p < symtab_end; ++p)
+         ElfW (Sym) *p;
+         for (p = symtab; p < symtab_end; ++p)
            {
              const char *s = strtab + p->st_name;
              if (strcmp (s, sym_name) == 0)
index bd6a352a8c348d43179301e4a348fa5ec012f467..ee67db7caa5e4e8792ac7af746fbda35b5f24d8c 100644 (file)
@@ -106,7 +106,8 @@ proc_with_prefix test { non-stop threaded run-or-attach } {
 }
 
 foreach_with_prefix threaded {0 1} {
-    set options [list debug additional_flags=-DWITH_THREADS=$threaded]
+    set options [list debug additional_flags=-DWITH_THREADS=$threaded \
+                   additional_flags=-std=gnu99]
     if { $threaded } {
        set binfile $binfile_threads
        lappend options pthreads
index e4d976493e941465e69b4cae9606d2d7a60ae281..8661d573cfe21afe0585f9f8be25ec1715499d71 100644 (file)
@@ -24,7 +24,7 @@ set MIFLAGS "-i=mi"
 standard_testfile .c
 
 if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile \
-       executable debug] != "" } {
+        executable {debug additional_flags=-std=gnu99}] != "" } {
     return -1
 }
 
index 864f6b6674341a8ed06824d7f3a2a73c9a3d92d3..4c78bed120324489d4ba6fa954924edba0e9b66a 100644 (file)
@@ -33,7 +33,13 @@ if { [skip_python_tests] } { continue }
 proc build_inferior {exefile lang} {
   global srcdir subdir srcfile testfile hex
 
-  if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" executable "debug $lang"] != "" } {
+  set flags [list debug $lang]
+  if { $lang == "c" } {
+    lappend flags additional_flags=-std=c99
+  }
+
+  if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${exefile}" \
+           executable $flags] != "" } {
       untested "failed to compile in $lang mode"
       return -1
   }
index 99c8705f966345bf7c4af2a33eda127fcb796ecb..c76d366e7a250e93203ca4efb60ac5d8093e135f 100644 (file)
@@ -23,7 +23,7 @@ if [get_compiler_info] {
 }
 
 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
-  executable {debug}] != "" } {
+  executable {debug additional_flags=-std=gnu99}] != "" } {
   return -1
 }
 
index e698bb46b050c139fa79b811fbaca061a8e53087..a6e6d33f4bffe541b0ddafd72ca96def3681e1a8 100644 (file)
@@ -22,7 +22,8 @@
 
 standard_testfile
 
-if { [build_executable "failed to prepare" ${testfile} ${srcfile} {debug pthreads}] } {
+if { [build_executable "failed to prepare" ${testfile} ${srcfile} \
+         {debug pthreads additional_flags=-std=c99}] } {
     return
 }