Gdb / lldb calls a function and breaks it

I have a global function in the long run:

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 interrupt it, then issue the following command:

(lldb) call test()
a=12a=22(int) $0 = 22
(lldb)

I want it to break the method test()into each line after I clicked call test(), and not immediately return the result. Does anyone know how to do this?

------------------------------------ Answer Below --------- --- ------------------------

@ Jason Molenda's answer is the correct answer, use expr -i0 -- test()instead 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 breaks into test(), but causes an error !!! How to avoid a mistake?

+4
source share
2 answers

expression lldb (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 , .

+2

? :

(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");
0

Source: https://habr.com/ru/post/1569952/


All Articles