[committed][gdb/testsuite] Add save_target_board_info

Tom de Vries
2020-12-20T08:37:08Z

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

[ was: Re: [PATCH][gdb/testsuite] Fix shlib compilation with target
board unix/-pie/-fPIE ]

On 12/20/20 3:29 AM, Simon Marchi wrote:
>
>
> On 2020-12-19 12:44 p.m., Tom de Vries wrote:
>> I thought this over a bit more, and came to the realization that what
>> this does is similar to save_vars, only for target board_info.
>>
>> So, how about this refactoring?
>
> Makes sense, but I would opt for a separate save_target_board_info proc
> instead, it's a bit easier to remember how to use, and will keep each
> implementation simple.
>

Done, committed as attached.

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-testsuite-Add-save_target_board_info.patch --]
[-- Type: text/x-patch, Size: 3687 bytes --]

[gdb/testsuite] Add save_target_board_info

Add a proc save_target_board_info, similar to save_vars, such that we can do:
...
save_target_board_info { multilib_flags } {
global board
set board [target_info name]
unset_board_info multilib_flags
set_board_info multilib_flags "$override_multilib_flags"
...
}
...
and use it in gdb_compile_shlib.

Tested on x86_64-linux.

gdb/testsuite/ChangeLog:

2020-12-19 Tom de Vries <tdevries@suse.de>

* lib/gdb.exp (save_target_board_info): New proc.
(gdb_compile_shlib): Use save_target_board_info.

---
gdb/testsuite/lib/gdb.exp | 75 +++++++++++++++++++++++++++++++++++------------
1 file changed, 56 insertions(+), 19 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index e91023093e..5bdc7ff8ee 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -2427,6 +2427,53 @@ proc save_vars { vars body } {
}
}

+# As save_vars, but for variables stored in the board_info for the
+# target board.
+#
+# Usage example:
+#
+# save_target_board_info { multilib_flags } {
+# global board
+# set board [target_info name]
+# unset_board_info multilib_flags
+# set_board_info multilib_flags "$multilib_flags"
+# ...
+# }
+
+proc save_target_board_info { vars body } {
+ global board board_info
+ set board [target_info name]
+
+ array set saved_target_board_info { }
+ set unset_target_board_info { }
+
+ foreach var $vars {
+ if { [info exists board_info($board,$var)] } {
+ set saved_target_board_info($var) [board_info $board $var]
+ } else {
+ lappend unset_target_board_info $var
+ }
+ }
+
+ set code [catch {uplevel 1 $body} result]
+
+ foreach {var value} [array get saved_target_board_info] {
+ unset_board_info $var
+ set_board_info $var $value
+ }
+
+ foreach var $unset_target_board_info {
+ unset_board_info $var
+ }
+
+ if {$code == 1} {
+ global errorInfo errorCode
+ return -code $code -errorinfo $errorInfo -errorcode $errorCode $result
+ } else {
+ return -code $code $result
+ }
+}
+
# Run tests in BODY with the current working directory (CWD) set to
# DIR. When BODY is finished, restore the original CWD. Return the
# result of BODY.
@@ -4422,32 +4469,22 @@ proc gdb_compile_shlib_1 {sources dest options} {
proc gdb_compile_shlib {sources dest options} {
global board

- # Save multilib_flags.
- set board [target_info name]
- set save_multilib_flag [board_info $board multilib_flags]
-
# Ignore PIE-related setting in multilib_flags.
- set multilib_flag ""
- foreach op $save_multilib_flag {
+ set board [target_info name]
+ set multilib_flags_orig [board_info $board multilib_flags]
+ set multilib_flags ""
+ foreach op $multilib_flags_orig {
if { $op == "-pie" || $op == "-no-pie" \
|| $op == "-fPIE" || $op == "-fno-PIE"} {
} else {
- append multilib_flag " $op"
+ append multilib_flags " $op"
}
}
- unset_board_info "multilib_flags"
- set_board_info multilib_flags "$multilib_flag"
- set code [catch {gdb_compile_shlib_1 $sources $dest $options} result]

- # Restore multilib_flags.
- unset_board_info "multilib_flags"
- set_board_info multilib_flags $save_multilib_flag
-
- if {$code == 1} {
- global errorInfo errorCode
- return -code error -errorinfo $errorInfo -errorcode $errorCode $result
- } elseif {$code > 1} {
- return -code $code $result
+ save_target_board_info { multilib_flags } {
+ unset_board_info multilib_flags
+ set_board_info multilib_flags "$multilib_flags"
+ set result [gdb_compile_shlib_1 $sources $dest $options]
}

return $result