Re: [PATCH 08/11] [C++/mingw] Simplify first chance exception handling

Pedro Alves
2015-11-02T21:09:53Z

On 11/02/2015 09:01 PM, Simon Marchi wrote:

> Does this change fix something initially related to C++?

Whoops, forgot to mention that in the commit log. Now updated.

From b2759c57612aa28d19b140a7edf5bac57982564b Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 30 Oct 2015 20:49:06 +0000
Subject: [PATCH] [C++/mingw] Simplify first chance exception handling

Building in C++ errors out with:

../../src/gdb/windows-nat.c: In function 'int get_windows_debug_event(target_ops*, int, target_waitstatus*)':
../../src/gdb/windows-nat.c:1503:13: warning: invalid conversion from 'int' to 'gdb_signal' [-fpermissive]
last_sig = 1;
^
../../src/gdb/windows-nat.c:1533:43: warning: invalid conversion from 'int' to 'gdb_signal' [-fpermissive]
windows_resume (ops, minus_one_ptid, 0, 1);
^
../../src/gdb/windows-nat.c:1228:1: warning: initializing argument 4 of 'void windows_resume(target_ops*, ptid_t, int, gdb_signal)' [-fpermissive]
windows_resume (struct target_ops *ops,
^

Looking at the code, I can't figure out why we treat first chance
exceptions any different here.

AFAICS, we set last_sig to 1, and then call windows_resume passing
signal==1, so the DBG_EXCEPTION_NOT_HANDLED code path in win32_resume
is taken:

~~~
if (sig != GDB_SIGNAL_0)
{
if (current_event.dwDebugEventCode != EXCEPTION_DEBUG_EVENT)
{
OUTMSG (("Cannot continue with signal %d here.\n", sig));
}
else if (sig == last_sig)
continue_status = DBG_EXCEPTION_NOT_HANDLED;
else
OUTMSG (("Can only continue with recieved signal %d.\n", last_sig));
}
~~~

Fix this by removing this special casing. gdbserver also goes
straight to continuing with DBG_EXCEPTION_NOT_HANDLED, AFAICS.

gdb/ChangeLog:
2015-11-01 Pedro Alves <palves@redhat.com>

* windows-nat.c (handle_exception): Return 0 for first chance
exceptions.
(get_windows_debug_event): Adjust.
---
gdb/windows-nat.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index cce10f8..a7132d6 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1124,7 +1124,7 @@ handle_exception (struct target_waitstatus *ourstatus)
default:
/* Treat unhandled first chance exceptions specially. */
if (current_event.u.Exception.dwFirstChance)
- return -1;
+ return 0;
printf_unfiltered ("gdb: unknown target exception 0x%08x at %s\n",
(unsigned) current_event.u.Exception.ExceptionRecord.ExceptionCode,
host_address_to_string (
@@ -1491,19 +1491,10 @@ get_windows_debug_event (struct target_ops *ops,
"EXCEPTION_DEBUG_EVENT"));
if (saw_create != 1)
break;
- switch (handle_exception (ourstatus))
- {
- case 0:
- continue_status = DBG_EXCEPTION_NOT_HANDLED;
- break;
- case 1:
- thread_id = current_event.dwThreadId;
- break;
- case -1:
- last_sig = 1;
- continue_status = -1;
- break;
- }
+ if (handle_exception (ourstatus))
+ thread_id = current_event.dwThreadId;
+ else
+ continue_status = DBG_EXCEPTION_NOT_HANDLED;
break;

case OUTPUT_DEBUG_STRING_EVENT: /* Message from the kernel. */
@@ -1529,10 +1520,7 @@ get_windows_debug_event (struct target_ops *ops,

if (!thread_id || saw_create != 1)
{
- if (continue_status == -1)
- windows_resume (ops, minus_one_ptid, 0, 1);
- else
- CHECK (windows_continue (continue_status, -1, 0));
+ CHECK (windows_continue (continue_status, -1, 0));
}
else
{
--
1.9.3