From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 021D1385782C; Wed, 4 May 2022 12:25:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 021D1385782C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/remote: send qSymbol to all inferiors on startup X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 06c7226ea19c1880fc160b8890c3a5574d490709 X-Git-Newrev: 901e4e8d5c4f1d32c50e4a31b228bc7ef4210775 Message-Id: <20220504122516.021D1385782C@sourceware.org> Date: Wed, 4 May 2022 12:25:16 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2022 12:25:16 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D901e4e8d5c4f= 1d32c50e4a31b228bc7ef4210775 commit 901e4e8d5c4f1d32c50e4a31b228bc7ef4210775 Author: Simon Marchi Date: Fri Apr 29 23:21:15 2022 -0400 gdb/remote: send qSymbol to all inferiors on startup =20 start_remote_1 calls remote_check_symbols after things are set up to give the remote side a chance to look up symbols. One call to remote_check_symbols sets the "general thread", if needed, and sends one qSymbol packet. However, a remote target could have more than one process on initial connection, and this would send a qSymbol for only one of these processes. =20 Change it to iterate on all the target's inferiors and send a qSymbol packet for each one. =20 I tested this by changing gdbserver to spawn two processes on startup: =20 diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 33c42714e72..9b682e9f85f 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3939,6 +3939,7 @@ captured_main (int argc, char *argv[]) =20 /* Wait till we are at first instruction in program. */ target_create_inferior (program_path.get (), program_args); + target_create_inferior (program_path.get (), program_args); =20 /* We are now (hopefully) stopped at the first instruction of the target process. This assumes that the target process = was =20 Instead of hacking GDBserver, it should also be possible to test this by starting manually two inferiors on an "extended-remote" connection, disconnecting from GDBserver (with the disconnect command), and re-connecting. =20 I was able to see qSymbol being sent for each inferior: =20 [remote] Sending packet: $Hgp828dc.828dc#1f [remote] Packet received: OK [remote] Sending packet: $qSymbol::#5b [remote] Packet received: qSymbol:6764625f6167656e745f6764625f747= 05f686561705f627566666572 [remote] Sending packet: $qSymbol::6764625f6167656e745f6764625f74= 705f686561705f627566666572#1e [remote] Packet received: qSymbol:6e70746c5f76657273696f6e [remote] Sending packet: $qSymbol::6e70746c5f76657273696f6e#4d [remote] Packet received: OK [remote] Sending packet: $Hgp828dd.828dd#21 [remote] Packet received: OK [remote] Sending packet: $qSymbol::#5b [remote] Packet received: qSymbol:6764625f6167656e745f6764625f747= 05f686561705f627566666572 [remote] Sending packet: $qSymbol::6764625f6167656e745f6764625f74= 705f686561705f627566666572#1e [remote] Packet received: qSymbol:6e70746c5f76657273696f6e [remote] Sending packet: $qSymbol::6e70746c5f76657273696f6e#4d [remote] Packet received: OK =20 Note that there would probably be more work to be done to fully support this scenario, more things that need to be done for each discovered inferior instead of just for one. =20 Change-Id: I21c4ecf6367391e2e389b560f0b4bd906cf6472f Diff: --- gdb/remote.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index fde6df3f84d..b8df3326849 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5021,12 +5021,24 @@ remote_target::start_remote_1 (int from_tty, int ex= tended_p) target_async (1); } =20 - /* If we connected to a live target, do some additional setup. */ - if (target_has_execution ()) + /* Give the target a chance to look up symbols. */ + for (inferior *inf : all_inferiors (this)) { + /* The inferiors that exist at this point were created from what + was found already running on the remote side, so we know they + have execution. */ + gdb_assert (this->has_execution (inf)); + /* No use without a symbol-file. */ - if (current_program_space->symfile_object_file) - remote_check_symbols (); + if (inf->pspace->symfile_object_file =3D=3D nullptr) + continue; + + /* Need to switch to a specific thread, because remote_check_symbols + uses INFERIOR_PTID to set the general thread. */ + scoped_restore_current_thread restore_thread; + thread_info *thread =3D any_thread_of_inferior (inf); + switch_to_thread (thread); + this->remote_check_symbols (); } =20 /* Possibly the target has been engaged in a trace run started