[PATCH] [gdb/testsuite] Fix gdb.cp/m-static.exp on arm

Tom de Vries tdevries@suse.de
Sun Jul 21 08:11:05 GMT 2024


With test-case gdb.cp/m-static.exp on arm-linux, I get:
...
(gdb) ptype test5.single_constructor^M
type = class single_constructor {^M
^M
  public:^M
    single_constructor(void);^M
    ~single_constructor(void);^M
} *(single_constructor * const)^M
(gdb) FAIL: gdb.cp/m-static.exp: simple object instance, ptype constructor
...

The test-case expects:
- no empty line before "public:", and
- no "~single_constructor(void)", but "~single_constructor()"

The latter is due to commit 137c886e9a6 ("[gdb/c++] Print destructor the same
for gcc and clang").

The failing test is in a part only enabled for is_aarch32_target == 1, so it
looks like it was left behind.

I'm assuming the same happened for the other difference.

Fix this by updating the regexps to match the observed output.

Tested on arm-linux.
---
 gdb/testsuite/gdb.cp/m-static.exp | 17 +++++++++++++----
 gdb/testsuite/lib/gdb-utils.exp   |  8 ++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/gdb.cp/m-static.exp b/gdb/testsuite/gdb.cp/m-static.exp
index 45bc090d01f..68b215a1d01 100644
--- a/gdb/testsuite/gdb.cp/m-static.exp
+++ b/gdb/testsuite/gdb.cp/m-static.exp
@@ -71,11 +71,20 @@ if { [is_aarch32_target] } {
     gdb_test "print test5.single_constructor" \
 	{ = {single_constructor \*\(single_constructor \* const\)} 0x[0-9a-f]+ <single_constructor::single_constructor\(\)>} \
 	"simple object instance, print constructor"
-    gdb_test "ptype test5.single_constructor" \
-	{type = class single_constructor {\r\n  public:\r\n    single_constructor\(void\);\r\n    ~single_constructor\(\);\r\n} \*\(single_constructor \* const\)} \
+
+    set open_scope "\{"
+    set close_scope "\}"
+    set re \
+	[multi_line_string_to_regexp \
+	     "type = class single_constructor $open_scope" \
+	     "" \
+	     "  public:" \
+	     "    single_constructor(void);" \
+	     "    ~single_constructor(void);" \
+	     "$close_scope *(single_constructor * const)"]
+    gdb_test "ptype test5.single_constructor" $re \
 	"simple object instance, ptype constructor"
-    gdb_test "ptype single_constructor::single_constructor" \
-	{type = class single_constructor {\r\n  public:\r\n    single_constructor\(void\);\r\n    ~single_constructor\(\);\r\n} \*\(single_constructor \* const\)} \
+    gdb_test "ptype single_constructor::single_constructor" $re \
 	"simple object class, ptype constructor"
 
     gdb_test "print test1.~gnu_obj_1" \
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 95c53d030d8..41989da3ed2 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -38,6 +38,14 @@ proc string_to_regexp {str} {
     return $result
 }
 
+# Convenience function that calls string_to_regexp for each arg, and
+# joins the results using "\r\n".
+
+proc multi_line_string_to_regexp { args } {
+    set res [lmap arg $args {string_to_regexp $arg}]
+    return [multi_line {*}$res]
+}
+
 # Given a list of strings, adds backslashes as needed to each string to
 # create a regexp that will match the string, and join the result.
 

base-commit: ad88661d55f3e62d90c44c8c286223db9aa76a77
-- 
2.35.3



More information about the Gdb-patches mailing list