From: Luis Machado Date: Mon, 14 Jun 2021 17:32:26 +0000 (-0300) Subject: Make capability maintenance command available to cross GDB X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a3d7ef8da1fbd92964964aabf218e553ba30d8c;p=thirdparty%2Fbinutils-gdb.git Make capability maintenance command available to cross GDB The capability maintenance commands were originally only available to native Morello GDB builds. Make those commands available to cross Morello GDB builds as well, since they are useful. gdb/ChangeLog: 2021-06-24 Luis Machado * aarch64-linux-nat.c (maint_print_cap_from_addr_cmd) (maint_set_capability_in_memory_cmd): Move functions to... * aarch64-linux-tdep.c: ... here. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 83fc5888053..c65189810fa 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2021-06-24 Luis Machado + + * aarch64-linux-nat.c (maint_print_cap_from_addr_cmd) + (maint_set_capability_in_memory_cmd): Move functions to... + * aarch64-linux-tdep.c: ... here. + 2021-06-24 Luis Machado * aarch64-linux-nat.c (store_cregs_to_thread) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 70263da9259..5e0e599c735 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -1130,57 +1130,6 @@ aarch64_linux_nat_target::write_capability (CORE_ADDR addr, return true; } -/* Implement the maintenance print capability tag command. */ - -static void -maint_print_cap_from_addr_cmd (const char *args, int from_tty) -{ - gdb::byte_vector cap; - CORE_ADDR addr = parse_and_eval_address (args); - cap = target_read_capability (addr); - - for (auto it : cap) - fprintf_unfiltered (gdb_stdlog, "%02x ", it); - - fputs_unfiltered ("\n", gdb_stdlog); -} - -/* Implement the maintenance set capability in memory command. */ - -static void -maint_set_capability_in_memory_cmd (const char *args, int from_tty) -{ - std::string addr_str, tag_str, upper_str, lower_str; - const char *args_ptr = args; - - addr_str = extract_string_maybe_quoted (&args_ptr); - tag_str = extract_string_maybe_quoted (&args_ptr); - upper_str = extract_string_maybe_quoted (&args_ptr); - lower_str = extract_string_maybe_quoted (&args_ptr); - - CORE_ADDR addr = parse_and_eval_address (addr_str.c_str ()); - CORE_ADDR tag_part = parse_and_eval_address (tag_str.c_str ()); - CORE_ADDR half_a = parse_and_eval_address (upper_str.c_str ()); - CORE_ADDR half_b = parse_and_eval_address (lower_str.c_str ()); - - unsigned __int128 a, b; - - a = half_a; - b = half_b; - - a = (a << 64) | b; - bool tag = (tag_part != 0)? true : false; - - gdb::byte_vector cap; - - cap.resize (17); - memcpy (cap.data (), &tag, 1); - memcpy (cap.data () + 1, &a, 16); - - if (!target_write_capability (addr, {cap.data (), cap.size ()})) - perror_with_name (_("Failed to set capability in memory.")); -} - /* Define AArch64 maintenance commands. */ static void @@ -1200,14 +1149,6 @@ triggers a breakpoint or watchpoint."), NULL, &maintenance_set_cmdlist, &maintenance_show_cmdlist); - - add_cmd ("cap_from_addr", class_maintenance, maint_print_cap_from_addr_cmd, _("\ -Print the capability from addr."), - &maintenanceprintlist); - - add_cmd ("cap_in_memory", class_maintenance, - maint_set_capability_in_memory_cmd, - _("Print the capability from addr."), &maintenancelist); } void _initialize_aarch64_linux_nat (); diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 11564009023..bada46f8442 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -20,6 +20,7 @@ #include "defs.h" +#include "gdbcmd.h" #include "gdbarch.h" #include "glibc-tdep.h" #include "linux-tdep.h" @@ -1765,6 +1766,57 @@ aarch64_linux_decode_memtag_note (struct gdbarch *gdbarch, return tag; } +/* Implement the maintenance print capability tag command. */ + +static void +maint_print_cap_from_addr_cmd (const char *args, int from_tty) +{ + gdb::byte_vector cap; + CORE_ADDR addr = parse_and_eval_address (args); + cap = target_read_capability (addr); + + for (auto it : cap) + fprintf_unfiltered (gdb_stdlog, "%02x ", it); + + fputs_unfiltered ("\n", gdb_stdlog); +} + +/* Implement the maintenance set capability in memory command. */ + +static void +maint_set_capability_in_memory_cmd (const char *args, int from_tty) +{ + std::string addr_str, tag_str, upper_str, lower_str; + const char *args_ptr = args; + + addr_str = extract_string_maybe_quoted (&args_ptr); + tag_str = extract_string_maybe_quoted (&args_ptr); + upper_str = extract_string_maybe_quoted (&args_ptr); + lower_str = extract_string_maybe_quoted (&args_ptr); + + CORE_ADDR addr = parse_and_eval_address (addr_str.c_str ()); + CORE_ADDR tag_part = parse_and_eval_address (tag_str.c_str ()); + CORE_ADDR half_a = parse_and_eval_address (upper_str.c_str ()); + CORE_ADDR half_b = parse_and_eval_address (lower_str.c_str ()); + + unsigned __int128 a, b; + + a = half_a; + b = half_b; + + a = (a << 64) | b; + bool tag = (tag_part != 0)? true : false; + + gdb::byte_vector cap; + + cap.resize (17); + memcpy (cap.data (), &tag, 1); + memcpy (cap.data () + 1, &a, 16); + + if (!target_write_capability (addr, {cap.data (), cap.size ()})) + perror_with_name (_("Failed to set capability in memory.")); +} + static void aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -2024,6 +2076,13 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) /* Core file helper to decode a memory tag note. */ set_gdbarch_decode_memtag_note (gdbarch, aarch64_linux_decode_memtag_note); + + add_cmd ("cap_from_addr", class_maintenance, maint_print_cap_from_addr_cmd, + _("Print the capability from addr."), &maintenanceprintlist); + + add_cmd ("cap_in_memory", class_maintenance, + maint_set_capability_in_memory_cmd, + _("Print the capability from addr."), &maintenancelist); } else {