Files
Christina Schimpe ff52c0736a gdb: Make global feature array a per-remote target array
This patch applies the appropriate FIXME notes described in commit 5b6d1e4
"Multi-target support".

"You'll notice that remote.c includes some FIXME notes.  These refer to
the fact that the global arrays that hold data for the remote packets
supported are still globals.  For example, if we connect to two
different servers/stubs, then each might support different remote
protocol features.  They might even be different architectures, like
e.g., one ARM baremetal stub, and a x86 gdbserver, to debug a
host/controller scenario as a single program.  That isn't going to
work correctly today, because of said globals.  I'm leaving fixing
that for another pass, since it does not appear to be trivial, and I'd
rather land the base work first.  It's already useful to be able to
debug multiple instances of the same server (e.g., a distributed
cluster, where you have full control over the servers installed), so I
think as is it's already reasonable incremental progress."

Using this patch it is possible to configure per-remote targets'
feature packets.

Given the following setup for two gdbservers:

~~~~
gdbserver --multi :1234
gdbserver --disable-packet=vCont --multi :2345
~~~~

Before this patch configuring of range-stepping was not possible for one
of two connected remote targets with different support for the vCont
packet.  As one of the targets supports vCont, it should be possible to
configure "set range-stepping".  However, the output of GDB looks like:

(gdb) target extended-remote :1234
Remote debugging using :1234
(gdb) add-inferior -no-connection
[New inferior 2]
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) target extended-remote :2345
Remote debugging using :2345
(gdb) set range-stepping on
warning: Range stepping is not supported by the current target
(gdb) inferior 1
[Switching to inferior 1 [<null>] (<noexec>)]
(gdb) set range-stepping on
warning: Range stepping is not supported by the current target
~~~~

Two warnings are shown.  The warning for inferior 1 should not appear
as it is connected to a target supporting the vCont package.

~~~~
(gdb) target extended-remote :1234
Remote debugging using :1234
(gdb) add-inferior -no-connection
[New inferior 2]
Added inferior 2
(gdb) inferior 2
[Switching to inferior 2 [<null>] (<noexec>)]
(gdb) target extended-remote :2345
Remote debugging using :2345
(gdb) set range-stepping on
warning: Range stepping is not supported by the current target
(gdb) inferior 1
[Switching to inferior 1 [<null>] (<noexec>)]
(gdb) set range-stepping on
(gdb)
~~~~

Now only one warning is shown for inferior 2, which is connected to
a target not supporting vCont.

The per-remote target feature array is realized by a new class
remote_features, which stores the per-remote target array and
provides functions to determine supported features of the target.
A remote_target object now has a new member of that class.

Each time a new remote_target object is initialized, a new per-remote
target array is constructed based on the global remote_protocol_packets
array.  The global array is initialized in the function _initialize_remote
and can be configured using the command line.  Before this patch the
command line configuration affected current targets and future remote
targets (due to the global feature array used by all remote
targets).  This behavior is different and the configuration applies as
follows:

 - If a target is connected, the command line configuration affects the
   current connection.  All other existing remote targets are not
   affected.

 - If not connected, the command line configuration affects future
   connections.

The show command displays the current remote target's configuration.  If no
remote target is selected the default configuration for future
connections is shown.

If we have for instance the following setup with inferior 2 being
selected:
~~~~
(gdb) info inferiors
  Num  Description       Connection                Executable
  1    <null>             1 (extended-remote :1234)
* 2    <null>             2 (extended-remote :2345)
~~~~

Before this patch, if we run 'set remote multiprocess-feature-packet', the
following configuration was set:
The feature array of all remote targets (in this setup the two connected
targets) and all future remote connections are affected.

After this patch, it will be configured as follows:
The feature array of target with port :2345 which is currently selected
will be configured.  All other existing remote targets are not affected.
The show command 'show remote multiprocess-feature-packet' will display
the configuration of target with port :2345.

Due to this configuration change, it is required to adapt the test
"gdb/testsuite/gdb.multi/multi-target-info-inferiors.exp" to configure the
multiprocess-feature-packet before the connections are created.

To inform the gdb user about the new behaviour of the 'show remote
PACKET-NAME' commands and the new configuration impact for remote
targets using the 'set remote PACKET-NAME' commands the commands'
outputs are adapted.  Due to this change it is required to adapt each
test using the set/show remote 'PACKET-NAME' commands.
2023-01-30 12:45:31 +01:00

225 lines
6.0 KiB
Plaintext

# Copyright (C) 2012-2023 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
standard_testfile
if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
return -1
}
set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
set dp_location1 [gdb_get_line_number "set dprintf 1 here"]
if ![runto_main] {
return -1
}
gdb_test "dprintf" "Format string required"
gdb_test "dprintf foo" "Format string required"
gdb_test "dprintf 29" "Format string required"
delete_breakpoints
gdb_breakpoint "main"
gdb_test "dprintf foo,\"At foo entry\\n\"" \
"Dprintf .*"
gdb_test "ignore \$bpnum 1" ".*Will ignore next crossing of breakpoint.*"
gdb_test "dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \
"Dprintf .*"
gdb_test_sequence "info breakpoints" "dprintf info 1" {
"\[\r\n\]Num Type Disp Enb Address +What"
"\[\r\n\]2 breakpoint"
"\[\r\n\]3 dprintf"
"\[\r\n\] printf \"At foo entry\\\\n\""
"\[\r\n\]4 dprintf"
"\[\r\n\] printf \"arg=%d, g=%d\\\\n\", arg, g"
}
gdb_test "break $bp_location1" \
"Breakpoint .*"
gdb_run_cmd
gdb_test "" "Breakpoint"
gdb_test "continue" "arg=1234, g=1234.*" "1st dprintf, gdb"
gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, gdb"
# Restart GDB and set set up for testing.
proc restart {} {
global binfile
global bp_location1 dp_location1
clean_restart $binfile
if ![runto_main] {
return -1
}
gdb_test "dprintf foo,\"At foo entry\\n\"" \
"Dprintf .*"
gdb_test "dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \
"Dprintf .*"
gdb_test "break $bp_location1" "Breakpoint .*"
}
# Test continuing across a dprintf. PATTERN matches the output
# generated by the dprintf. MSG is used as test message.
proc test_dprintf {pattern msg} {
gdb_test_stdio "continue" $pattern "" "$msg"
}
# Test the "call" style.
proc test_call {} {
global binfile
global bp_location1
# Now switch styles and rerun; in the absence of redirection the
# output should be the same.
with_test_prefix "printf" {
restart
gdb_test_no_output "set dprintf-style call" "set dprintf style to call"
test_dprintf "At foo entry.*arg=1234, g=1234\r\n" "1st dprintf"
test_dprintf "At foo entry.*arg=1235, g=2222\r\n" "2nd dprintf"
}
gdb_test_multiple "print stderr" "stderr symbol check" {
-re "\\'stderr\\' has unknown type.*" {
untested "No information available for stderr, exiting early"
return
}
-re "\\\$1.*" {
pass $gdb_test_name
}
}
with_test_prefix "fprintf" {
restart
gdb_test_no_output "set dprintf-function fprintf" "set dprintf function"
gdb_test_no_output "set dprintf-channel stderr" "set dprintf channel"
gdb_test_no_output "set dprintf-style call" "set dprintf style to call"
test_dprintf "At foo entry.*arg=1234, g=1234\r\n" "1st dprintf"
test_dprintf "At foo entry.*arg=1235, g=2222\r\n" "2nd dprintf"
}
}
# The "call" style depends on having I/O functions available.
if ![target_info exists gdb,noinferiorio] {
with_test_prefix "call" {
test_call
}
}
# Test the "agent" style.
proc test_agent {} {
global binfile
global gdb_prompt
restart
set target_can_dprintf 1
set msg "set dprintf style to agent"
gdb_test_multiple "set dprintf-style agent" $msg {
-re "warning: Target cannot run dprintf commands.*\r\n$gdb_prompt $" {
# The target reports that it doesn't support target side
# commands at all.
set target_can_dprintf 0
unsupported "$msg"
}
-re ".*$gdb_prompt $" {
pass "$msg"
}
}
if !$target_can_dprintf {
return
}
# Even if the target reports that it does support target side
# commands, we can only tell that it supports them in combination
# with a particular breakpoint type (Z0, Z1, etc.) when we try to
# insert the breakpoint. When "set breakpoint always-inserted is
# off", that'll be on next continue.
set msg "1st dprintf"
gdb_test_multiple "continue" $msg {
-re "Warning:.*Target doesn't support breakpoints that have target side commands.*\r\n$gdb_prompt $" {
set target_can_dprintf 0
unsupported "$msg"
}
-re "Breakpoint \[0-9\]+, foo .*$gdb_prompt $" {
pass "$msg"
}
}
if $target_can_dprintf {
gdb_test "continue" "Breakpoint \[0-9\]+, foo .*" "2nd dprintf"
gdb_test_sequence "info breakpoints" "dprintf info" {
"\[\r\n\]Num Type Disp Enb Address +What"
"\[\r\n\]1 breakpoint"
"\[\r\n\]\tbreakpoint already hit 1 time"
"\[\r\n\]2 dprintf"
"\[\r\n\] agent-printf \"At foo entry\\\\n\""
"\[\r\n\]3 dprintf"
"\[\r\n\] agent-printf \"arg=%d, g=%d\\\\n\", arg, g"
"\[\r\n\]4 breakpoint"
"\[\r\n\]\tbreakpoint already hit 2 times"
}
}
}
with_test_prefix "agent" {
test_agent
}
gdb_test "set dprintf-style foobar" "Undefined item: \"foobar\"." \
"Set dprintf style to an unrecognized type"
# Test that force-disabling the BreakpointCommands RSP feature works
# as expected. dprintf relies on support for target-side breakpoint
# commands --- use it as proxy.
if [gdb_is_target_remote] {
gdb_test \
"set remote breakpoint-commands-packet off" \
"Support for the 'BreakpointCommands' packet on the current remote target is set to \"off\"."
gdb_test "set dprintf-style agent" \
"warning: Target cannot run dprintf commands.*" \
"set dprintf-style agent, with feature disabled"
}