From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30107 invoked by alias); 23 Jan 2012 19:57:47 -0000 Received: (qmail 30075 invoked by uid 22791); 23 Jan 2012 19:57:45 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Jan 2012 19:57:31 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0NJvSdt015335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 23 Jan 2012 14:57:28 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q0NJvRjm030608; Mon, 23 Jan 2012 14:57:28 -0500 Message-ID: <4F1DBBA7.2060507@redhat.com> Date: Mon, 23 Jan 2012 20:27:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: GDB Patches CC: Ulrich Weigand Subject: Distinguish target and "fake" PID values in extended-remote's "run", and when connecting in non-stop mode too. Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-01/txt/msg00792.txt.bz2 At , Pedro Alves wrote: > I remembered that extended_remote_create_inferior_1 (for "run") > will need the same treatment. It's no biggie, since we'll be using > multiprocess extensions in gdbserver. I'll fix it, but don't let > this block you (unless you want to fix it yourself). Here's the promised fix. Non-stop's thread/inferior discovery on connection also needed to be handled. I've made sure "info proc" would complain when the multiprocess extensions were off, with extended-remote/run, and also with plain remote + non-stop, and would operate on the currect process otherwise. I've ran the testsuite against local gdbserver, and no regressions showed up. I also ran the testsuite with multiprocess extensions off, and the only regressions were caused by core file generation no longer working, which was expected. I've simplified the code that was previously put in a bit while factoring it out to the new add_current_inferior_and_thread function, avoiding the ptid_build ugliness. Comments? gdb/ 2012-01-23 Pedro Alves * remote.c (remote_add_inferior): New `fake_pid_p' parameter. Use it. (remote_notice_new_inferior): If the remote end doesn't support the multiprocess extensions, then the PID is fake. (add_current_inferior_and_thread): New. (remote_start_remote): Use it. (extended_remote_attach_1): Adjust. (extended_remote_create_inferior_1): Use add_current_inferior_and_thread. --- gdb/remote.c | 111 +++++++++++++++++++++++++++++++--------------------------- 1 files changed, 59 insertions(+), 52 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index f348536..1277641 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1440,16 +1440,17 @@ remote_query_attached (int pid) return 0; } -/* Add PID to GDB's inferior table. Since we can be connected to a - remote system before before knowing about any inferior, mark the - target with execution when we find the first inferior. If ATTACHED - is 1, then we had just attached to this inferior. If it is 0, then - we just created this inferior. If it is -1, then try querying the - remote stub to find out if it had attached to the inferior or - not. */ +/* Add PID to GDB's inferior table. If FAKE_PID_P is true, then PID + has been invented by GDB, instead of reported by the target. Since + we can be connected to a remote system before before knowing about + any inferior, mark the target with execution when we find the first + inferior. If ATTACHED is 1, then we had just attached to this + inferior. If it is 0, then we just created this inferior. If it + is -1, then try querying the remote stub to find out if it had + attached to the inferior or not. */ static struct inferior * -remote_add_inferior (int pid, int attached) +remote_add_inferior (int fake_pid_p, int pid, int attached) { struct inferior *inf; @@ -1481,6 +1482,7 @@ remote_add_inferior (int pid, int attached) } inf->attach_flag = attached; + inf->fake_pid_p = fake_pid_p; return inf; } @@ -1556,7 +1558,13 @@ remote_notice_new_inferior (ptid_t currthread, int running) may not know about it yet. Add it before adding its child thread, so notifications are emitted in a sensible order. */ if (!in_inferior_list (ptid_get_pid (currthread))) - inf = remote_add_inferior (ptid_get_pid (currthread), -1); + { + struct remote_state *rs = get_remote_state (); + int fake_pid_p = !remote_multi_process_p (rs); + + inf = remote_add_inferior (fake_pid_p, + ptid_get_pid (currthread), -1); + } /* This is really a new thread. Add it. */ remote_add_thread (currthread, running); @@ -3150,6 +3158,45 @@ send_interrupt_sequence (void) interrupt_sequence_mode); } +/* Query the remote target for which is the current thread/process, + add it to our tables, and update INFERIOR_PTID. The caller is + responsible for setting the state such that the remote end is ready + to return the current thread. */ + +static void +add_current_inferior_and_thread (void) +{ + struct remote_state *rs = get_remote_state (); + int fake_pid_p = 0; + ptid_t ptid; + + inferior_ptid = null_ptid; + + /* Now, if we have thread information, update inferior_ptid. */ + ptid = remote_current_thread (inferior_ptid); + if (!ptid_equal (ptid, null_ptid)) + { + if (!remote_multi_process_p (rs)) + fake_pid_p = 1; + + inferior_ptid = ptid; + } + else + { + /* Without this, some commands which require an active target + (such as kill) won't work. This variable serves (at least) + double duty as both the pid of the target process (if it has + such), and as a flag indicating that a target is active. */ + inferior_ptid = magic_null_ptid; + fake_pid_p = 1; + } + + remote_add_inferior (fake_pid_p, ptid_get_pid (inferior_ptid), -1); + + /* Add the main thread. */ + add_thread_silent (inferior_ptid); +} + static void remote_start_remote (int from_tty, struct target_ops *target, int extended_p) { @@ -3277,40 +3324,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p) /* Let the stub know that we want it to return the thread. */ set_continue_thread (minus_one_ptid); - inferior_ptid = minus_one_ptid; - - /* Now, if we have thread information, update inferior_ptid. */ - ptid = remote_current_thread (inferior_ptid); - if (!ptid_equal (ptid, minus_one_ptid)) - { - if (ptid_get_pid (ptid) == -1) - { - ptid = ptid_build (ptid_get_pid (magic_null_ptid), - ptid_get_lwp (ptid), - ptid_get_tid (ptid)); - fake_pid_p = 1; - } - - inferior_ptid = ptid; - } - else - { - /* Without this, some commands which require an active - target (such as kill) won't work. This variable serves - (at least) double duty as both the pid of the target - process (if it has such), and as a flag indicating that a - target is active. These functions should be split out - into seperate variables, especially since GDB will - someday have a notion of debugging several processes. */ - inferior_ptid = magic_null_ptid; - fake_pid_p = 1; - } - - inf = remote_add_inferior (ptid_get_pid (inferior_ptid), -1); - inf->fake_pid_p = fake_pid_p; - - /* Always add the main thread. */ - add_thread_silent (inferior_ptid); + add_current_inferior_and_thread (); /* init_wait_for_inferior should be called before get_offsets in order to manage `inserted' flag in bp loc in a correct state. @@ -4300,7 +4314,7 @@ extended_remote_attach_1 (struct target_ops *target, char *args, int from_tty) error (_("Attaching to %s failed"), target_pid_to_str (pid_to_ptid (pid))); - set_current_inferior (remote_add_inferior (pid, 1)); + set_current_inferior (remote_add_inferior (0, pid, 1)); inferior_ptid = pid_to_ptid (pid); @@ -7674,14 +7688,7 @@ extended_remote_create_inferior_1 (char *exec_file, char *args, init_wait_for_inferior (); } - /* Now mark the inferior as running before we do anything else. */ - inferior_ptid = magic_null_ptid; - - /* Now, if we have thread information, update inferior_ptid. */ - inferior_ptid = remote_current_thread (inferior_ptid); - - remote_add_inferior (ptid_get_pid (inferior_ptid), 0); - add_thread_silent (inferior_ptid); + add_current_inferior_and_thread (); /* Get updated offsets, if the stub uses qOffsets. */ get_offsets ();