gdb/lldb 调用一个函数并在其中打断
gdb/lldb call a function and break in it
我在一个长期运行的程序中有一个全局函数:
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) [=12=] = 22
(lldb)
我希望它在我点击 call test()
后在每一行中中断 test()
方法,而不仅仅是立即 return 结果。任何人都知道该怎么做?
------------------------------------ 下面回答------ ----------------------------
@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()
,但会报错!!!如何避免错误?
这不是开玩笑吗?刚刚检查了标准断点以确保:
(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");
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
文件中,您将被设置。
我在一个长期运行的程序中有一个全局函数:
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) [=12=] = 22
(lldb)
我希望它在我点击 call test()
后在每一行中中断 test()
方法,而不仅仅是立即 return 结果。任何人都知道该怎么做?
------------------------------------ 下面回答------ ----------------------------
@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()
,但会报错!!!如何避免错误?
这不是开玩笑吗?刚刚检查了标准断点以确保:
(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");
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
文件中,您将被设置。