免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 738 | 回复: 0
打印 上一主题 下一主题

Linux几个程序员常用的工具 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-22 22:12 |只看该作者 |倒序浏览
1. ldd:检查共享库的倚赖,即检查程序所用的共享库
例子:
->localhost:ldd ex1
        linux-gate.so.1 =>  (0x00110000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x07e32000)
        libm.so.6 => /lib/libm.so.6 (0x00522000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00da1000)
        libc.so.6 => /lib/libc.so.6 (0x003c7000)
        /lib/ld-linux.so.2 (0x003a8000)
->localhost:
2. nm: 列出目标文件的所有符号
->localhost:nm ex1
0804a1c8 d _DYNAMIC
0804a2ac d _GLOBAL_OFFSET_TABLE_
08048aca t _GLOBAL__I_main
...
08048af6 T main
         U puts@@GLIBC_2.0
3. objdump: 显示目标文件的信息,这个工具对从事编译工具程序员非常有用
->localhost:objdump -h a.out
a.out:     file format elf32-i386
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .interp       00000013  08048134  08048134  00000134  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  1 .note.ABI-tag 00000020  08048148  08048148  00000148  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 .note.gnu.build-id 00000024  08048168  08048168  00000168  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .gnu.hash     00000020  0804818c  0804818c  0000018c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .dynsym       00000050  080481ac  080481ac  000001ac  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
4. valgrind: 用来检测内存泄露
#include
main()
{
  char *ptr = (char*)malloc(1024*sizeof(char));
  ptr = "hello world";
  printf("%s\n", ptr);
}
将以上文件保存为exam4.c, 用gcc编译生成可执行文件。
gcc -o exam4 exam4.c
然后运行: ->localhost: valgrind ./exam4
==3381== Memcheck, a memory error detector.
==3381== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==3381== Using LibVEX rev 1732, a library for dynamic binary translation.
==3381== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==3381== Using valgrind-3.2.3, a dynamic binary instrumentation framework.
==3381== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==3381== For more details, rerun with: -v
==3381==
hello world
==3381==
==3381== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 12 from 1)
==3381== malloc/free: in use at exit: 1,024 bytes in 1 blocks.
==3381== malloc/free: 1 allocs, 0 frees, 1,024 bytes allocated.
==3381== For counts of detected errors, rerun with: -v
==3381== searching for pointers to 1 not-freed blocks.
==3381== checked 47,700 bytes.
==3381==
==3381== LEAK SUMMARY:
==3381==    definitely lost: 1,024 bytes in 1 blocks.
==3381==      possibly lost: 0 bytes in 0 blocks.
==3381==    still reachable: 0 bytes in 0 blocks.
==3381==         suppressed: 0 bytes in 0 blocks.
==3381== Rerun with --leak-check=full to see details of leaked memory.
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43765/showart_482406.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP