zoukankan      html  css  js  c++  java
  • GDB调试GCC(jRate)

    GDB调试GCC(jRate)

    1、前提是build GCC的时候要修改makefile,在configure之后生成的makefile忠,将CFLAGS和CFLAGS_FOR_BUILD改成-g3 -O0..

    2、在root用户下,切换到源码所在目录,输入:

    jRate-gcj --main=Test1 Test1.java -o Test1 -dr -O0 -v

     -dr表示导出RTL代码,-v会显示GCC编译各个过程的命令行信息,在后面使用GDB的时候会用到。

    这里我显示的如下所示:

    复制代码
    Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs
    Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/../../../libgcj.spec
    rename spec lib to liborig
    Configured with: /home/yanxin/jrate/gcc/configure --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --target=i686-pc-linux-gnu --disable-jvmpi --enable-java-gc=jRate --enable-threads=posix --enable-languages=c,c++,java --prefix=/usr/local --program-prefix=jRate- --disable-interpreter --disable-hash-synchronization --disable-pthread-self-cache --enable-shared --enable-static
    Thread model: posix
    gcc version 3.3.3
     /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/jc1 Test1.java -fno-use-divide-subroutine -fnon-call-exceptions -fkeep-inline-functions -quiet -dumpbase Test1.java -dr -auxbase Test1 -O0 -version -o /tmp/ccUyN2au.s
    GNU Java version 3.3.3 (i686-pc-linux-gnu)
        compiled by GNU C version 3.3.3.
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
    Class path starts here:
        ./
        /usr/local/share/java/libgcj-3.3.3.jar/ (system) (zip)
     as --traditional-format -V -Qy -o /tmp/ccLz5gJN.o /tmp/ccUyN2au.s
    GNU assembler version 2.22 (i686-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.22
     /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/jvgenmain Test1main /tmp/cc4SRZv7.i
     /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/cc1 /tmp/cc4SRZv7.i -quiet -dumpbase Test1main.c -dr -O0 -version -fdollars-in-identifiers -o /tmp/ccUyN2au.s
    GNU C version 3.3.3 (i686-pc-linux-gnu)
        compiled by GNU C version 3.3.3.
    GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
     as --traditional-format -V -Qy -o /tmp/ccPD6vYr.o /tmp/ccUyN2au.s
    GNU assembler version 2.22 (i686-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.22
     /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o Test1 /usr/lib/i386-linux-gnu/crt1.o /usr/lib/i386-linux-gnu/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/crtbegin.o -L/usr/lib/i386-linux-gnu -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/../../.. /tmp/ccPD6vYr.o /tmp/ccLz5gJN.o -lgcc_s -lgcc -lgcj -lm -lpthread -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/crtend.o /usr/lib/i386-linux-gnu/crtn.o
    复制代码

    我们主要用到这个:

    /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/jc1 Test1.java -fno-use-divide-subroutine -fnon-call-exceptions -fkeep-inline-functions -quiet -dumpbase Test1.java -dr -auxbase Test1 -O0 -version -o /tmp/ccUyN2au.s
    
    

    3、在终端里输入:

    gdb /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/jc1
    break main
    run Test1.java -fno-use-divide-subroutine -fnon-call-exceptions -fkeep-inline-functions -quiet -dumpbase Test1.java -dr -auxbase Test1 -O0 -version -o /tmp/ccUyN2au.s
    break rest_of_compilation
    continue
    backtrace

    下面给出了显示出的从main到rest_of_compilation的函数调用情况:

    复制代码
    #0  rest_of_compilation (decl=0xb7a9d488) at /home/yanxin/jrate/gcc/gcc/toplev.c:2368
    #1  0x08059af0 in source_end_java_method () at /home/yanxin/jrate/gcc/gcc/java/parse.y:7568
    #2  0x0805a835 in java_expand_method_bodies (class=0x5) at /home/yanxin/jrate/gcc/gcc/java/parse.y:8249
    #3  0x0805becd in java_expand_classes () at /home/yanxin/jrate/gcc/gcc/java/parse.y:9230
    #4  0x08083336 in java_parse_file (set_yydebug=0) at /home/yanxin/jrate/gcc/gcc/java/jcf-parse.c:1144
    #5  0x08221d5a in compile_file () at /home/yanxin/jrate/gcc/gcc/toplev.c:2130
    #6  0x08227055 in do_compile () at /home/yanxin/jrate/gcc/gcc/toplev.c:5407
    #7  0x082270fd in toplev_main (argc=5, argv=0xbffff1f4) at /home/yanxin/jrate/gcc/gcc/toplev.c:5437
    #8  0x080927cb in main (argc=5, argv=0x5) at /home/yanxin/jrate/gcc/gcc/main.c:35
    复制代码
     
     
     
    标签: GCCGDB
  • 相关阅读:
    分层图最短路(DP思想) BZOJ2662 [BeiJing wc2012]冻结
    动态规划 BZOJ1925 地精部落
    线性DP SPOJ Mobile Service
    线性DP codevs2185 最长公共上升子序列
    数位DP POJ3208 Apocalypse Someday
    线性DP POJ3666 Making the Grade
    杨氏矩阵 线性DP? POJ2279 Mr.Young's Picture Permutations
    tarjan强连通分量 洛谷P1262 间谍网络
    树链剖分 BZOJ3589 动态树
    二分图 BZOJ4554 [Tjoi2016&Heoi2016]游戏
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3151565.html
Copyright © 2011-2022 走看看