zoukankan      html  css  js  c++  java
  • gdb 调试动态库

    原文链接

    cat get.h

    int   get   (); 
    int   set   (int   a); 

    cat get.c

    #include   <stdio.h> 
    #include   "get.h" 
    
    static   int   x=0; 
    int   get   () 
    { 
                    printf   ( "get   x=%d\n ",   x); 
                    return   x; 
    } 
    int   set   (int   a) 
    { 
                    printf   ( "set   a=%d\n ",   a); 
                    x   =   a; 
                    return   x; 
    } 

    cat main.c

    #include   <stdio.h> 
    #include   "get.h " 
    int   main   (int   argc,   char**   argv) 
    { 
                    int   a   =   100; 
                    int   b   =   get   (); 
                    int   c   =   set   (a); 
                    int   d   =   get   (); 
    
                    printf   ( "a=%d,b=%d,c=%d,d=%d\n ",a,b,c,d); 
                    return   0; 
    } 

     cat   ./makefile 

    all:main 
    libget.so:get.c 
                    gcc   -g   -c   -o   get.o   get.c 
                    gcc   -g   -shared   -o   libget.so   get.o 
    
    main:main.c   libget.so 
                    gcc   -g   -c   -o   main.o   main.c 
                    gcc   -g   -o   main   main.o   -L./   -lget 
    
    clean: 
                    @rm   libget.so   get.o   main.o   main 

    5)用GDB调试(step   in) 

    >   gdb   ./main 
    
    (gdb)   break   main 
    Breakpoint   1   at   0x80484d0:   file   main.c,   line   5. 
    (gdb)   r 
    Starting   program:   /home/hchen/test/so/main 
    
    Breakpoint   1,   main   (argc=1,   argv=0xbfe62fc4)   at   main.c:5 
    5                               int   a   =   100; 
    (gdb)   n 
    6                               int   b   =   get   (); 
    (gdb)   s         <-------   进入动态库 
    get   ()   at   get.c:7 
    7                               printf   ( "get   x=%d\n ",   x); 
    (gdb)   s 
    get   x=0 
    8                               return   x; 
    
    6)用GDB调试(break   set) 
    (gdb)   break   set 
    Function   "set "   not   defined. 
    Make   breakpoint   pending   on   future   shared   library   load?   (y   or   [n])   y 
    
    Breakpoint   1   (set)   pending. 

  • 相关阅读:
    tableView小细节
    iOS5 切换中文键盘时覆盖输入框的解决方案
    NSBundle读取txt文件,图片,plist
    iOS OC 字符串处理
    图片拉伸 几种方式
    UIAlertView小结
    新来报道
    VC6.0之Debug调试总结
    关于C++中的临时对象问题
    与临时对象的斗争(下)
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2562974.html
Copyright © 2011-2022 走看看