public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Hannes Domani <ssbssa@yahoo.de>,
	Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 25/28] Don't write to inferior_ptid in windows-nat.c, part II
Date: Wed, 15 Apr 2020 16:08:20 +0100	[thread overview]
Message-ID: <d413cf4d-ea7a-7c3c-a799-d02fcce126d3@redhat.com> (raw)
In-Reply-To: <1253231843.1175283.1586904073822@mail.yahoo.com>

On 4/14/20 11:41 PM, Hannes Domani via Gdb-patches wrote:

> The removal of these lines breaks debugging on Windows, right on startup I get:
> 
> (gdb) r
> Starting program: C:\qiewer\heob\heob64.exe
> C:/src/repos/binutils-gdb.git/gdb/thread.c:86: internal-error: thread_info* inferior_thread(): Assertion `tp' failed.
> 
> Full stacktrace of the assertion failure:
> 
> (gdb) bt
> #0  internal_error (file=0xa713a8 <selftests::test_target_info+168> "C:/src/repos/binutils-gdb.git/gdb/thread.c", line=86,
>     fmt=0xa71388 <selftests::test_target_info+136> "%s: Assertion `%s' failed.") at C:/src/repos/binutils-gdb.git/gdbsupport/errors.cc:51
> #1  0x000000000066cfd9 in inferior_thread () at C:/src/repos/binutils-gdb.git/gdb/thread.c:86
> #2  inferior_thread () at C:/src/repos/binutils-gdb.git/gdb/thread.c:83
> #3  0x00000000005603a0 in post_create_inferior (target=0x999ba0 <the_windows_nat_target>, from_tty=from_tty@entry=0)
>     at C:/src/repos/binutils-gdb.git/gdb/infcmd.c:444
> #4  0x0000000000563727 in run_command_1 (args=<optimized out>, from_tty=1, run_how=RUN_NORMAL) at C:/src/repos/binutils-gdb.git/gdb/infcmd.c:670

> Btw., I think this variable in get_windows_debug_event is no longer useful:
>   static windows_thread_info dummy_thread_info (0, 0, 0);
> 

Thanks for pointing that out.

> 
> This replacement works fine for me so far:

Does this instead work for you?  This adds a single
switch_to_thread at the end of the initialization.

From 00648f5a0bd7b8d85a2bdf49a2d8f71087826062 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 15 Apr 2020 15:52:32 +0100
Subject: [PATCH] Fix Windows

---
 gdb/windows-nat.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 78e7e31c67..dd15fa1fab 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -358,6 +358,8 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
   const char *thread_name (struct thread_info *) override;
 
   int get_windows_debug_event (int pid, struct target_waitstatus *ourstatus);
+
+  void do_initial_windows_stuff (DWORD pid, bool attaching);
 };
 
 static windows_nat_target the_windows_nat_target;
@@ -1508,8 +1510,6 @@ windows_nat_target::get_windows_debug_event (int pid,
 {
   BOOL debug_event;
   DWORD continue_status, event_code;
-  windows_thread_info *th;
-  static windows_thread_info dummy_thread_info (0, 0, 0);
   DWORD thread_id = 0;
 
   /* If there is a relevant pending stop, report it now.  See the
@@ -1522,7 +1522,7 @@ windows_nat_target::get_windows_debug_event (int pid,
       *ourstatus = stop->status;
 
       ptid_t ptid (current_event.dwProcessId, thread_id);
-      th = thread_rec (ptid, INVALIDATE_CONTEXT);
+      windows_thread_info *th = thread_rec (ptid, INVALIDATE_CONTEXT);
       th->reload_context = 1;
 
       return thread_id;
@@ -1537,7 +1537,6 @@ windows_nat_target::get_windows_debug_event (int pid,
 
   event_code = current_event.dwDebugEventCode;
   ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
-  th = NULL;
   have_saved_context = 0;
 
   switch (event_code)
@@ -1563,7 +1562,7 @@ windows_nat_target::get_windows_debug_event (int pid,
 	}
       /* Record the existence of this thread.  */
       thread_id = current_event.dwThreadId;
-      th = windows_add_thread
+      windows_add_thread
         (ptid_t (current_event.dwProcessId, current_event.dwThreadId, 0),
 	 current_event.u.CreateThread.hThread,
 	 current_event.u.CreateThread.lpThreadLocalBase,
@@ -1580,7 +1579,6 @@ windows_nat_target::get_windows_debug_event (int pid,
 				     current_event.dwThreadId, 0),
 			     current_event.u.ExitThread.dwExitCode,
 			     false /* main_thread_p */);
-      th = &dummy_thread_info;
       break;
 
     case CREATE_PROCESS_DEBUG_EVENT:
@@ -1594,7 +1592,7 @@ windows_nat_target::get_windows_debug_event (int pid,
 
       current_process_handle = current_event.u.CreateProcessInfo.hProcess;
       /* Add the main thread.  */
-      th = windows_add_thread
+      windows_add_thread
         (ptid_t (current_event.dwProcessId,
 		 current_event.dwThreadId, 0),
 	 current_event.u.CreateProcessInfo.hThread,
@@ -1731,7 +1729,7 @@ windows_nat_target::get_windows_debug_event (int pid,
 	  && windows_initialization_done)
 	{
 	  ptid_t ptid = ptid_t (current_event.dwProcessId, thread_id, 0);
-	  th = thread_rec (ptid, INVALIDATE_CONTEXT);
+	  windows_thread_info *th = thread_rec (ptid, INVALIDATE_CONTEXT);
 	  th->stopped_at_software_breakpoint = true;
 	}
       pending_stops.push_back ({thread_id, *ourstatus, current_event});
@@ -1944,8 +1942,8 @@ windows_add_all_dlls (void)
     }
 }
 
-static void
-do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
+void
+windows_nat_target::do_initial_windows_stuff (DWORD pid, bool attaching)
 {
   int i;
   struct inferior *inf;
@@ -1961,8 +1959,8 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
 #endif
   current_event.dwProcessId = pid;
   memset (&current_event, 0, sizeof (current_event));
-  if (!target_is_pushed (ops))
-    push_target (ops);
+  if (!target_is_pushed (this))
+    push_target (this);
   disable_breakpoints_in_shlibs ();
   windows_clear_solib ();
   clear_proceed_status (0);
@@ -1992,11 +1990,13 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
 
   windows_initialization_done = 0;
 
+  ptid_t last_ptid;
+
   while (1)
     {
       struct target_waitstatus status;
 
-      ops->wait (minus_one_ptid, &status, 0);
+      last_ptid = this->wait (minus_one_ptid, &status, 0);
 
       /* Note windows_wait returns TARGET_WAITKIND_SPURIOUS for thread
 	 events.  */
@@ -2004,9 +2004,11 @@ do_initial_windows_stuff (struct target_ops *ops, DWORD pid, int attaching)
 	  && status.kind != TARGET_WAITKIND_SPURIOUS)
 	break;
 
-      ops->resume (minus_one_ptid, 0, GDB_SIGNAL_0);
+      this->resume (minus_one_ptid, 0, GDB_SIGNAL_0);
     }
 
+  switch_to_thread (find_thread_ptid (this, last_ptid));
+
   /* Now that the inferior has been started and all DLLs have been mapped,
      we can iterate over all DLLs and load them in.
 
@@ -2138,7 +2140,7 @@ windows_nat_target::attach (const char *args, int from_tty)
     }
 #endif
 
-  do_initial_windows_stuff (this, pid, 1);
+  do_initial_windows_stuff (pid, 1);
   target_terminal::ours ();
 }
 
@@ -2978,9 +2980,8 @@ windows_nat_target::create_inferior (const char *exec_file,
   else
     saw_create = 0;
 
-  do_initial_windows_stuff (this, pi.dwProcessId, 0);
+  do_initial_windows_stuff (pi.dwProcessId, 0);
 
   /* windows_continue (DBG_CONTINUE, -1, 0); */
 }

-- 
2.14.5


  reply	other threads:[~2020-04-15 15:08 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14 17:54 [PATCH 00/28] Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR/25412) Pedro Alves
2020-04-14 17:54 ` [PATCH 01/28] Don't write to inferior_ptid in linux_get_siginfo_data Pedro Alves
2020-04-14 17:54 ` [PATCH 02/28] gcore, handle exited threads better Pedro Alves
2020-04-14 17:54 ` [PATCH 03/28] Refactor delete_program_space as a destructor Pedro Alves
2020-04-15 15:54   ` Simon Marchi
2020-04-16 14:47     ` Pedro Alves
2020-04-14 17:54 ` [PATCH 04/28] Don't write to inferior_ptid in gdbarch-selftests.c, mock address_space too Pedro Alves
2020-04-14 17:54 ` [PATCH 05/28] Don't write to inferior_ptid in inf-ptrace.c Pedro Alves
2020-04-14 17:54 ` [PATCH 06/28] Don't write to inferior_ptid in target.c Pedro Alves
2020-04-14 17:54 ` [PATCH 07/28] Don't write to inferior_ptid in infrun.c Pedro Alves
2020-04-14 17:54 ` [PATCH 08/28] Don't write to inferior_ptid in procfs.c Pedro Alves
2020-04-14 17:54 ` [PATCH 09/28] Don't write to inferior_ptid in tracefile-tfile.c Pedro Alves
2020-04-14 17:54 ` [PATCH 10/28] Don't write to inferior_ptid in tracectf.c Pedro Alves
2020-04-14 17:54 ` [PATCH 11/28] Don't write to inferior_ptid in remote.c Pedro Alves
2020-04-14 17:54 ` [PATCH 12/28] Don't write to inferior_ptid in remote-sim.c Pedro Alves
2020-04-14 17:54 ` [PATCH 13/28] Don't write to inferior_ptid in nto-procfs.c Pedro Alves
2020-04-14 17:54 ` [PATCH 14/28] Don't write to inferior_ptid in go32-nat.c Pedro Alves
2020-04-14 17:54 ` [PATCH 15/28] Don't write to inferior_ptid in gnu-nat.c Pedro Alves
2020-04-14 17:54 ` [PATCH 16/28] Don't write to inferior_ptid in darwin-nat.c Pedro Alves
2020-04-16  1:33   ` Simon Marchi
2020-04-16 19:23     ` Pedro Alves
2020-04-14 17:54 ` [PATCH 17/28] Don't write to inferior_ptid in corelow.c Pedro Alves
2020-04-14 17:54 ` [PATCH 18/28] Don't write to inferior_ptid in bsd-kvm.c Pedro Alves
2020-04-14 17:54 ` [PATCH 19/28] Don't write to inferior_ptid in btrace_fetch Pedro Alves
2020-04-15  4:52   ` Metzger, Markus T
2020-04-15 14:13     ` Pedro Alves
2020-04-15 15:17       ` Metzger, Markus T
2020-04-14 17:54 ` [PATCH 20/28] Don't write to inferior_ptid in bsd-kvm.c Pedro Alves
2020-04-14 17:54 ` [PATCH 21/28] Don't write to inferior_ptid in fork-child.c Pedro Alves
2020-04-14 17:54 ` [PATCH 22/28] Don't write to inferior_ptid in go32-nat.c Pedro Alves
2020-04-14 17:54 ` [PATCH 23/28] Don't write to inferior_ptid in remote-sim.c Pedro Alves
2020-04-16  0:53   ` Simon Marchi
2020-04-16 14:58     ` Pedro Alves
2020-04-14 17:54 ` [PATCH 24/28] Don't write to inferior_ptid in windows-nat.c, part I Pedro Alves
2020-04-14 17:54 ` [PATCH 25/28] Don't write to inferior_ptid in windows-nat.c, part II Pedro Alves
2020-04-14 22:41   ` Hannes Domani
2020-04-15 15:08     ` Pedro Alves [this message]
2020-04-15 15:32       ` Hannes Domani
2020-04-14 17:54 ` [PATCH 26/28] Don't write to inferior_ptid in ravenscar-thread.c Pedro Alves
2020-04-17 18:45   ` Tom Tromey
2020-06-18 20:00     ` Pedro Alves
2020-06-18 21:38       ` Tom Tromey
2020-04-14 17:54 ` [PATCH 27/28] Don't write to inferior_ptid in aix-thread.c Pedro Alves
2020-04-14 17:54 ` [PATCH 28/28] Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR/25412) Pedro Alves
2020-04-16 19:39   ` Simon Marchi
2020-04-16 20:12     ` Pedro Alves
2020-04-16 20:38       ` Simon Marchi
2020-04-17 10:29         ` Pedro Alves
2020-04-17 14:06           ` Simon Marchi
2020-04-17 16:46             ` Pedro Alves
2020-04-17 18:53   ` Tom Tromey
2020-06-18 19:59     ` Pedro Alves
2020-06-23 13:37   ` Andrew Burgess
2020-06-23 14:26     ` Pedro Alves
2020-06-23 15:38       ` [PATCH] Fix "maint selftest" regression, add struct, scoped_mock_context Pedro Alves
2020-06-23 16:34         ` Andrew Burgess
2020-06-23 17:58           ` Pedro Alves
2020-04-14 18:46 ` [PATCH 00/28] Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR/25412) Hannes Domani
2020-04-14 19:24   ` Pedro Alves
2020-04-15 15:04     ` Simon Marchi
2020-04-16 13:41       ` Pedro Alves
2020-04-15 14:46 ` Simon Marchi
2020-04-15 15:33   ` Pedro Alves
2020-04-15 15:42     ` Simon Marchi
2020-04-17 20:20 ` Tom Tromey
2020-06-18 20:00   ` Pedro Alves
2020-06-18 22:30 ` Pedro Alves
2020-07-07 23:16 ` John Baldwin
2020-07-07 23:53   ` Pedro Alves
2020-07-08  0:19     ` John Baldwin
2020-07-08  0:10   ` Multiprocess on FreeBSD John Baldwin
2020-07-08  0:34     ` John Baldwin

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=d413cf4d-ea7a-7c3c-a799-d02fcce126d3@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=ssbssa@yahoo.de \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).