From 38d015075b08dd709ad1b62fca386c7ee7b3f95a Mon Sep 17 00:00:00 2001 From: Lancelot SIX Date: Mon, 6 Feb 2023 10:34:52 +0000 Subject: [PATCH] gdb: Add the $_poke utility function Add the $_poke utility function so it is possible to use poke in breakpoint condition for example. The expression must return a poke boolean. --- gdb/poke.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/gdb/poke.c b/gdb/poke.c index 9bb24236d2f..cb1bb1431c4 100644 --- a/gdb/poke.c +++ b/gdb/poke.c @@ -864,6 +864,45 @@ poke_command (const char *args, int from_tty) poke_handle_exception (exit_exception); } +static struct value * +poke_internal_fn (struct gdbarch *gdbarch, + const struct language_defn *language, + void *cookie, int argc, struct value **argv) +{ + if (argc != 1) + error ("_poke_poc requires only one argument"); + + struct type *type = value_type (argv[0]); + if (type->code () != TYPE_CODE_ARRAY + || TYPE_TARGET_TYPE (type) != builtin_type (gdbarch)->builtin_char) + error ("_poke_poc's first argument must have type 'const char *'"); + + gdb::array_view content = value_contents (argv[0]); + const char *poke_expr = reinterpret_cast (content.begin ()); + const char *poke_end = reinterpret_cast (content.end () - 1); + gdb_assert (*poke_end) == '\0'); + pk_val val; + pk_val exit_exception = PK_NULL; + if (pk_compile_statement (poke_compiler, poke_cmd, &poke_end, + &val, &exit_exception) != PK_OK + || exit_exception != PK_NULL) + { + poke_handle_exception (exit_exception); + error ("Error compiling poke call"); + } + + /* Do the best we can to convert a poke value to a GDB value. */ + switch (pk_val_kind (val)) + { + case PK_VAL_INT: + case PK_VAL_UINT: + default: + error ("Poke"); + } + + return value_from_longest (builtin_type (gdbarch)->builtin_int, 0); +} + /* Initialize the poke GDB subsystem. */ void _initialize_poke (void); @@ -886,5 +925,8 @@ Usage: poke-dump-types\n")); Execute a Poke statement or declaration.\n\ Usage: poke [STMT]\n")); + add_internal_function ("_poke", _("\ +Run the expression in poke", poke_internal_fn, nullptr); + make_final_cleanup (poke_finalize, nullptr); } -- 2.47.2