Aaron2932

导航

lldb

lldb

main.c

#include<stdio.h>


int add(int n){
    int i, sum=0;
    for (i=0;i<n;i++){
        sum += i;
    }
    return sum;
}


int main(){
    int b = 100;
    int c = add(b);
    printf("c = %d\n", c);
    return 0;
}

mac上,使用lldb可以和gdb一样调试

gcc main.c -o ${proc_name}

如果需要gdb,必须加编译选项

gcc -g main.c -o ${proc_name}

开始调试

╭─aaron@Aarons-MacBook-Pro ~/cacheWorkspace/tmp 
╰─$ gcc -g main.c -o demo
╭─aaron@Aarons-MacBook-Pro ~/cacheWorkspace/tmp 
╰─$ lldb demo
(lldb) target create "demo"
Current executable set to 'demo' (x86_64).
(lldb) b main.c:5
Breakpoint 1: where = demo`add + 7 at main.c:5:12, address = 0x0000000100000f07
(lldb) r
Process 6426 launched: '/Users/aaron/cacheWorkspace/tmp/demo' (x86_64)
Process 6426 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f07 demo`add(n=100) at main.c:5:12
   2   	
   3   	
   4   	int add(int n){
-> 5   	    int i, sum=0;
   6   	    for (i=0;i<n;i++){
   7   	        sum += i;
   8   	    }
Target 0: (demo) stopped.
(lldb) q
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y
╭─aaron@Aarons-MacBook-Pro ~/cacheWorkspace/tmp 
╰─$ 

posted on 2022-09-03 15:24  Aaron2932  阅读(109)  评论(0编辑  收藏  举报