]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb: LoongArch: Add support for hardware watchpoint
authorHui Li <lihui@loongson.cn>
Tue, 11 Jun 2024 11:21:25 +0000 (19:21 +0800)
committerTiezhu Yang <yangtiezhu@loongson.cn>
Mon, 24 Jun 2024 21:50:08 +0000 (05:50 +0800)
commitc1cdee0e2c1715718c1e6224038096142ccabe40
tree1e50ae293e34a0f0bde9f21c71fc68a956cb24ed
parent5ae5974d60378fa3faecff64725e00c8695bcc7d
gdb: LoongArch: Add support for hardware watchpoint

LoongArch defines hardware watchpoint functions for load/store
operations. After the software configures the watchpoints for
load/store, the processor hardware will monitor the access
addresses of the load/store operations and trigger watchpoint
exception when the watchpoint setting conditions are met.

After this patch, watch/rwatch/awatch command are supported. Refer to the
following document for hardware watchpoint.
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints

A simple test is as follows:

lihui@bogon:~$ cat test.c
  #include <stdio.h>
  int a = 0;
  int main()
  {
        printf("start test\n");
        a = 1;
        printf("a = %d\n", a);
        printf("end test\n");
        return 0;
  }

lihui@bogon:~$ gcc -g test.c -o test

without this patch:

lihui@bogon:~$ gdb test
...
(gdb) start
...
Temporary breakpoint 1, main () at test.c:5
5               printf("start test\n");
(gdb) awatch a
Target does not support this type of hardware watchpoint.
...

with this patch:

lihui@bogon:~$ gdb test
...
(gdb) start
...
Temporary breakpoint 1, main () at test.c:5
5               printf("start test\n");
(gdb) awatch a
Hardware access (read/write) watchpoint 2: a
(gdb) c
Continuing.
start test

Hardware access (read/write) watchpoint 2: a

Old value = 0
New value = 1
main () at test.c:7
7               printf("a = %d\n", a);
(gdb) c
Continuing.

Hardware access (read/write) watchpoint 2: a

Value = 1
0x00000001200006e0 in main () at test.c:7
7               printf("a = %d\n", a);
(gdb) c
Continuing.
a = 1
end test
[Inferior 1 (process 22250) exited normally]

Signed-off-by: Hui Li <lihui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
gdb/Makefile.in
gdb/configure.nat
gdb/loongarch-linux-nat.c
gdb/loongarch-tdep.c
gdb/nat/loongarch-hw-point.c [new file with mode: 0644]
gdb/nat/loongarch-hw-point.h [new file with mode: 0644]
gdb/nat/loongarch-linux-hw-point.c [new file with mode: 0644]
gdb/nat/loongarch-linux-hw-point.h [new file with mode: 0644]
gdb/nat/loongarch-linux.c [new file with mode: 0644]
gdb/nat/loongarch-linux.h [new file with mode: 0644]
include/elf/common.h