长颈鹿Giraffe

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

 

posted on 2013-06-23 20:52  长颈鹿Giraffe  阅读(1697)  评论(0编辑  收藏  举报