From bf94662bfe3ac43e792a4a6c44e35d7aafa9d0c1 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Wed, 17 Nov 2021 09:35:46 +0000 Subject: [PATCH] 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. --- gdb/target.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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); } -- 2.30.2