From: Hannes Domani <ssbssa@yahoo.de>
To: Hannes Domani via Gdb-patches <gdb-patches@sourceware.org>,
Tom Tromey <tom@tromey.com>, Simon Marchi <simark@simark.ca>
Subject: Re: [PATCH] Fix ctrl-c when debugging WOW64 processes
Date: Fri, 18 Sep 2020 14:27:20 +0000 (UTC) [thread overview]
Message-ID: <725154490.1784012.1600439240290@mail.yahoo.com> (raw)
In-Reply-To: <334596674.1355343.1600376198632@mail.yahoo.com>
Am Donnerstag, 17. September 2020, 22:56:45 MESZ hat Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> Folgendes geschrieben:
> Am Donnerstag, 17. September 2020, 22:18:01 MESZ hat Tom Tromey <tom@tromey.com> Folgendes geschrieben:
>
> > >>>>> "Hannes" == Hannes Domani via Gdb-patches <gdb-patches@sourceware.org> writes:
> >
> > Hannes> 2020-09-17 Hannes Domani <ssbssa@yahoo.de>
> >
> > Hannes> * windows-nat.c (ctrl_c_handler): Use 32bit DbgUiRemoteBreakin
> > Hannes> for WOW64 processes.
> >
> > Does gdbserver need this treatment as well?
> > If so maybe this code can be shared.
>
> I thought so, but I just tried it and it works without it.
>
> The reason seems to be that gdbserver first calls GenerateConsoleCtrlEvent(),
> and only when that fails falls back to DebugBreakProcess().
>
> When I tried to do the same in gdb just now, it didn't work.
> Weird, I will have to investigate this some more.
I did some experiments.
Seems like GenerateConsoleCtrlEvent() only works if the target process was
created without CREATE_NEW_CONSOLE.
And what's worse, it seems to always return TRUE, so it never reaches
DebugBreakProcess(), even if the target process doesn't have a console at all.
I also tried the "last resort", with soft_interrupt_requested=1, but this
immediatly crashed gdbserver.
I fixed this crash with:
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -1339,6 +1335,7 @@ fake_breakpoint_event (void)
faked_breakpoint = 1;
memset (¤t_event, 0, sizeof (current_event));
+ current_event.dwProcessId = current_process_id;
current_event.dwThreadId = main_thread_id;
current_event.dwDebugEventCode = EXCEPTION_DEBUG_EVENT;
current_event.u.Exception.ExceptionRecord.ExceptionCode
But this didn't work either, I think it's because gdb checks if the current
instruction is int3, and continues if not.
I'm wondering why this last resort was added, was this done for pre-XP where
DebugBreakProcess() didn't exist?
So right now ctrl-c doesn't really work that well with gdbserver, and not
at all when debugging a program without console (WOW64 or not doesn't matter).
And the WOW64 fix for DbgUiRemoteBreakin() probably can't be used in
gdbserver, because find_minimal_symbol_address() is not available.
Meanwhile I came up with a possible alternative for DbgUiRemoteBreakin():
--- a/gdb/nat/windows-nat.c
+++ b/gdb/nat/windows-nat.c
@@ -240,6 +241,13 @@ handle_exception (struct target_waitstatus *ourstatus, bool debug_exceptions)
case EXCEPTION_BREAKPOINT:
#ifdef __x86_64__
if (ignore_first_breakpoint)
{
/* For WOW64 processes, there are always 2 breakpoint exceptions
on startup, first a BREAKPOINT for the 64bit ntdll.dll,
then a WX86_BREAKPOINT for the 32bit ntdll.dll.
Here we only care about the WX86_BREAKPOINT's. */
ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
ignore_first_breakpoint = false;
}
+ else if (wow64_process)
+ {
+ DEBUG_EXCEPTION_SIMPLE ("EXCEPTION_BREAKPOINT");
+ rec->ExceptionCode = DBG_CONTROL_C;
+ ourstatus->value.sig = GDB_SIGNAL_INT;
+ break;
+ }
#endif
/* FALLTHROUGH */
case STATUS_WX86_BREAKPOINT:
This transforms the (64bit) breakpoint from DebugBreakProcess() into
SIGINT, then the check for the int3 instruction is not done, and gdb stops
the target process in any case.
So far this seems to work fine for both gdb and gdbserver.
Hannes
next prev parent reply other threads:[~2020-09-18 14:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200917180337.1984-1-ssbssa.ref@yahoo.de>
2020-09-17 18:03 ` Hannes Domani
2020-09-17 20:00 ` Simon Marchi
2020-09-17 20:23 ` Hannes Domani
2020-09-17 20:17 ` Tom Tromey
2020-09-17 20:56 ` Hannes Domani
2020-09-18 14:27 ` Hannes Domani [this message]
2020-09-18 15:48 ` Simon Marchi
2020-09-18 16:09 ` Hannes Domani
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=725154490.1784012.1600439240290@mail.yahoo.com \
--to=ssbssa@yahoo.de \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--cc=tom@tromey.com \
/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