Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4238947
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: LINUX

2011-06-07 14:42:35


gcc 命令之 objdump
---------------objdump 是用查看目标文件或者可执行的目标文件的构成的GCC工具----------
以下3条命令足够那些喜欢探索目标文件与源代码之间的丝丝的关系的朋友。
objdump -x obj 以某种分类信息的形式把目标文件的数据组织(被分为几大块)输出 <可查到该文件的所有动态库>
objdump -t obj 输出目标文件的符号表()
objdump -h obj 输出目标文件的所有段概括()
objdump -j .text/.data -S obj 输出指定段的信息,大概就是反汇编源代码把
objdump -S obj C语言与汇编语言同时显示



objdump -j .text -Sl hello | more
objdump -j .text -Sl hello --prefix-address | more
objdump -j .text -Dl hello | more

  1. 命令行上要给出至少一个下面的选项:
  2. -a, --archive-headers 显示归档头文件的信息
  3. -f, --file-headers 显示全部头文件的内容
  4. -p, --private-headers 显示特定object头文件的内容
  5. -h, --[section-]headers 显示段头的内容
  6. -x, --all-headers 显示所有头内容
  7. -d, --disassemble 显示可执行段的汇编内容
  8. -D, --disassemble-all 显示所有断的汇编内容
  9. -S, --source 显示汇编内容和机器码
  10. -s, --full-contents 显示所有请求段的所有内容
  11. -g, --debugging 显示object文件中的调试信息
  12. -e, --debugging-tags 使用ctags的风格显示调试信息
  13. -G, --stabs 显示(用原始的表格)文件中任意的STABS信息
  14. -W, --dwarf 显示文件中的DWARF信息
  15. -t, --syms 显示符号表的内容
  16. -T, --dynamic-syms 显示动态符号表的内容
  17. -r, --reloc 显示文件中重定位的入口
  18. -R, --dynamic-reloc 显示文件中动态重定位的入口

  1. --archive-headers
  2. -a 显示档案库的成员信息,与 ar tv 类似

  3.     objdump -a libpcap.a
  4.     和 ar -tv libpcap.a 显示结果比较比较
  5.     显然这个选项没有什么意思。

  6. --adjust-vma=offset
  7.     When dumping information, first add offset to all
  8.     the section addresses. This is useful if the sec-
  9.     tion addresses do not correspond to the symbol
  10.     table, which can happen when putting sections at
  11.     particular addresses when using a format which can
  12.     not represent section addresses, such as a.out.

  13. -b bfdname
  14. --target=bfdname
  15.     指定目标码格式。这不是必须的,objdump能自动识别许多格式,
  16.     比如:objdump -b oasys -m vax -h fu.o
  17.     显示fu.o的头部摘要信息,明确指出该文件是Vax系统下用Oasys
  18.     编译器生成的目标文件。objdump -i将给出这里可以指定的
  19.     目标码格式列表

  20. --demangle
  21. -C 将底层的符号名解码成用户级名字,除了去掉所有开头
  22.    的下划线之外,还使得C++函数名以可理解的方式显示出来。

  23. --debugging
  24.     显示调试信息。企图解析保存在文件中的调试信息并以C语言
  25.     的语法显示出来。仅仅支持某些类型的调试信息。

  26. --disassemble
  27. -d 反汇编那些应该还有指令机器码的section

  28. --disassemble-all
  29. -D 与 -d 类似,但反汇编所有section

  30. --prefix-addresses
  31.     反汇编的时候,显示每一行的完整地址。这是一种比较老的反汇编格式。
  32.     显示效果并不理想,但可能会用到其中的某些显示,自己可以对比。

  33. --disassemble-zeroes
  34.     一般反汇编输出将省略大块的零,该选项使得这些零块也被反汇编。

  35. -EB
  36. -EL
  37. --endian={big|little}
  38.     这个选项将影响反汇编出来的指令。
  39.     little-endian就是我们当年在dos下玩汇编的时候常说的高位在高地址,
  40.     x86都是这种。

  41. --file-headers
  42. -f 显示objfile中每个文件的整体头部摘要信息。

  43. --section-headers
  44. --headers
  45. -h 显示目标文件各个section的头部摘要信息。

  46. --help 简短的帮助信息。

  47. --info
  48. -i 显示对于 -b 或者 -m 选项可用的架构和目标格式列表。

  49. --section=name
  50. -j name 仅仅显示指定section的信息

  51. --line-numbers
  52. -l 用文件名和行号标注相应的目标代码,仅仅和-d、-D或者-r一起使用
  53.    使用-ld和使用-d的区别不是很大,在源码级调试的时候有用,要求
  54.    编译时使用了-g之类的调试编译选项。

  55. --architecture=machine
  56. -m machine
  57.     指定反汇编目标文件时使用的架构,当待反汇编文件本身没有描述
  58.     架构信息的时候(比如S-records),这个选项很有用。可以用-i选项
  59.     列出这里能够指定的架构

  60. --reloc
  61. -r 显示文件的重定位入口。如果和-d或者-D一起使用,重定位部分以反汇
  62.    编后的格式显示出来。

  63. --dynamic-reloc
  64. -R 显示文件的动态重定位入口,仅仅对于动态目标文件有意义,比如某些
  65.    共享库。

  66. --full-contents
  67. -s 显示指定section的完整内容。

  68.     objdump --section=.text -s inet.o | more

  69. --source
  70. -S 尽可能反汇编出源代码,尤其当编译的时候指定了-g这种调试参数时,
  71.    效果比较明显。隐含了-d参数。

  72. --show-raw-insn
  73.     反汇编的时候,显示每条汇编指令对应的机器码,除非指定了
  74.     --prefix-addresses,这将是缺省选项。

  75. --no-show-raw-insn
  76.     反汇编时,不显示汇编指令的机器码,这是指定 --prefix-addresses
  77.     选项时的缺省设置。

  78. --stabs
  79.     Display the contents of the .stab, .stab.index, and
  80.     .stab.excl sections from an ELF file. This is only
  81.     useful on systems (such as Solaris 2.0) in which
  82.     .stab debugging symbol-table entries are carried in
  83.     an ELF section. In most other file formats, debug-
  84.     ging symbol-table entries are interleaved with
  85.     linkage symbols, and are visible in the --syms output.

  86. --start-address=address
  87.     从指定地址开始显示数据,该选项影响-d、-r和-s选项的输出。

  88. --stop-address=address
  89.     显示数据直到指定地址为止,该选项影响-d、-r和-s选项的输出。

  90. --syms
  91. -t 显示文件的符号表入口。类似于nm -s提供的信息

  92. --dynamic-syms
  93. -T 显示文件的动态符号表入口,仅仅对动态目标文件有意义,比如某些
  94.    共享库。它显示的信息类似于 nm -D|--dynamic 显示的信息。

  95. --version 版本信息

  96.     objdump --version

  97. --all-headers
  98. -x 显示所有可用的头信息,包括符号表、重定位入口。-x 等价于
  99.    -a -f -h -r -t 同时指定。

  100.     objdump -x inet.o

  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. int bss_array[1024*1024]; //4MB 未初始化 bss段
  4.                 // objdump -h hello | grep bss
  5.                //看到 bss段4 MB 大小
  6. int main(int argc, char *argv[])
  7. {
  8.         printf("hello world.\n");
  9.         int a;
  10.         a = 1024;
  11.         char b[] = "abcdefg";
  12.         exit(EXIT_SUCCESS);
  13. }
gcc hello.c -g -o hello

ywx@yuweixian:~/yu/c/test$ objdump -j .text -Sl hello |

more


  1. 080483e4 <main>:
  2. main():
  3. /home/ywx/yu/c/test/hello.c:7
  4. #include <stdlib.h>

  5. int bss_array[1024*1024]; //4MB

  6. int main(int argc, char *argv[])
  7. {
  8.  80483e4:    55     push %ebp
  9.  80483e5:    89 e5     mov %esp,%ebp
  10.  80483e7:    83 e4 f0     and $0xfffffff0,%esp
  11.  80483ea:    83 ec 30     sub $0x30,%esp
  12.  80483ed:    8b 45 0c     mov 0xc(%ebp),%eax
  13.  80483f0:    89 44 24 1c     mov %eax,0x1c(%esp)
  14.  80483f4:    65 a1 14 00 00 00     mov %gs:0x14,%eax
  15.  80483fa:    89 44 24 2c     mov %eax,0x2c(%esp)
  16.  80483fe:    31 c0     xor %eax,%eax
  17. /home/ywx/yu/c/test/hello.c:8
  18.     printf("hello world.\n");
  19.  8048400:    c7 04 24 00 85 04 08     movl $0x8048500,(%esp)
  20.  8048407:    e8 04 ff ff ff     call 8048310 <puts@plt>
  21. /home/ywx/yu/c/test/hello.c:12
  22. //    return 0;

  23.     int a;
  24.     a = 1024;
  25.  804840c:    c7 44 24 20 00 04 00     movl $0x400,0x20(%esp)
  26.  8048413:    00
  27. /home/ywx/yu/c/test/hello.c:13
  28.     char b[] = "abcdefg";
  29.  8048414:    a1 0d 85 04 08     mov 0x804850d,%eax
  30.  8048419:    8b 15 11 85 04 08     mov 0x8048511,%edx
  31.  804841f:    89 44 24 24     mov %eax,0x24(%esp)
  32.  8048423:    89 54 24 28     mov %edx,0x28(%esp)
  33. /home/ywx/yu/c/test/hello.c:14
  34.     exit(EXIT_SUCCESS);



阅读(2287) | 评论(0) | 转发(1) |
0

上一篇:VMA & LMA

下一篇:GCC(v4.1.2)编译器分析

给主人留下些什么吧!~~