]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb.base/examine-backward.exp C++ify and Clang
authorPedro Alves <pedro@palves.net>
Thu, 17 Sep 2020 22:33:40 +0000 (23:33 +0100)
committerPedro Alves <pedro@palves.net>
Thu, 17 Sep 2020 23:04:47 +0000 (00:04 +0100)
Adjust gdb.base/examine-backward.exp to let the testcase build and run
as a C++ program, built with either G++ or Clang++.

The change to use unsigned char instead of plain char is to avoid
narrowing warnings:

  gdb compile failed, src/gdb/testsuite/gdb.base/examine-backward.c:55:1: error: narrowing conversion of '227' from 'int' to 'char' [-Wnarrowing]
     55 | };
| ^

gdb/testsuite/ChangeLog:

* gdb.base/examine-backward.c (Barrier, TestStrings): Now unsigned
char array.
(main): Add references to Barrier, TestStrings, TestStringsH and
TestStringsW.
* gdb.base/examine-backward.exp: Issue "set print asm-demangle on"
and expect a full prototype in C++.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/examine-backward.c
gdb/testsuite/gdb.base/examine-backward.exp

index 2dbaab74d0e9c07b0d26a0cfca5a319e2fb7a55d..aee673f16212867c1fdc91c33dcad54f1087930c 100644 (file)
@@ -1,3 +1,12 @@
+2020-09-17  Pedro Alves  <pedro@palves.net>
+
+       * gdb.base/examine-backward.c (Barrier, TestStrings): Now unsigned
+       char array.
+       (main): Add references to Barrier, TestStrings, TestStringsH and
+       TestStringsW.
+       * gdb.base/examine-backward.exp: Issue "set print asm-demangle on"
+       and expect a full prototype in C++.
+
 2020-09-17  Pedro Alves  <pedro@palves.net>
 
        * gdb.base/nested-addr.c (main): Add cast.
index cf61df8bbe7064d4b6c90ac295c1308c651b7393..4db40959c48ee7c40b48c41a521b833b3028853d 100644 (file)
@@ -36,11 +36,11 @@ literals.  The content of each array is the same as followings:
    TestStrings, to avoid showing garbage when we look for strings
    backwards from TestStrings.  */
 
-const char Barrier[] = {
+const unsigned char Barrier[] = {
   0x00,
 };
 
-const char TestStrings[] = {
+const unsigned char TestStrings[] = {
   0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
   0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
   0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
@@ -92,6 +92,9 @@ const int TestStringsW[] = {
 int
 main (void)
 {
+  /* Clang++ eliminates the variables if nothing references them.  */
+  int dummy = Barrier[0] + TestStrings[0] + TestStringsH[0] + TestStringsW[0];
+
   /* Backward disassemble test requires at least 20 instructions in
      this function.  Adding a simple bubble sort.  */
   int i, j;
index c1ab4d1ce8d1ccba8923eb69cebcbdf53b56011d..b2d9fc1e1b2e19a99596a7f6e787eff942ce32b1 100644 (file)
@@ -345,9 +345,12 @@ with_test_prefix "backward disassemble general" {
     set length_to_examine {1 2 3 4 10}
     set disassmbly {}
 
-    gdb_test "x/i main" "0x\[0-9a-fA-F\]+ <main>:\t.*" \
+    gdb_test_no_output "set print asm-demangle on"
+    set main_re "main(\\(\\))?"
+
+    gdb_test "x/i main" "0x\[0-9a-fA-F\]+ <$main_re>:\t.*" \
         "move the current position to main (x/i)"
-    gdb_test "x/-i" "0x\[0-9a-fA-F\]+ <main>:\t.*" \
+    gdb_test "x/-i" "0x\[0-9a-fA-F\]+ <$main_re>:\t.*" \
         "move the current position to main (x/-i)"
     for {set i 0} {$i < [llength $length_to_examine]} {incr i} {
         set len [lindex $length_to_examine $i]