mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-05 15:15:42 +00:00
Introduce gdb_exception_forced_quit
This commit adds a new exception 'gdb_exception_forced_quit', reason code 'REASON_FORCED_QUIT', return mask 'RETURN_MASK_FORCED_QUIT', and a wrapper for throwing the exception, throw_forced_quit(). The addition of this exception plus supporting code will allow us to recognize that a SIGTERM has been received by GDB and then propagate recognition of that fact to the upper levels of GDB where it can be correctly handled. At the moment, when GDB receives a SIGTERM, it will attempt to exit via a series of calls from the QUIT checking code. However, before it can exit, it must do various cleanups, such as killing or detaching all inferiors. Should these cleanups be attempted while GDB is executing very low level code, such as reading target memory from within ps_xfer_memory(), it can happen that some of GDB's state is out of sync with regard to the cleanup code's expectations. In the case just mentioned, it's been observed that inferior_ptid and the current_thread_ are not in sync; this triggers an assert / internal error. This commit only introduces the exception plus supporting machinery; changes which use this new exception are in later commits in this series. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26761 Tested-by: Tom de Vries <tdevries@suse.de> Approved-by: Pedro Alves <pedro@palves.net>
This commit is contained in:
@@ -184,6 +184,8 @@ throw_exception (gdb_exception &&exception)
|
|||||||
{
|
{
|
||||||
if (exception.reason == RETURN_QUIT)
|
if (exception.reason == RETURN_QUIT)
|
||||||
throw gdb_exception_quit (std::move (exception));
|
throw gdb_exception_quit (std::move (exception));
|
||||||
|
else if (exception.reason == RETURN_FORCED_QUIT)
|
||||||
|
throw gdb_exception_forced_quit (std::move (exception));
|
||||||
else if (exception.reason == RETURN_ERROR)
|
else if (exception.reason == RETURN_ERROR)
|
||||||
throw gdb_exception_error (std::move (exception));
|
throw gdb_exception_error (std::move (exception));
|
||||||
else
|
else
|
||||||
@@ -196,6 +198,8 @@ throw_it (enum return_reason reason, enum errors error, const char *fmt,
|
|||||||
{
|
{
|
||||||
if (reason == RETURN_QUIT)
|
if (reason == RETURN_QUIT)
|
||||||
throw gdb_exception_quit (fmt, ap);
|
throw gdb_exception_quit (fmt, ap);
|
||||||
|
else if (reason == RETURN_FORCED_QUIT)
|
||||||
|
throw gdb_exception_forced_quit (fmt, ap);
|
||||||
else if (reason == RETURN_ERROR)
|
else if (reason == RETURN_ERROR)
|
||||||
throw gdb_exception_error (error, fmt, ap);
|
throw gdb_exception_error (error, fmt, ap);
|
||||||
else
|
else
|
||||||
@@ -233,3 +237,13 @@ throw_quit (const char *fmt, ...)
|
|||||||
throw_vquit (fmt, args);
|
throw_vquit (fmt, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
throw_forced_quit (const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
|
||||||
|
va_start (args, fmt);
|
||||||
|
throw_it (RETURN_FORCED_QUIT, GDB_NO_ERROR, fmt, args);
|
||||||
|
va_end (args);
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
enum return_reason
|
enum return_reason
|
||||||
{
|
{
|
||||||
|
/* SIGTERM sent to GDB. */
|
||||||
|
RETURN_FORCED_QUIT = -3,
|
||||||
/* User interrupt. */
|
/* User interrupt. */
|
||||||
RETURN_QUIT = -2,
|
RETURN_QUIT = -2,
|
||||||
/* Any other error. */
|
/* Any other error. */
|
||||||
@@ -42,9 +44,10 @@ enum return_reason
|
|||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
RETURN_MASK_FORCED_QUIT = RETURN_MASK (RETURN_FORCED_QUIT),
|
||||||
RETURN_MASK_QUIT = RETURN_MASK (RETURN_QUIT),
|
RETURN_MASK_QUIT = RETURN_MASK (RETURN_QUIT),
|
||||||
RETURN_MASK_ERROR = RETURN_MASK (RETURN_ERROR),
|
RETURN_MASK_ERROR = RETURN_MASK (RETURN_ERROR),
|
||||||
RETURN_MASK_ALL = (RETURN_MASK_QUIT | RETURN_MASK_ERROR)
|
RETURN_MASK_ALL = (RETURN_MASK_FORCED_QUIT | RETURN_MASK_QUIT | RETURN_MASK_ERROR)
|
||||||
} return_mask;
|
} return_mask;
|
||||||
|
|
||||||
/* Describe all exceptions. */
|
/* Describe all exceptions. */
|
||||||
@@ -294,6 +297,21 @@ struct gdb_exception_quit : public gdb_exception
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct gdb_exception_forced_quit : public gdb_exception
|
||||||
|
{
|
||||||
|
gdb_exception_forced_quit (const char *fmt, va_list ap)
|
||||||
|
ATTRIBUTE_PRINTF (2, 0)
|
||||||
|
: gdb_exception (RETURN_FORCED_QUIT, GDB_NO_ERROR, fmt, ap)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit gdb_exception_forced_quit (gdb_exception &&ex) noexcept
|
||||||
|
: gdb_exception (std::move (ex))
|
||||||
|
{
|
||||||
|
gdb_assert (ex.reason == RETURN_FORCED_QUIT);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* An exception type that inherits from both std::bad_alloc and a gdb
|
/* An exception type that inherits from both std::bad_alloc and a gdb
|
||||||
exception. This is necessary because operator new can only throw
|
exception. This is necessary because operator new can only throw
|
||||||
std::bad_alloc, and OTOH, we want exceptions thrown due to memory
|
std::bad_alloc, and OTOH, we want exceptions thrown due to memory
|
||||||
@@ -336,5 +354,7 @@ extern void throw_error (enum errors error, const char *fmt, ...)
|
|||||||
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
|
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
|
||||||
extern void throw_quit (const char *fmt, ...)
|
extern void throw_quit (const char *fmt, ...)
|
||||||
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
|
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
|
||||||
|
extern void throw_forced_quit (const char *fmt, ...)
|
||||||
|
ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
|
||||||
|
|
||||||
#endif /* COMMON_COMMON_EXCEPTIONS_H */
|
#endif /* COMMON_COMMON_EXCEPTIONS_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user