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

我在长期计划中有一个全局函数:

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()之后每行都在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中的表达式命令(call是表达式的别名)需要十几个选项,其中一个是lldb是否应该在执行表达式时在断点处停止, – ignore-breakpoints false,或-i false,或者 – 我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命令只是表达式的别名.如果要更改其行为,可以使用自己的别名覆盖别名.例如命令别名call expr -i false – 会做的伎俩.您可以将它放在〜/ .lldbinit文件中,然后就可以了.

点赞