gdb / lldb调用一个函数并中断它

我有一个长期计划的全局function:

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) 

我希望它在我call test()之后每一行都在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()中断了,但是引发了错误! 如何避免错误?

lldb中的expression命令( callexpression的别名)需要十几个选项,其中一个是lldb是否应该在执行表达式时在断点处停止, – ignore --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文件中,然后就可以设置了。

这可不是说笑? 只需检查标准断点即可:

 (gdb) b test Breakpoint 2 at 0x400671: file tc, line 6. (gdb) call test() Breakpoint 2, test () at tc:6 6 printf("a\n");