From: Xavier Roirand <roirand@adacore.com>
To: gdb-patches@sourceware.org
Cc: brobecker@adacore.com, Xavier Roirand <roirand@adacore.com>
Subject: [RFA 4/5] Darwin: fix thread ptid started by fork_inferior
Date: Wed, 22 Aug 2018 10:11:00 -0000 [thread overview]
Message-ID: <1534932677-9496-5-git-send-email-roirand@adacore.com> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2018-08-22 10:11 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-22 10:11 [RFA 0/5] Fix some bugs on macOS Xavier Roirand
2018-08-22 10:11 ` [RFA 1/5] Darwin: fix bad loop incrementation Xavier Roirand
2018-08-22 13:14 ` Simon Marchi
2018-08-23 15:21 ` Simon Marchi
2018-08-22 10:11 ` [RFA 3/5] Darwin: set startup-with-shell to off on Sierra and later Xavier Roirand
2018-08-22 14:20 ` Simon Marchi
2018-08-22 14:37 ` Pedro Alves
2018-09-03 13:23 ` Xavier Roirand
2018-09-17 19:31 ` Tom Tromey
2018-08-22 10:11 ` [RFA 5/5] Darwin: fix SIGTRAP when debugging Xavier Roirand
2018-08-22 14:34 ` Simon Marchi
2018-08-22 10:11 ` Xavier Roirand [this message]
2018-08-22 14:30 ` [RFA 4/5] Darwin: fix thread ptid started by fork_inferior Simon Marchi
2018-08-22 16:10 ` Pedro Alves
2018-08-22 18:14 ` Simon Marchi
2018-08-22 10:11 ` [RFA 2/5] Darwin: Handle unrelocated dyld Xavier Roirand
2018-08-22 13:55 ` Simon Marchi
2018-09-18 21:22 ` Tom Tromey
2018-09-19 13:41 ` Joel Brobecker
2018-09-19 14:16 ` Simon Marchi
2018-09-19 14:28 ` Joel Brobecker
2018-09-19 14:36 ` Tom Tromey
2018-09-19 14:44 ` Simon Marchi
2018-09-19 15:32 ` Joel Brobecker
2018-09-19 19:15 ` Tom Tromey
2018-09-19 19:50 ` Simon Marchi
2018-09-28 13:31 ` Xavier Roirand
2018-09-28 17:22 ` Tom Tromey
2018-08-22 13:59 ` Simon Marchi
2018-09-18 21:23 ` Tom Tromey
2018-09-17 20:57 ` [RFA 0/5] Fix some bugs on macOS Tom Tromey
2018-09-17 21:25 ` Joel Brobecker
2018-09-17 23:03 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1534932677-9496-5-git-send-email-roirand@adacore.com \
--to=roirand@adacore.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox