This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 4/5] Darwin: fix thread ptid started by fork_inferior
- From: Xavier Roirand <roirand at adacore dot com>
- To: gdb-patches at sourceware dot org
- Cc: brobecker at adacore dot com, Xavier Roirand <roirand at adacore dot com>
- Date: Wed, 22 Aug 2018 12:11:16 +0200
- Subject: [RFA 4/5] Darwin: fix thread ptid started by fork_inferior
- References: <1534932677-9496-1-git-send-email-roirand@adacore.com>
When debugging a program on Mac OS X Darwin, gdb stops with:
Temporary breakpoint 1 at 0x100000fb4: file /tmp/helloworld.c, line 1.
Starting program: /private/tmp/helloworld
[New Thread 0xb03 of process 65066]
[New Thread 0xd03 of process 65066]
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.
When the inferior is started a thread with lwp=tid=0 is created
and has to be fixed later by darwin_init_thread_list(). Because
this is not done, GDB does not understand that the SIGTRAP is
coming from GDB and not the program itself.
gdb/ChangeLog:
* darwin-nat.c (darwin_check_new_threads): Check if first
silent thread case.
(darwin_init_thread_list): Fixup thread ptid.
(darwin_ptrace_him): Add call.
(darwin_nat_target::attach): Add call.
Change-Id: Ie8ad7edfff167a1f95140907c75af45ceb3fae14
---
gdb/darwin-nat.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 96f70cf..9ad4a87 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -344,8 +344,22 @@ darwin_check_new_threads (struct inferior *inf)
pti->gdb_port = new_id;
pti->msg_state = DARWIN_RUNNING;
- /* Add the new thread. */
- add_thread_with_info (ptid_t (inf->pid, 0, new_id), pti);
+ if (old_nbr == 0 && new_ix == 0)
+ {
+ /* A ptid is created when the inferior is started (see
+ fork-child.c) with lwp=tid=0. This ptid will be renamed
+ later by darwin_init_thread_list (), so find this previous
+ thread silently added. */
+
+ struct thread_info *tp = find_thread_ptid (ptid_t (inf->pid, 0, 0));
+ tp->priv.reset (pti);
+ }
+ else
+ {
+ /* Add the new thread. */
+ add_thread_with_info (ptid_t (inf->pid, 0, new_id), pti);
+ }
+
new_thread_vec.push_back (pti);
new_ix++;
continue;
@@ -1733,6 +1747,8 @@ thread_info_from_private_thread_info (darwin_thread_info *pti)
static void
darwin_init_thread_list (struct inferior *inf)
{
+ ptid_t new_ptid;
+
darwin_check_new_threads (inf);
darwin_inferior *priv = get_darwin_inferior (inf);
@@ -1743,7 +1759,11 @@ darwin_init_thread_list (struct inferior *inf)
struct thread_info *first_thread
= thread_info_from_private_thread_info (first_pti);
- inferior_ptid = first_thread->ptid;
+ /* Note: fork_inferior automatically add a thread but it uses a wrong ptid.
+ Fix up. */
+ new_ptid = ptid_t (inf->pid, 0, first_pti->gdb_port);
+ thread_change_ptid (inferior_ptid, new_ptid);
+ inferior_ptid = new_ptid;
}
/* The child must synchronize with gdb: gdb must set the exception port
@@ -1806,6 +1826,9 @@ darwin_ptrace_him (int pid)
int traps_expected;
struct inferior *inf = current_inferior ();
+ inferior_ptid = ptid_t (pid);
+ add_thread_silent (inferior_ptid);
+
darwin_attach_pid (inf);
/* Let's the child run. */
@@ -1933,6 +1956,8 @@ darwin_nat_target::attach (const char *args, int from_tty)
inferior_appeared (inf, pid);
inf->attach_flag = 1;
+ add_thread_silent (inferior_ptid);
+
darwin_attach_pid (inf);
darwin_suspend_inferior (inf);
--
2.7.4