查看程序符号表的几个命令

objdump -t xxx.o

weeds@weeds-ThinkPad-T440p:~/Documents/encrypchip$ objdump -t main.o

main.o:     file format elf32-little

SYMBOL TABLE:
00000000 l    df *ABS*  00000000 main.c
00000000 l    d  .text  00000000 .text
00000000 l    d  .data  00000000 .data
00000000 l    d  .bss   00000000 .bss
00000000 l    d  .mdebug.abi32  00000000 .mdebug.abi32
00000000 l    d  .rodata    00000000 .rodata
00000000 l    d  .reginfo   00000000 .reginfo
00000000 l    d  .pdr   00000000 .pdr
00000000 l    d  .comment   00000000 .comment
00000000 l    d  .gnu.attributes    00000000 .gnu.attributes
00000000 g     F .text  000000dc demo1
00000000         *UND*  00000000 GetIdChipSerialNo
00000000         *UND*  00000000 printf
00000000         *UND*  00000000 putchar
000000dc g     F .text  0000027c demo2
00000000         *UND*  00000000 _alpu_rand
00000000         *UND*  00000000 gettimeofday
00000000         *UND*  00000000 alpuc_process
00000000         *UND*  00000000 puts
00000358 g     F .text  0000003c main

readelf -h xxx.o

weeds@weeds-ThinkPad-T440p:~/Documents/encrypchip$ readelf  -h main.o 
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          1624 (bytes into file)
  Flags:                             0x1005, noreorder, cpic, o32, mips1
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         15
  Section header string table index: 12

readelf -s main.o

weeds@weeds-ThinkPad-T440p:~/Documents/encrypchip$ readelf  -s main.o 

Symbol table '.symtab' contains 21 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
    0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
 1: 00000000     0 FILE    LOCAL  DEFAULT  ABS main.c
 2: 00000000     0 SECTION LOCAL  DEFAULT    1 
 3: 00000000     0 SECTION LOCAL  DEFAULT    3 
 4: 00000000     0 SECTION LOCAL  DEFAULT    4 
 5: 00000000     0 SECTION LOCAL  DEFAULT    8 
 6: 00000000     0 SECTION LOCAL  DEFAULT    9 
 7: 00000000     0 SECTION LOCAL  DEFAULT    5 
 8: 00000000     0 SECTION LOCAL  DEFAULT    6 
 9: 00000000     0 SECTION LOCAL  DEFAULT   10 
10: 00000000     0 SECTION LOCAL  DEFAULT   11 
11: 00000000   220 FUNC    GLOBAL DEFAULT    1 demo1
12: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND GetIdChipSerialNo
13: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND printf
14: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND putchar
15: 000000dc   636 FUNC    GLOBAL DEFAULT    1 demo2
16: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND _alpu_rand
17: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND gettimeofday
18: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND alpuc_process
19: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND puts
20: 00000358    60 FUNC    GLOBAL DEFAULT    1 main

nm xxx.o 对比g++编译程序生成的符号表与gcc生成的不同点。

weeds@weeds-ThinkPad-T440p:~/Documents/encrypchip$ nm main.o #g++ compile
     U _Z10_alpu_randv
     U _Z13alpuc_processPhS_
     U _Z17GetIdChipSerialNoPh
00000000 T _Z5demo1v
000000dc T _Z5demo2v
     U gettimeofday
00000358 T main
     U printf
     U putchar
     U puts

weeds@weeds-ThinkPad-T440p:~/Documents/encrypchip$ mipsel-openwrt-linux-gcc -c main.c 
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
weeds@weeds-ThinkPad-T440p:~/Documents/encrypchip$ nm main.o #gcc compile
     U GetIdChipSerialNo
     U _alpu_rand
     U alpuc_process
00000000 T demo1
000000dc T demo2
         U gettimeofday
00000358 T main
     U printf
     U putchar
     U puts
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: Windbg 是一种在 Windows 操作系统下进行调试的工具,可以帮助开发人员识别并解决程序中的错误。由于 Windows 使用符号表(Symbol tables)来存储可执行文件和模块文件中的符号名称和地址信息,所以为了更准确地调试程序,我们需要下载符号表。 Windbg 自带了一个命令程序名为 SymChk,它可以搜索符号服务器以获取可执行文件和程序库的符号表。下面是下载符号表的步骤: 1. 打开 Windbg。 2. 在 Windbg 中打开需要调试的程序。此时,Windbg 可能会提示无法加载符号文件。 3. 在 Windbg 的命令行界面中,输入以下命令: .sympath SRV*c:\symbols*http://msdl.microsoft.com/download/symbols 其中,c:\symbols 是本地符号目录,通常情况下是新建一个空文件夹作为符号目录;http://msdl.microsoft.com/download/symbols 是微软的符号服务器地址。 4. 输入以下命令以开始下载符号表: .symfix c:\symbols 这个命令是告诉 Windbg 将符号文件存储到指定的符号目录。 5. 最后,在 Windbg 的命令行中输入命令: .reload /f 这个命令告诉 Windbg 重新加载程序和所有的符号表文件。 完成上述步骤之后,Windbg 就可以正确地显示程序的符号信息了。需要注意的是,如果程序使用的是自定义的符号文件而不是 Microsoft 的符号文件,则需要将符号文件添加到符号路径中。 ### 回答2: Windbg是Microsoft Windows操作系统上一种强大的调试工具,能够帮助开发者/程序员追踪和解决程序在运行时出现的各种问题。在进行Windbg调试的过程中,符号表显得尤为重要。符号表是一种包含源代码、二进制代码和调试信息的文件,它可以帮助调试器将二进制代码映射到源代码的行数和函数名上。 在Windbg中下载符号表有以下几个步骤: 第一步:打开Windbg,按"F12"键打开"命令"窗口。 第二步:在"命令"窗口中输入下列命令之一,以下载目标文件的符号表: - .symfix c:\symbols:将符号表下载到c盘上的symbols文件夹中。 - .sympath+ C:\path_to_your_symbols:在已有的符号路径中添加一个路径。 - .symproxy (proxy server):(port):在符号路径前面添加代理。 第三步:输入"!sym noisy"命令可以打开符号下载的详细输出,并且确认符号表下载正在进行。 第四步:下载完成后,在Windbg的左部窗口"Modules"中选择想要观察的模块,右键点击该模块,在弹出的菜单中选择"Symbol Load Information",即可查看符号加载的情况。 通过以上步骤,我们可以轻松下载到符号表,并且在调试程序时得到更准确和详细的调试信息,从而更好地定位和解决程序的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钱国正

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值