[PATCH]-Change gdb.base/examine-backwards.exp testcase for AIX

Aditya Kamath1
2023-11-06T11:03:24Z

[-- Attachment #1.1: Type: text/plain, Size: 4401 bytes --]

Respected GDB community members,

Hi,

This is a patch requesting to modify the gdb.base/examine-backwards testcase so that AIX can also pass this test. Currently we fail by saying

Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/aditya/gdb_tests/examine-backward...
(gdb) b main
Breakpoint 1 at 0x100004ac: file /home/aditya/gdb_tests/examine-backward.c, line 96.
(gdb) r
Starting program: /home/aditya/gdb_tests/examine-backward

Breakpoint 1, main () at /home/aditya/gdb_tests/examine-backward.c:96
96 int dummy = Barrier[0] + TestStrings[0] + TestStringsH[0] + TestStringsW[0];
(gdb) x/6s TestStrings
0xffffffff: <error: Cannot access memory at address 0xffffffff>
0xffffffff: <error: Cannot access memory at address 0xffffffff>
0xffffffff: <error: Cannot access memory at address 0xffffffff>
0xffffffff: <error: Cannot access memory at address 0xffffffff>
0xffffffff: <error: Cannot access memory at address 0xffffffff>
0xffffffff: <error: Cannot access memory at address 0xffffffff>
(gdb)

This is because linker has not assigned any address to the variable TestStrings and still treats it as unused.

In the dwarf dump in AIX for the gdb.base/examine-backward.c file’s binary we see:-

<1>< 252> DW_TAG_variable
DW_AT_name TestStrings
DW_AT_decl_file 1
DW_AT_decl_line 43
DW_AT_decl_column 21
DW_AT_type <247>
DW_AT_external yes
DW_AT_location DW_OP_addr 0xffffffff
<1>< 278> DW_TAG_array_type
DW_AT_type <312>
DW_AT_sibling <294>
<2>< 287> DW_TAG_subrange_type
DW_AT_type <166>
DW_AT_upper_bound 72
<1>< 294> DW_TAG_const_type
DW_AT_type <278>
<1>< 299> DW_TAG_base_type
DW_AT_byte_size 2
DW_AT_encoding DW_ATE_signed
DW_AT_name short int
<1>< 312> DW_TAG_const_type
DW_AT_type <299>
<1>< 317> DW_TAG_variable
DW_AT_name TestStringsH
DW_AT_decl_file 1

This is a problem. After we modify the test case as done by this patch say using {+ char *dummy_string = TestStrings;} we get,

(gdb) b main
Breakpoint 1 at 0x100004ac: file /home/aditya/gdb_tests/examine-backward.c, line 96.
(gdb) r
Starting program: /home/aditya/gdb_tests/examine-backward

Breakpoint 1, main () at /home/aditya/gdb_tests/examine-backward.c:96
96 int dummy = Barrier[0] + TestStrings[0] + TestStringsH[0] + TestStringsW[0];
(gdb) x/6s TestStrings
0x10000c74 <TestStrings>: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
0x10000c8f <TestStrings+27>: ""
0x10000c90 <TestStrings+28>: ""
0x10000c91 <TestStrings+29>: "�\201��\201\222�\201��\201\222"
0x10000c9e <TestStrings+42>: "012345678901234567890123456789"
0x10000cbd <TestStrings+73>: "!!!!!!"
(gdb)

Dwarf dump after modification of the test case:-
<1>< 242> DW_TAG_variable
DW_AT_name TestStrings
DW_AT_decl_file 1
DW_AT_decl_line 43
DW_AT_decl_column 21
DW_AT_type <237>
DW_AT_external yes
DW_AT_location DW_OP_addr 0x10000c74

Test case numbers after patch applied:-
=== gdb Summary ===

# of expected passes 70
# of unsupported tests 1

Before we applied this patch, we had around 28 failures. 1 unsupported is info proc mappings which is not there in AIX as of now.

Kindly let me know what you think. I know that we have some dummy variables that is used to negate a similar problem using clang with lto. But if we can produce something that works for both AIX GCC and other targets Clang with LTO it will be great, and we can create a patch.

Have a nice day ahead.

Thanks and regards,
Aditya Kamath.

[-- Attachment #1.2: Type: text/html, Size: 15113 bytes --]

[-- Attachment #2: 0001-Change-gdb.base-examine-backwards.exp-for-AIX.patch --]
[-- Type: application/octet-stream, Size: 1294 bytes --]

From 14f0452ef34f1a47f14717d081bdc890babeded7 Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Date: Mon, 6 Nov 2023 04:42:38 -0600
Subject: [PATCH] Change gdb.base/examine-backwards.exp for AIX.

In AIX unused variables are collected as garbage by the linker and in the dwarf dump
an address which all f's in hexadecimal are assigned. Hence the testcase fails with many failures stating
it cannot access memory.

This patch is a small change to get it working in AIX as well.
---
gdb/testsuite/gdb.base/examine-backward.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/gdb/testsuite/gdb.base/examine-backward.c b/gdb/testsuite/gdb.base/examine-backward.c
index e30b58fb005..995dc6a0b78 100644
--- a/gdb/testsuite/gdb.base/examine-backward.c
+++ b/gdb/testsuite/gdb.base/examine-backward.c
@@ -95,6 +95,12 @@ main (void)
/* Clang++ eliminates the variables if nothing references them. */
int dummy = Barrier[0] + TestStrings[0] + TestStringsH[0] + TestStringsW[0];

+ #ifdef _AIX
+ char *dummy_string = TestStrings;
+ dummy_string = TestStringsH;
+ dummy_string = TestStringsW;
+ #endif
+
/* Backward disassemble test requires at least 20 instructions in
this function. Adding a simple bubble sort. */
int i, j;
--
2.38.3