Chinaunix首页 | 论坛 | 博客
  • 博客访问: 134356
  • 博文数量: 51
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 540
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-21 12:33
文章分类

全部博文(51)

文章存档

2011年(1)

2010年(5)

2009年(1)

2008年(12)

2007年(32)

我的朋友

分类: LINUX

2008-02-22 22:12:33

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.




阅读(962) | 评论(0) | 转发(0) |
0

上一篇:perl CGI编程之文件上传

下一篇:SCTP编程

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