]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Add the $_poke utility function users/lsix/poke-gdb
authorLancelot SIX <lancelot.six@amd.com>
Mon, 6 Feb 2023 10:34:52 +0000 (10:34 +0000)
committerLancelot SIX <lancelot.six@amd.com>
Mon, 6 Feb 2023 10:34:52 +0000 (10:34 +0000)
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

index 9bb24236d2f7116062f903bc61f31af14f32a05f..cb1bb1431c4bad4226a0b15d6b9d332890258724 100644 (file)
@@ -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<const gdb_byte> content = value_contents (argv[0]);
+  const char *poke_expr = reinterpret_cast<const char *> (content.begin ());
+  const char *poke_end = reinterpret_cast<const char *> (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);
 }