From 94223333026f06dc5d78266dd9b6082544641f07 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Tue, 30 Jul 2024 19:41:05 +0800 Subject: gdb: LoongArch: Add show-debug-regs maintenance command This patch register the command "maint set show-debug-regs on/off" and make it settable by the user. If show-debug-regs is enabled, the debug register values are shown when GDB inserts or removes a hardware breakpoint or watchpoint. This is helpful for the use and development of hardware watchpoints. With this patch, the effect of this maintenance command as follows: lihui@bogon:~$ cat test.c int a = 0; int main() { a = 1; return 0; } lihui@bogon:~$ gcc -g test.c -o test lihui@bogon:~$ gdb test ... (gdb) watch a Hardware watchpoint 1: a (gdb) maint set show-debug-regs on (gdb) r Starting program: /home/lihui/test ... ... prepare_to_resume thread 41525 ... insert_watchpoint (addr=0x12000803c, len=4, type=hw-write-watchpoint): BREAKPOINTs: BP0: addr=0x0, ctrl=0x00000000, ref.count=0 BP1: addr=0x0, ctrl=0x00000000, ref.count=0 BP2: addr=0x0, ctrl=0x00000000, ref.count=0 BP3: addr=0x0, ctrl=0x00000000, ref.count=0 BP4: addr=0x0, ctrl=0x00000000, ref.count=0 BP5: addr=0x0, ctrl=0x00000000, ref.count=0 BP6: addr=0x0, ctrl=0x00000000, ref.count=0 BP7: addr=0x0, ctrl=0x00000000, ref.count=0 WATCHPOINTs: WP0: addr=0x0, ctrl=0x00000000, ref.count=0 WP1: addr=0x0, ctrl=0x00000000, ref.count=0 WP2: addr=0x0, ctrl=0x00000000, ref.count=0 WP3: addr=0x0, ctrl=0x00000000, ref.count=0 WP4: addr=0x0, ctrl=0x00000000, ref.count=0 WP5: addr=0x0, ctrl=0x00000000, ref.count=0 WP6: addr=0x0, ctrl=0x00000000, ref.count=0 WP7: addr=0x12000803c, ctrl=0x00000610, ref.count=1 ... remove_watchpoint (addr=0x12000803c, len=4, type=hw-write-watchpoint): BREAKPOINTs: BP0: addr=0x0, ctrl=0x00000000, ref.count=0 BP1: addr=0x0, ctrl=0x00000000, ref.count=0 BP2: addr=0x0, ctrl=0x00000000, ref.count=0 BP3: addr=0x0, ctrl=0x00000000, ref.count=0 BP4: addr=0x0, ctrl=0x00000000, ref.count=0 BP5: addr=0x0, ctrl=0x00000000, ref.count=0 BP6: addr=0x0, ctrl=0x00000000, ref.count=0 BP7: addr=0x0, ctrl=0x00000000, ref.count=0 WATCHPOINTs: WP0: addr=0x0, ctrl=0x00000000, ref.count=0 WP1: addr=0x0, ctrl=0x00000000, ref.count=0 WP2: addr=0x0, ctrl=0x00000000, ref.count=0 WP3: addr=0x0, ctrl=0x00000000, ref.count=0 WP4: addr=0x0, ctrl=0x00000000, ref.count=0 WP5: addr=0x0, ctrl=0x00000000, ref.count=0 WP6: addr=0x0, ctrl=0x00000000, ref.count=0 WP7: addr=0x0, ctrl=0x00000000, ref.count=0 Hardware watchpoint 1: a Old value = 0 New value = 1 main () at test.c:5 5 return 0; (gdb) Signed-off-by: Hui Li Signed-off-by: Tiezhu Yang --- gdb/loongarch-linux-nat.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gdb/loongarch-linux-nat.c') diff --git a/gdb/loongarch-linux-nat.c b/gdb/loongarch-linux-nat.c index 8736287..bc9927d 100644 --- a/gdb/loongarch-linux-nat.c +++ b/gdb/loongarch-linux-nat.c @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "cli/cli-cmds.h" #include "elf/common.h" #include "gregset.h" #include "inferior.h" @@ -765,4 +766,19 @@ _initialize_loongarch_linux_nat () { linux_target = &the_loongarch_linux_nat_target; add_inf_child_target (&the_loongarch_linux_nat_target); + + /* Add a maintenance command to enable printing the LoongArch internal + debug registers mirror variables. */ + add_setshow_boolean_cmd ("show-debug-regs", class_maintenance, + &show_debug_regs, _("\ +Set whether to show the LoongArch debug registers state."), _("\ +Show whether to show the LoongArch debug registers state."), _("\ +Use \"on\" to enable, \"off\" to disable.\n\ +If enabled, the debug registers values are shown when GDB inserts\n\ +or removes a hardware breakpoint or watchpoint, and when the inferior\n\ +triggers a breakpoint or watchpoint."), + NULL, + NULL, + &maintenance_set_cmdlist, + &maintenance_show_cmdlist); } -- cgit v1.1