From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7869) id CB15C3858C2F; Mon, 30 Jan 2023 14:32:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB15C3858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675089168; bh=3iXR2xOrOAh0+PtOL6Hjl/4mLW7uR77ZbVb2uJAQ1Yc=; h=From:To:Subject:Date:From; b=wKvAPzViPv3TLgY/sE6Ym/n7b+KyIq//H+pIN/wkpue5ImNxVGuNoNhdPnUtKr396 PbGChCSfgeq2wEy/FcubnwyOfZ1cPhRTqj9f0Ykif6/40h78ctg+1w6zJC3QndcH+1 F0ZG9UsKSjBENN+Cs+jEBKy6QFLTl94MTjaxo7BY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Christina Schimpe To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: Add per-remote target variables for memory read and write config X-Act-Checkin: binutils-gdb X-Git-Author: Christina Schimpe X-Git-Refname: refs/heads/master X-Git-Oldrev: ff52c0736a637fec4938f4b957bc8847c709b13c X-Git-Newrev: fe4c3ca0036b37ea43be1c36728b323f195ef1bb Message-Id: <20230130143248.CB15C3858C2F@sourceware.org> Date: Mon, 30 Jan 2023 14:32:48 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dfe4c3ca0036b= 37ea43be1c36728b323f195ef1bb commit fe4c3ca0036b37ea43be1c36728b323f195ef1bb Author: Christina Schimpe Date: Fri Nov 26 18:23:48 2021 +0000 gdb: Add per-remote target variables for memory read and write config =20 This patch adds per-remote target variables for the configuration of memory read- and write packet size. It is a further change to commit "gdb: Make global feature array a per-remote target array" to apply the fixme notes described in commit 5b6d1e4 "Multi-target support". =20 The former global variables for that configuration are still available to allow the command line configuration for all future remote connections. Similar to the command line configuration of the per- remote target feature array, the commands =20 - set remotewritesize (deprecated) - set remote memory-read-packet-size - set remote memory-write-packet-size =20 will configure the current target (if available). If no target is available, the default configuration for future remote connections is adapted. The show command will display the current remote target's packet size configuration. If no remote target is selected, the default configuration for future connections will be shown. =20 It is required to adapt the test gdb.base/remote.exp which is failing for --target_board=3Dnative-extended-gdbserver. With that board GDB connects to gdbserver at gdb start time. Due to this patch two loggings "The target may not be able to.." are shown if the command 'set remote memory-write-packet-size fixed' is executed while a target is connected for the current inferior. To fix this, the clean_restart command is moved to a later time point of the test. It is sufficient to be connected to the server when "runto_main" is executed. Now the connection time is similar to a testrun with --target_board=3Dnative-gdbserver. =20 To allow the user to distinguish between the packet-size configuration for future remote connections and for the currently selected target, the commands' loggings are adapted. Diff: --- gdb/NEWS | 11 ++- gdb/doc/gdb.texinfo | 15 ++++ gdb/remote.c | 163 +++++++++++++++++++++++++++-------= ---- gdb/testsuite/gdb.base/remote.exp | 45 +++++++---- 4 files changed, 169 insertions(+), 65 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 9a40932b79d..445d28efed9 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -11,8 +11,15 @@ configure a target's feature packet and to display its configuration, respectively. =20 - The configuration of the packet itself applies to the currently selected - target (if available). If no target is selected, it applies to future r= emote + The individual packet sizes can be configured and shown using the comman= ds + ** 'set remote memory-read-packet-size (number of bytes|fixed|limit)' + ** 'set remote memory-write-packet-size (number of bytes|fixed|limit)' + ** 'show remote memory-read-packet-size' + ** 'show remote memory-write-packet-size'. + + The configuration of the packet itself, as well as the size of a memory-= read + or memory-write packet applies to the currently selected target (if + available). If no target is selected, it applies to future remote connections. Similarly, the show commands print the configuration of the currently selected target. If no remote target is selected, the default configuration for future connections is shown. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index afbb4dea998..03033c7f9e3 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -24128,6 +24128,21 @@ future connections is shown. The available settin= gs are: =20 @end multitable =20 +@cindex packet size, remote, configuring +The number of bytes per memory-read or memory-write packet for a remote ta= rget +can be configured using the commands +@w{@code{set remote memory-read-packet-size}} and +@w{@code{set remote memory-write-packet-size}}. If set to @samp{0} (zero)= the +default packet size will be used. The actual limit is further reduced dep= ending +on the target. Specify @samp{fixed} to disable the target-dependent restr= iction +and @samp{limit} to enable it. Similar to the enabling and disabling of r= emote +packets, the command applies to the currently selected target (if availabl= e). +If no remote target is selected, it applies to all future remote connectio= ns. +The configuration of the selected target can be displayed using the comman= ds +@w{@code{show remote memory-read-packet-size}} and +@w{@code{show remote memory-write-packet-size}}. If no remote target is +selected, the default configuration for future connections is shown. + @node Remote Stub @section Implementing a Remote Stub =20 diff --git a/gdb/remote.c b/gdb/remote.c index e4333291de8..9f78d359542 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -600,6 +600,32 @@ struct packet_config enum packet_support support; }; =20 +/* User configurable variables for the number of characters in a + memory read/write packet. MIN (rsa->remote_packet_size, + rsa->sizeof_g_packet) is the default. Some targets need smaller + values (fifo overruns, et.al.) and some users need larger values + (speed up transfers). The variables ``preferred_*'' (the user + request), ``current_*'' (what was actually set) and ``forced_*'' + (Positive - a soft limit, negative - a hard limit). */ + +struct memory_packet_config +{ + const char *name; + long size; + int fixed_p; +}; + +/* These global variables contain the default configuration for every new + remote_feature object. */ +static memory_packet_config memory_read_packet_config =3D +{ + "memory-read-packet-size", +}; +static memory_packet_config memory_write_packet_config =3D +{ + "memory-write-packet-size", +}; + /* This global array contains packet descriptions (name and title). */ static packet_description packets_descriptions[PACKET_MAX]; /* This global array contains the default configuration for every new @@ -613,6 +639,9 @@ struct remote_features { remote_features () { + m_memory_read_packet_config =3D memory_read_packet_config; + m_memory_write_packet_config =3D memory_write_packet_config; + std::copy (std::begin (remote_protocol_packets), std::end (remote_protocol_packets), std::begin (m_protocol_packets)); @@ -658,6 +687,11 @@ struct remote_features packet_result packet_ok (const char *buf, const int which_packet); packet_result packet_ok (const gdb::char_vector &buf, const int which_pa= cket); =20 + /* Configuration of a remote target's memory read packet. */ + memory_packet_config m_memory_read_packet_config; + /* Configuration of a remote target's memory write packet. */ + memory_packet_config m_memory_write_packet_config; + /* The per-remote target array which stores a remote's packet configurations. */ packet_config m_protocol_packets[PACKET_MAX]; @@ -1921,21 +1955,6 @@ show_remotebreak (struct ui_file *file, int from_tty, static unsigned int remote_address_size; =20 =0C -/* User configurable variables for the number of characters in a - memory read/write packet. MIN (rsa->remote_packet_size, - rsa->sizeof_g_packet) is the default. Some targets need smaller - values (fifo overruns, et.al.) and some users need larger values - (speed up transfers). The variables ``preferred_*'' (the user - request), ``current_*'' (what was actually set) and ``forced_*'' - (Positive - a soft limit, negative - a hard limit). */ - -struct memory_packet_config -{ - const char *name; - long size; - int fixed_p; -}; - /* The default max memory-write-packet-size, when the setting is "fixed". The 16k is historical. (It came from older GDB's using alloca for buffers and the knowledge (folklore?) that some hosts @@ -2001,13 +2020,14 @@ remote_target::get_memory_packet_size (struct memor= y_packet_config *config) something really big then do a sanity check. */ =20 static void -set_memory_packet_size (const char *args, struct memory_packet_config *con= fig) +set_memory_packet_size (const char *args, struct memory_packet_config *con= fig, + bool target_connected) { int fixed_p =3D config->fixed_p; long size =3D config->size; =20 if (args =3D=3D NULL) - error (_("Argument required (integer, `fixed' or `limited').")); + error (_("Argument required (integer, \"fixed\" or \"limit\").")); else if (strcmp (args, "hard") =3D=3D 0 || strcmp (args, "fixed") =3D=3D 0) fixed_p =3D 1; @@ -2035,31 +2055,49 @@ set_memory_packet_size (const char *args, struct me= mory_packet_config *config) ? DEFAULT_MAX_MEMORY_PACKET_SIZE_FIXED : size); =20 - if (! query (_("The target may not be able to correctly handle a %s\= n" - "of %ld bytes. Change the packet size? "), - config->name, query_size)) + if (target_connected + && !query (_("The target may not be able to correctly handle a %s\n" + "of %ld bytes. Change the packet size? "), + config->name, query_size)) + error (_("Packet size not changed.")); + else if (!target_connected + && !query (_("Future remote targets may not be able to " + "correctly handle a %s\nof %ld bytes. Change the " + "packet size for future remote targets? "), + config->name, query_size)) error (_("Packet size not changed.")); } /* Update the config. */ config->fixed_p =3D fixed_p; config->size =3D size; + + const char *target_type =3D get_target_type_name (target_connected); + gdb_printf (_("The %s %s is set to \"%s\".\n"), config->name, target_typ= e, + args); + } =20 +/* Show the memory-read or write-packet size configuration CONFIG of the + target REMOTE. If REMOTE is nullptr, the default configuration for fut= ure + remote targets should be passed in CONFIG. */ + static void -show_memory_packet_size (struct memory_packet_config *config) +show_memory_packet_size (memory_packet_config *config, remote_target *remo= te) { + const char *target_type =3D get_target_type_name (remote !=3D nullptr); + if (config->size =3D=3D 0) - gdb_printf (_("The %s is 0 (default). "), config->name); + gdb_printf (_("The %s %s is 0 (default). "), config->name, target_type= ); else - gdb_printf (_("The %s is %ld. "), config->name, config->size); + gdb_printf (_("The %s %s is %ld. "), config->name, target_type, + config->size); + if (config->fixed_p) gdb_printf (_("Packets are fixed at %ld bytes.\n"), get_fixed_memory_packet_size (config)); else { - remote_target *remote =3D get_current_remote_target (); - - if (remote !=3D NULL) + if (remote !=3D nullptr) gdb_printf (_("Packets are limited to %ld bytes.\n"), remote->get_memory_packet_size (config)); else @@ -2068,22 +2106,39 @@ show_memory_packet_size (struct memory_packet_confi= g *config) } } =20 -/* FIXME: needs to be per-remote-target. */ -static struct memory_packet_config memory_write_packet_config =3D -{ - "memory-write-packet-size", -}; +/* Configure the memory-write-packet size of the currently selected target= . If + no target is available, the default configuration for future remote tar= gets + is configured. */ =20 static void set_memory_write_packet_size (const char *args, int from_tty) { - set_memory_packet_size (args, &memory_write_packet_config); + remote_target *remote =3D get_current_remote_target (); + if (remote !=3D nullptr) + { + set_memory_packet_size + (args, &remote->m_features.m_memory_write_packet_config, true); + } + else + { + memory_packet_config* config =3D &memory_write_packet_config; + set_memory_packet_size (args, config, false); + } } =20 +/* Display the memory-write-packet size of the currently selected target. = If + no target is available, the default configuration for future remote tar= gets + is shown. */ + static void show_memory_write_packet_size (const char *args, int from_tty) { - show_memory_packet_size (&memory_write_packet_config); + remote_target *remote =3D get_current_remote_target (); + if (remote !=3D nullptr) + show_memory_packet_size (&remote->m_features.m_memory_write_packet_con= fig, + remote); + else + show_memory_packet_size (&memory_write_packet_config, nullptr); } =20 /* Show the number of hardware watchpoints that can be used. */ @@ -2139,31 +2194,47 @@ show_remote_packet_max_chars (struct ui_file *file,= int from_tty, long remote_target::get_memory_write_packet_size () { - return get_memory_packet_size (&memory_write_packet_config); + return get_memory_packet_size (&m_features.m_memory_write_packet_config); } =20 -/* FIXME: needs to be per-remote-target. */ -static struct memory_packet_config memory_read_packet_config =3D -{ - "memory-read-packet-size", -}; +/* Configure the memory-read-packet size of the currently selected target.= If + no target is available, the default configuration for future remote tar= gets + is adapted. */ =20 static void set_memory_read_packet_size (const char *args, int from_tty) { - set_memory_packet_size (args, &memory_read_packet_config); + remote_target *remote =3D get_current_remote_target (); + if (remote !=3D nullptr) + set_memory_packet_size + (args, &remote->m_features.m_memory_read_packet_config, true); + else + { + memory_packet_config* config =3D &memory_read_packet_config; + set_memory_packet_size (args, config, false); + } + } =20 +/* Display the memory-read-packet size of the currently selected target. = If + no target is available, the default configuration for future remote tar= gets + is shown. */ + static void show_memory_read_packet_size (const char *args, int from_tty) { - show_memory_packet_size (&memory_read_packet_config); + remote_target *remote =3D get_current_remote_target (); + if (remote !=3D nullptr) + show_memory_packet_size (&remote->m_features.m_memory_read_packet_conf= ig, + remote); + else + show_memory_packet_size (&memory_read_packet_config, nullptr); } =20 long remote_target::get_memory_read_packet_size () { - long size =3D get_memory_packet_size (&memory_read_packet_config); + long size =3D get_memory_packet_size (&m_features.m_memory_read_packet_c= onfig); =20 /* FIXME: cagney/1999-11-07: Functions like getpkt() need to get an extra buffer size argument before the memory read size can be @@ -15082,16 +15153,16 @@ Show the maximum number of bytes per memory write= packet (deprecated)."), Set the maximum number of bytes per memory-write packet.\n\ Specify the number of bytes in a packet or 0 (zero) for the\n\ default packet size. The actual limit is further reduced\n\ -dependent on the target. Specify ``fixed'' to disable the\n\ -further restriction and ``limit'' to enable that restriction."), +dependent on the target. Specify \"fixed\" to disable the\n\ +further restriction and \"limit\" to enable that restriction."), &remote_set_cmdlist); add_cmd ("memory-read-packet-size", no_class, set_memory_read_packet_size, _("\ Set the maximum number of bytes per memory-read packet.\n\ Specify the number of bytes in a packet or 0 (zero) for the\n\ default packet size. The actual limit is further reduced\n\ -dependent on the target. Specify ``fixed'' to disable the\n\ -further restriction and ``limit'' to enable that restriction."), +dependent on the target. Specify \"fixed\" to disable the\n\ +further restriction and \"limit\" to enable that restriction."), &remote_set_cmdlist); add_cmd ("memory-write-packet-size", no_class, show_memory_write_packet_size, diff --git a/gdb/testsuite/gdb.base/remote.exp b/gdb/testsuite/gdb.base/rem= ote.exp index b9b05deb2b5..3dc5f8f97ee 100644 --- a/gdb/testsuite/gdb.base/remote.exp +++ b/gdb/testsuite/gdb.base/remote.exp @@ -39,31 +39,37 @@ gdb_test "disconnect" ".*" # =20 gdb_test "show remote memory-write-packet-size" \ - "The memory-write-packet-size is 0 \\(default\\). The actual limit will b= e further reduced dependent on the target\." \ + "The memory-write-packet-size on future remote targets is 0 \\(default\\)= . The actual limit will be further reduced dependent on the target\." \ "write-packet default" =20 gdb_test "set remote memory-write-packet-size" \ - "Argument required .integer, `fixed' or `limited'.\." \ + "Argument required .integer, \"fixed\" or \"limit\".\." \ "set write-packet - NULL" =20 -gdb_test_no_output "set remote memory-write-packet-size 20" +gdb_test "set remote memory-write-packet-size 20" \ + "The memory-write-packet-size on future remote targets is set to \"20\"." + gdb_test "show remote memory-write-packet-size" \ - "The memory-write-packet-size is 20. The actual limit will be further red= uced dependent on the target\." \ + "The memory-write-packet-size on future remote targets is 20. The actual = limit will be further reduced dependent on the target\." \ "set write-packet - small" =20 -gdb_test_no_output "set remote memory-write-packet-size 1" +gdb_test "set remote memory-write-packet-size 1" \ + "The memory-write-packet-size on future remote targets is set to \"1\"." + gdb_test "show remote memory-write-packet-size" \ - "The memory-write-packet-size is 1. The actual limit will be further redu= ced dependent on the target\." \ + "The memory-write-packet-size on future remote targets is 1. The actual l= imit will be further reduced dependent on the target\." \ "set write-packet - very-small" =20 -gdb_test_no_output "set remote memory-write-packet-size 0" +gdb_test "set remote memory-write-packet-size 0" \ + "The memory-write-packet-size on future remote targets is set to \"0\"." + gdb_test "show remote memory-write-packet-size" \ - "The memory-write-packet-size is 0 \\(default\\). The actual limit will b= e further reduced dependent on the target\." \ + "The memory-write-packet-size on future remote targets is 0 \\(default\\)= . The actual limit will be further reduced dependent on the target\." \ "write-packet default again" =20 set test "set remote memory-write-packet-size fixed" gdb_test_multiple $test $test { - -re "Change the packet size. .y or n. " { + -re "Change the packet size for future remote targets. .y or n. " { gdb_test_multiple "y" $test { -re "$gdb_prompt $" { pass $test @@ -71,13 +77,16 @@ gdb_test_multiple $test $test { } } } + gdb_test "show remote memory-write-packet-size" \ - "The memory-write-packet-size is 0 \\(default\\). Packets are fixed at 16= 384 bytes\." \ + "The memory-write-packet-size on future remote targets is 0 \\(default\\)= . Packets are fixed at 16384 bytes\." \ "write-packet default fixed" =20 -gdb_test_no_output "set remote memory-write-packet-size limit" +gdb_test "set remote memory-write-packet-size limit" \ + "The memory-write-packet-size on future remote targets is set to \"limit\= "." + gdb_test "show remote memory-write-packet-size" \ - "The memory-write-packet-size is 0 \\(default\\). The actual limit will b= e further reduced dependent on the target\." \ + "The memory-write-packet-size on future remote targets is 0 \\(default\\)= . The actual limit will be further reduced dependent on the target\." \ "write-packet default limit again" =20 # @@ -89,7 +98,8 @@ proc gdb_load_timed {executable class writesize} { set test "timed download `[file tail $executable]' - $class, $writesiz= e" =20 if {$writesize !=3D ""} { - gdb_test_no_output "set remote memory-write-packet-size $writesize" \ + gdb_test "set remote memory-write-packet-size $writesize" \ + "The memory-write-packet-size on future remote targets is set to \"$w= ritesize\"." \ "$test - set packet size" =20 send_gdb "set remote memory-write-packet-size $class\n" @@ -130,8 +140,6 @@ proc gdb_load_timed {executable class writesize} { pass $test } =20 -clean_restart $binfile - # These download tests won't actually download anything on !is_remote # target boards, but we run them anyway because it's simpler, and # harmless. @@ -156,6 +164,8 @@ gdb_load_timed $binfile "limit" 0 # Get the size of random_data table (defaults to 48K). set sizeof_random_data [get_sizeof "random_data" 48*1024] =20 +clean_restart $binfile + # # Part THREE: Check the upload behavour # @@ -179,10 +189,11 @@ if {$sizeof_random_data > 16380} { =20 # Read a chunk just larger than the packet size (reduce the packet # size to make life easier) -gdb_test_no_output "set remote memory-read-packet-size 16" +gdb_test "set remote memory-read-packet-size 16" \ + "The memory-read-packet-size on the current remote target is set to \"16\= "." =20 gdb_test "show remote memory-read-packet-size" \ - "The memory-read-packet-size is 16. Packets are limited to 20 bytes." + "The memory-read-packet-size on the current remote target is 16. Packets = are limited to 20 bytes." gdb_test "x/17ub random_data" \ ":\[ \t\]+60\[ \t\]+74\[ \t\]+216\[ \t\]+38\[ \t\]+149\[ \t\= ]+49\[ \t\]+207\[ \t\]+44.*:\[ \t\]+124\[ \t\]+38\[ \t\]+9= 3\[ \t\]+125\[ \t\]+232\[ \t\]+67\[ \t\]+228\[ \t\]+56.*:= \[ \t\]+161"