我在长期计划中有一个全局功能:
int test()
{
int a = 12;
int c = 10;
printf("a=%d",a);
a += c ;
printf("a=%d", a);
return a;
}
我调试程序并中断,然后发出以下命令:
(lldb) call test()
a=12a=22(int) $0 = 22
(lldb)
我希望在我点击test()
之后每行都在call test()
方法中断,而不是立即返回结果。谁知道怎么做?
------------------------------------以下答案--------- ---------------------------
@Jason Molenda的回答是正确答案,请使用expr -i0 -- test()
代替call test()
:
(lldb) b test
Breakpoint 1: 4 locations.
(lldb) expr -i0 -- test()
error: Execution was interrupted, reason: breakpoint 1.1.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
(lldb)
现在它突破了test()
,但引发了错误!如何避免错误?
答案 0 :(得分:2)
lldb中的expression
命令(call
是expression
的别名)需要十几个选项,其中一个是lldb是否应该在执行表达式时在断点处停止,--ignore-breakpoints false
或-i false
或-i 0
。
(lldb) br s -n printf
Breakpoint 2: where = libsystem_c.dylib`printf, address = 0x00007fff89ee7930
(lldb) expr -- (void)printf("hi\n")
hi
(lldb) expr -i0 -- (void)printf("hi\n")
error: Execution was interrupted, reason: breakpoint 2.1.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
Process 15259 stopped
* thread #1: tid = 0xf0daf, 0x00007fff89ee7930 libsystem_c.dylib`printf, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
#0: 0x00007fff89ee7930 libsystem_c.dylib`printf
libsystem_c.dylib`printf:
-> 0x7fff89ee7930: pushq %rbp
0x7fff89ee7931: movq %rsp, %rbp
0x7fff89ee7934: pushq %r15
0x7fff89ee7936: pushq %r14
(lldb)
有一些想法投入到默认行为(是否在断点处停止),这似乎是大多数人所期望的行为。
正如我所说,call
命令只是expression
的别名。如果要更改其行为,可以使用自己的别名覆盖别名。例如command alias call expr -i false --
会做到这一点。您可以将其放在~/.lldbinit
文件中,然后设置即可。
答案 1 :(得分:0)
这不是开玩笑吗?只需检查标准断点即可:
(gdb) b test
Breakpoint 2 at 0x400671: file t.c, line 6.
(gdb) call test()
Breakpoint 2, test () at t.c:6
6 printf("a\n");