From: Hannes Domani <ssbssa@yahoo.de>
To: Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 25/28] Don't write to inferior_ptid in windows-nat.c, part II
Date: Tue, 14 Apr 2020 22:41:13 +0000 (UTC) [thread overview]
Message-ID: <1253231843.1175283.1586904073822@mail.yahoo.com> (raw)
In-Reply-To: <20200414175434.8047-26-palves@redhat.com>
I did my tests now, thanks for your git branch.
Am Dienstag, 14. April 2020, 19:55:30 MESZ hat Pedro Alves via Gdb-patches <gdb-patches@sourceware.org> Folgendes geschrieben:
> Writing to inferior_ptid in
> windows_nat_target::get_windows_debug_event is just incorrect and not
> necessary. We'll report the event to GDB's core, which then takes
> care of switching inferior_ptid / current thread.
>
> Related (see windows_nat_target::get_windows_debug_event), there's
> also a "current_windows_thread" global that is just begging to get out
> of sync with core GDB's current thread. This patch removes it.
> gdbserver already does not have an equivalent global in win32-low.cc.
>
> gdb/ChangeLog:
> yyyy-mm-dd Pedro Alves <palves@redhat.com>
>
> * nat/windows-nat.c (current_windows_thread): Remove.
> * nat/windows-nat.h (current_windows_thread): Remove.
> * windows-nat.c (windows_nat_target::stopped_by_sw_breakpoint):
> Adjust.
> (display_selectors): Adjust to fetch the current
> windows_thread_info based on inferior_ptid.
> (fake_create_process): No longer write to current_windows_thread.
> (windows_nat_target::get_windows_debug_event):
> Don't set inferior_ptid or current_windows_thread.
> (windows_nat_target::wait): Adjust to not rely on
> current_windows_thread.
> (windows_nat_target::detach): Use switch_to_no_thread instead of
> writing to inferior_ptid directly.
> ---
> gdb/nat/windows-nat.c | 1 -
> gdb/nat/windows-nat.h | 3 ---
> gdb/windows-nat.c | 62 ++++++++++++++++++++++++++-------------------------
> 3 files changed, 32 insertions(+), 34 deletions(-)
>
> diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c
> index cd7c1d177c..a382b9edb9 100644
> --- a/gdb/nat/windows-nat.c
> +++ b/gdb/nat/windows-nat.c
> @@ -36,7 +36,6 @@ DEBUG_EVENT current_event;
> ContinueDebugEvent. */
> static DEBUG_EVENT last_wait_event;
>
> -windows_thread_info *current_windows_thread;
> DWORD desired_stop_thread_id = -1;
> std::vector<pending_stop> pending_stops;
> EXCEPTION_RECORD siginfo_er;
> diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
> index aea1519672..dc27827d9c 100644
> --- a/gdb/nat/windows-nat.h
> +++ b/gdb/nat/windows-nat.h
> @@ -168,9 +168,6 @@ extern enum gdb_signal last_sig;
> stop. */
> extern DEBUG_EVENT current_event;
>
> -/* Info on currently selected thread */
> -extern windows_thread_info *current_windows_thread;
> -
> /* The ID of the thread for which we anticipate a stop event.
> Normally this is -1, meaning we'll accept an event in any
> thread. */
> diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
> index 1bbebf00b9..78e7e31c67 100644
> --- a/gdb/windows-nat.c
> +++ b/gdb/windows-nat.c
> @@ -317,7 +317,9 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
>
> bool stopped_by_sw_breakpoint () override
> {
> - return current_windows_thread->stopped_at_software_breakpoint;
> + windows_thread_info *th
> + = thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT);
> + return th->stopped_at_software_breakpoint;
> }
>
> bool supports_stopped_by_sw_breakpoint () override
> @@ -1125,11 +1127,15 @@ display_selector (HANDLE thread, DWORD sel)
> static void
> display_selectors (const char * args, int from_tty)
> {
> - if (!current_windows_thread)
> + if (inferior_ptid == null_ptid)
> {
> puts_filtered ("Impossible to display selectors now.\n");
> return;
> }
> +
> + windows_thread_info *current_windows_thread
> + = thread_rec (inferior_ptid, DONT_INVALIDATE_CONTEXT);
> +
> if (!args)
> {
> #ifdef __x86_64__
> @@ -1338,12 +1344,11 @@ fake_create_process (void)
> (unsigned) GetLastError ());
> /* We can not debug anything in that case. */
> }
> - current_windows_thread
> - = windows_add_thread (ptid_t (current_event.dwProcessId,
> - current_event.dwThreadId, 0),
> - current_event.u.CreateThread.hThread,
> - current_event.u.CreateThread.lpThreadLocalBase,
> - true /* main_thread_p */);
> + windows_add_thread (ptid_t (current_event.dwProcessId, 0,
> + current_event.dwThreadId),
> + current_event.u.CreateThread.hThread,
> + current_event.u.CreateThread.lpThreadLocalBase,
> + true /* main_thread_p */);
> return current_event.dwThreadId;
> }
>
> @@ -1516,10 +1521,9 @@ windows_nat_target::get_windows_debug_event (int pid,
> thread_id = stop->thread_id;
> *ourstatus = stop->status;
>
> - inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0);
> - current_windows_thread = thread_rec (inferior_ptid,
> - INVALIDATE_CONTEXT);
> - current_windows_thread->reload_context = 1;
> + ptid_t ptid (current_event.dwProcessId, thread_id);
> + th = thread_rec (ptid, INVALIDATE_CONTEXT);
> + th->reload_context = 1;
>
> return thread_id;
> }
> @@ -1734,14 +1738,6 @@ windows_nat_target::get_windows_debug_event (int pid,
> thread_id = 0;
> CHECK (windows_continue (continue_status, desired_stop_thread_id, 0));
> }
> - else
> - {
> - inferior_ptid = ptid_t (current_event.dwProcessId, thread_id, 0);
> - current_windows_thread = th;
> - if (!current_windows_thread)
> - current_windows_thread = thread_rec (inferior_ptid,
> - INVALIDATE_CONTEXT);
> - }
>
> out:
> return thread_id;
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
#5 0x00000000004810c2 in cmd_func (cmd=0xa713a8 <selftests::test_target_info+168>, args=0x56 <error: Cannot access memory at address 0x56>,
from_tty=10949512) at C:/src/repos/binutils-gdb.git/gdb/cli/cli-decode.c:1952
#6 0x00000000006735a8 in execute_command (p=<optimized out>, p@entry=0x13bae0 "", from_tty=1) at C:/src/repos/binutils-gdb.git/gdb/top.c:655
#7 0x00000000005153f4 in command_handler (command=0x13bae0 "") at C:/src/repos/binutils-gdb.git/gdb/event-top.c:588
#8 0x00000000005162a2 in command_line_handler (rl=...) at C:/src/repos/binutils-gdb.git/gdb/event-top.c:773
#9 0x0000000000515bd3 in gdb_rl_callback_handler (rl=0x13b4c0 "r") at c:/msys64/mingw64/x86_64-w64-mingw32/include/c++/9.3.0/bits/unique_ptr.h:153
#10 0x00000000006e4eec in rl_callback_read_char () at C:/src/repos/binutils-gdb.git/readline/readline/callback.c:281
#11 0x0000000000514f4e in gdb_rl_callback_read_char_wrapper_noexcept () at C:/src/repos/binutils-gdb.git/gdb/event-top.c:177
#12 0x0000000000515a84 in gdb_rl_callback_read_char_wrapper (client_data=<optimized out>) at C:/src/repos/binutils-gdb.git/gdb/event-top.c:193
#13 0x0000000000514d92 in stdin_event_handler (error=<optimized out>, client_data=0x13b720) at C:/src/repos/binutils-gdb.git/gdb/event-top.c:516
#14 0x00000000007a91e0 in handle_file_event (ready_mask=2, file_ptr=0x1e93c0) at C:/src/repos/binutils-gdb.git/gdbsupport/event-loop.cc:548
#15 gdb_wait_for_event (block=<optimized out>) at C:/src/repos/binutils-gdb.git/gdbsupport/event-loop.cc:698
#16 gdb_wait_for_event (block=<optimized out>) at C:/src/repos/binutils-gdb.git/gdbsupport/event-loop.cc:561
#17 0x00000000007a9318 in gdb_do_one_event () at C:/src/repos/binutils-gdb.git/gdbsupport/event-loop.cc:215
#18 0x0000000000592c4d in start_event_loop () at C:/src/repos/binutils-gdb.git/gdb/main.c:356
#19 captured_command_loop () at C:/src/repos/binutils-gdb.git/gdb/main.c:416
#20 0x0000000000594b55 in captured_main (data=0xfd4fdc0) at C:/src/repos/binutils-gdb.git/gdb/main.c:1254
#21 gdb_main (args=args@entry=0xfd4fe20) at C:/src/repos/binutils-gdb.git/gdb/main.c:1269
#22 0x000000000098a757 in main (argc=3, argv=0x1048a0) at C:/src/repos/binutils-gdb.git/gdb/gdb.c:32
(gdb) up
#1 0x000000000066cfd9 in inferior_thread () at C:/src/repos/binutils-gdb.git/gdb/thread.c:86
86 gdb_assert (tp);
(gdb) l
81
82 struct thread_info*
83 inferior_thread (void)
84 {
85 struct thread_info *tp = find_thread_ptid (current_inferior (), inferior_ptid);
86 gdb_assert (tp);
87 return tp;
88 }
89
90 /* Delete the breakpoint pointed at by BP_P, if there's one. */
This replacement works fine for me so far:
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 78e7e31c67..b22df182a1 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1738,6 +1738,12 @@ windows_nat_target::get_windows_debug_event (int pid,
thread_id = 0;
CHECK (windows_continue (continue_status, desired_stop_thread_id, 0));
}
+ else
+ {
+ if (th != nullptr)
+ switch_to_thread (&the_windows_nat_target,
+ ptid_t (current_event.dwProcessId, thread_id, 0));
+ }
out:
return thread_id;
Btw., I think this variable in get_windows_debug_event is no longer useful:
static windows_thread_info dummy_thread_info (0, 0, 0);
Hannes
next prev parent reply other threads:[~2020-04-14 22:41 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 [this message]
2020-04-15 15:08 ` Pedro Alves
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=1253231843.1175283.1586904073822@mail.yahoo.com \
--to=ssbssa@yahoo.de \
--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