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);
返回a;
}
我调试程序并中断,然后发出以下命令:
(lldb)call test()
a = 12a = 22(int)$ 0 = 22
(lldb)
我希望它在 test()
方法在每次按下 call test()
之后的每一行,而不仅仅是立即返回结果。任何人都知道如何做到这一点?
----------------------------------- - 下面的答案------------------------------------
@Jason Molenda的答案是正确的答案,使用 expr -i0 - test()
而不是 call test()
:
(lldb)b测试
断点1:4个位置。
(lldb)expr -i0 - test()
错误:执行中断,原因:断点1.1。
该进程已经被中断,使用线程返回-x返回表达式评估之前的状态。
(lldb)
现在在 test()
,但会引发错误!如何避免错误?
call
是表达式的别名
)需要十几个选项,其中之一是lldb是否应该停止执行表达式时的断点, - ignore-breakpoints false
或 -i false
或 -i 0
。
(lldb)br s -n printf
断点2 :where = libsystem_c.dylib`printf,address = 0x00007fff89ee7930
(lldb)expr - (void)printf(hi\\\
)
hi
(lldb)expr -i0 - - (void)printf(hi\\\
)
错误:执行中断,原因:断点2.1。
该进程已经被中断,使用线程返回-x返回表达式评估之前的状态。
进程15259停止
*线程#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)
对默认行为有一些想法(是否停止在断点上),这似乎是大多数人的行为期望。
正如我所说的,调用
命令只是表达式的别名
。如果你想改变它的行为,你可以用你自己的别名覆盖别名。例如命令别名调用expr -i false -
会执行该操作。你可以把它放在〜/ .lldbinit
文件中,你就可以设置。
I have a global function in a long run program :
int test()
{
int a = 12;
int c = 10;
printf("a=%d",a);
a += c ;
printf("a=%d", a);
return a;
}
I debug the program and break, then issue the following command:
(lldb) call test()
a=12a=22(int) $0 = 22
(lldb)
I want it to break in test()
method every line after I hit call test()
, not just return the result immediately. Anyone knows how to do it ?
------------------------------------ Answer Below ------------------------------------
@Jason Molenda 's answer is the right answer,use expr -i0 -- test()
instead of 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)
Now it break in test()
, but raise an error!!! How to avoid the error ?
The expression
command in lldb (call
is an alias for expression
) takes a dozen or so options, one of them being whether lldb should stop on a breakpoint while executing the expression, --ignore-breakpoints false
, or -i false
, or -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)
There was some thought put in to the default behavior (whether to stop on a breakpoint or not), and this seemed the behavior most people would expect.
As I said, the call
command is just an alias for expression
. If you want to change the behavior of it, you can overwrite the alias with one of your own. e.g. command alias call expr -i false --
will do the trick. You can put this in your ~/.lldbinit
file and you'll be set.
这篇关于gdb / lldb调用一个函数并打断它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!