From: Andrew Burgess Date: Wed, 17 Nov 2021 09:35:46 +0000 (+0000) Subject: gdb: add asserts in target.c for target_async_permitted X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bf94662bfe3ac43e792a4a6c44e35d7aafa9d0c1;p=binutils-gdb.git gdb: add asserts in target.c for target_async_permitted The target_async_permitted flag allows a user to override whether a target can act in async mode or not. In previous commits I have moved the checking of this flag out of the various ::can_async_p methods and into the common target.c code. In this commit I will add some additional assertions into target_is_async_p and target_async. The rules these assertions are checking are: 1. A target that returns false for target_can_async_p should never become "async enabled", and so ::is_async_p should always return false. This is being checked in target_is_async_p. 2. GDB should never try to enable async mode for a target that returns false for target_can_async_p, this is checked in target_async. There are a few places where we call the ::is_async_p method directly, in these cases we will obviously not pass through the assert in target_is_async_p, however, there are also plenty of places where we do call target_is_async_p so if GDB starts to misbehave we should catch it quickly enough. There should be no user visible changes after this commit. --- diff --git a/gdb/target.c b/gdb/target.c index db1abcc325e..06a21c46a19 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -409,7 +409,9 @@ target_can_async_p (struct target_ops *target) bool target_is_async_p () { - return current_inferior ()->top_target ()->is_async_p (); + bool result = current_inferior ()->top_target ()->is_async_p (); + gdb_assert (target_async_permitted || !result); + return result; } exec_direction_kind @@ -4338,6 +4340,9 @@ maintenance_print_target_stack (const char *cmd, int from_tty) void target_async (int enable) { + /* If we are trying to enable async mode then it must be the case that + async mode is possible for this target. */ + gdb_assert (!enable || target_can_async_p ()); infrun_async (enable); current_inferior ()->top_target ()->async (enable); }