简体   繁体   English

对于 gdb,rwatch 断点是否应该激活写入该断点的命令? 我的没有

[英]For gdb, should an rwatch breakpoint activate the commands written to that breakpoint? Mine don't

After I finished writing this I saw that rwatch actives a signal, SIGTRAP, which seems to be different than a breakpoint.写完这篇文章后,我看到 rwatch 激活了一个信号 SIGTRAP,它似乎与断点不同。 I'm confused now because the command 'info breakpoints' still lists it as a breakpoint.我现在很困惑,因为命令“信息断点”仍然将其列为断点。

I don't know if this is expected behavior or if I'm setting up something wrong.我不知道这是预期的行为还是我设置错误。 I have a setup running gdb (from ARM toolchain) and openocd with the target being a stm32 discovery board.我有一个运行 gdb(来自 ARM 工具链)和 openocd 的设置,目标是 stm32 发现板。 I'm trying to run certain gdb commands on a watchpoint using the command我正在尝试使用命令在观察点上运行某些 gdb 命令

commands [breakpointnumber]

Then I add the commands when prompted, I'm using 'px' and 'py' to print the x and y variable, and end it with 'end' like it says I should.然后在出现提示时添加命令,我使用“px”和“py”来打印 x 和 y 变量,并以“end”结束,就像我应该说的那样。

This does work when I set a breakpoint using当我使用设置断点时,这确实有效

b [linenumber]

Here is an example of it running on gdb这是在 gdb 上运行的示例

(gdb) b 15
Breakpoint 5 at 0x8000134: file main.c, line 15.
(gdb) commands 5
Type commands for breakpoint(s) 5, one per line.
End with a line saying just "end".
>p x
>p y
>end
(gdb) info breakpoints
Num     Type           Disp Enb Address    What
5       breakpoint     keep y   0x08000134 in main at main.c:15
        p x
        p y
(gdb) c
Continuing.

Breakpoint 5, main () at main.c:15
15          y++;
$21 = 46 '.'
$22 = 44 ','
(gdb) c
Continuing.

Breakpoint 5, main () at main.c:15
15          y++;
$23 = 47 '/'
$24 = 46 '.'
(gdb) c
Continuing.

Breakpoint 5, main () at main.c:15
15          y++;
$25 = 48 '0'
$26 = 48 '0'

but if I use the rwatch command such as但是如果我使用 rwatch 命令,例如

rwatch x

and set the commands like before, those commands don't run when the program reaches the rwatch breakpoint.并像以前一样设置命令,当程序到达 rwatch 断点时,这些命令不会运行。 Here is gdb running using rwatch这是使用 rwatch 运行的 gdb

(gdb) delete
Delete all breakpoints? (y or n) y
(gdb) rwatch x
Hardware read watchpoint 6: x
(gdb) commands 6
Type commands for breakpoint(s) 6, one per line.
End with a line saying just "end".
>p x
>p y
>end
(gdb) info breakpoints
Num     Type            Disp Enb Address    What
6       read watchpoint keep y              x
        p x
        p y
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0800012c in main () at main.c:14
14          x++;
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0800012c in main () at main.c:14
14          x++;
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0800012c in main () at main.c:14
14          x++;

I have deleted all other breakpoints.我已经删除了所有其他断点。 Using 'info breakpoints' shows the commands are associated with the breakpoint使用“信息断点”显示命令与断点相关联

It's just a test program as I learn gdb and openocd so it's really short.这只是一个测试程序,因为我学习了 gdb 和 openocd,所以它真的很短。

#include "stdint.h"
  5 uint8_t checker = 0x50;
  4 uint8_t x = 0x21;
  3 uint8_t y = 0x14;
  2 int main(void)
  1 {
12      while(1)
  1     {
  2         x++;
  3         y++;
  4         y++;
  5         ;
  6         if(x == 5000)
  7         {
  8             x = 0;
  9         }
 10         if(y == 10000)
 11         {
 12             y = 0;
 13         }
 14     }
 15 }

I suspect that this is an openocd bug.我怀疑这是一个 openocd 错误。 That the watchpoint is being reported as a SIGTRAP is not the correct behaviour, but most likely reflects what GDB is being told by openocd.将观察点报告为 SIGTRAP 不是正确的行为,但很可能反映了 openocd 告诉 GDB 的内容。

If we look at the behaviour of GDB running on native Linux, I see this behaviour:如果我们查看在本机 Linux 上运行的 GDB 的行为,我会看到以下行为:

$ gdb -q test
Reading symbols from test...
(gdb) start
Temporary breakpoint 1 at 0x401123: file test.c, line 10.
Starting program: /tmp/rwatch/test 

Temporary breakpoint 1, main () at test.c:10
10    int var = 0;
(gdb) rwatch var
Hardware read watchpoint 2: var
(gdb) commands
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>echo hello world\n
>end
(gdb) c
Continuing.

Hardware read watchpoint 2: var

Value = 0
main () at test.c:12
12    func (&var);
hello world
(gdb) 

And, if I use gdbserver , then I see the same behaviour:而且,如果我使用gdbserver ,那么我会看到相同的行为:

> gdb -q test
Reading symbols from test...
(gdb) target remote :54321
Remote debugging using :54321
... snip lots of library loading text ...
(gdb) b main
Breakpoint 1 at 0x401123: file test.c, line 10.
(gdb) c
Continuing.
... snip lots more library loading text ...
Breakpoint 1, main () at test.c:10
10    int var = 0;
(gdb) rwatch var
Hardware read watchpoint 2: var
(gdb) command
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>echo hello world\n
>end
(gdb) c
Continuing.

Hardware read watchpoint 2: var

Value = 0
main () at test.c:12
12    func (&var);
hello world
(gdb) 

So we can see that GDB can handle read watchpoints better than just reporting a SIGTRAP, so I suspect the problem here is openocd reporting that the stop is due to a SIGTRAP, rather than being due to a read watchpoint triggering.所以我们可以看到 GDB 可以比仅仅报告 SIGTRAP 更好地处理读取观察点,所以我怀疑这里的问题是 openocd 报告停止是由于 SIGTRAP,而不是由于读取观察点触发。

You might be able to work around this problem by making use of the Python API, there is a gdb.StopEvent , you could catch these and then try printing out the variables you are interested in maybe?您可以通过使用 Python API 来解决此问题,有一个gdb.StopEvent ,您可以抓住这些变量然后尝试打印出您感兴趣的变量吗? The following Python code, placed into a file and then sourced into GDB should do the job:将以下 Python 代码放入文件中,然后将其导入 GDB 应该可以完成这项工作:

def stop_handler (event):
    if (type (event) == gdb.SignalEvent
        and event.stop_signal == 'SIGTRAP'):
        print ("Use gdb.execute to run arbitrary commands here!")

gdb.events.stop.connect (stop_handler)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM