プロセスのメモリ内容をダンプする

  • 投稿者:
  • 投稿カテゴリー:Linux

参考URL

パクりました。
http://blog.akagi.jp/archives/128.html

gdb

The GNU Project Debugger
Linuxで標準的に使われるフリーのデバッグ用ソフト(デバッガ)

インストールと確認方法

### インストール ###
root@hostname:/home/shimizu# aptitude install gdb
以下の新規パッケージがインストールされます:
  gdb gdbserver{a} libc6-dbg{a}
...
root@hostname:/home/shimizu# ps afx | grep [a]pache2
 3627 ?        Ss     1:05 /usr/sbin/apache2 -k start
15435 ?        S      0:00  \_ /usr/sbin/apache2 -k start
15442 ?        S      0:00  \_ /usr/sbin/apache2 -k start

### ダンプする ###
root@hostname:/home/shimizu# gdb
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) attach 3627
Attaching to process 3627
Reading symbols from /usr/sbin/apache2...(no debugging symbols found)...done.
Reading symbols from /lib/x86_64-linux-gnu/libpcre.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libpcre.so.3
...

(gdb) gcore memory.text
warning: target file /proc/3627/cmdline contained unexpected null characters
warning: Memory read failed for corefile section, 8192 bytes at 0x7ffc84899000.
Saved corefile memory.text
(gdb) detach
Detaching from program: /usr/sbin/apache2, process 3627
(gdb) quit

### バイナリエディタで閲覧する ###
root@hostname:/home/shimizu# od memory.text
417444000 077457 000000 062141 072144 070171 000145 063456 000172
417444020 000000 000000 072056 075147 077400 000000 062141 072144
417444040 070171 000145 061056 031172 000000 000000 062141 066144
...