Prayer

在一般中寻求卓越
posts - 1256, comments - 190, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Core Dump杂记

Posted on 2009-03-13 12:07 Prayer 阅读(2193) 评论(5)  编辑 收藏 引用 所属分类: LINUX/UNIX/AIX
1、开启系统的Core Dump功能

ulimit -c core_file_size_in_kb

如果要关闭该功能core_file_size_in_kb为0就行了。

2、设置Core Dump的核心转储文件目录和命名规则

文件的命名规则放在

/proc/sys/kernel/core_name_format文件中

使用sysctl -w "kernel.core_name_format=/coredump/%n.core"

上例的core文件放在/coredump目录下,文件名是进程名+.core

以下是一些命名的格式说明

%P The Process ID (current->pid)
%U The UID of the process (current->uid)
%N The command name of the process (current->comm)
%H The nodename of the system (system_utsname.nodename)
%% A "%"


3、分析核心转储文件

程序如下:

#include

int main()

{

int i=0;

int j=5;

int tmp;

for(; i System Environments --> Change/ Show Characteristics of Operating System

Change/ Show Characteristics of Operating System
Maximum number of PROCESSES allowed per user [128]
Maximum number of pages in block I/O BUFFER CACHE [20]
Maximum Kbytes of real memory allowed for MBUFS [0]
Automatically REBOOT system after a crash false
Continuously maintain DISK I/O history false
HIGH water mark for pending write I/Os per file [33]
LOW water mark for pending write I/Os per file [24]
Amount of usable physical memory in Kbytes 262144
State of system keylock at boot time normal
Enable full CORE dump true
Use pre-430 style CORE dump false
Enable CPU Guard disable

将上面列表中的“ Enable full CORE dump ”项设置为“true”。


4. 使用下面的命令产生一个core文件:
# kill -11
注意:上面的命令同时也会杀掉指定的进程。


附录 B. 如何查看C程序产生的CORE DUMP(来源于IBM cn)
Document #: 1317181000005

环境

产品:IBM C 和C++ Compiler
平台:AIX4.3.0以上
版本: C for AIX version 3 以上

问题描述

如何查看C程序产生的CORE DUMP,并找到产生问题的根源?

解答

在AIX操作系统上查看C程序产生的CORE DUMP,可以使用AIX操作系统提供的命令:dbx. 如果用户在使用时发现无此命令,则需安装 操作系统的文件包:bos.adt.debug。
具体使用dbx命令的方法如下:
1。首先在进行C程序 编译时,要使用-g选项。
cc -g -o samp1.o samp1.c
2.在执行完程序,并产生CORE DUMP文件core后,使用:dbx samp1.o core 命令可查看CORE DUMP。
要想找到是哪个函数或语句引起的问题,在dbx的命令行再输入where,即可显示出所需的信息。dbx的命令行还可执行多种命令以完成不同的查看功能,用户可通过help命令了解这些命令。

Posted by vitter at February 21, 2006 02:14 PM

如何分析一个未知二进制文件

当你在unix下拿到一个二进制文件但不知道它是什么的时候,可以通过以下方法得到一此提示

1. 最首先应该尝试strings命令,比如拿到一个叫cr1的二进制文件,可以:
$ strings cr1 | more
里面可能会有一些对于这个cr1的描述,这些信息都是编译之后在程序中留下的一些文本性的说明,所以可能会告诉你这个文件是什么.
比如有输出:
$ strings cr1 | more

%s %s %s%s%s -> %s%s%s (%.*s)
Version: 2.3
Usage: dsniff [-cdmn] [-i interface] [-s snaplen] [-f services]
[-t trigger[,...]] [-r|-w savefile] [expression]
...
/usr/local/lib/dsniff.magic
/usr/local/lib/dsniff.services
...

那么我们就可以知道,其实 cr1就是dsniff命令.

2. 如果这样的方法没有帮助你的话,那么你可以尝试:
$ /usr/ccs/bin/nm -p cr1 | more
比如说得到如下输出:
cr1:

[Index] Value Size Type Bind Other Shndx Name
[180] |0 | 0| FILE | LOCL | 0 |ABS | decode_smtp.c
[2198] |160348| 320| FUNC | GLOB | 0 | 9 | decode_sniffer

这些都是生成这个二进制文件的obj文件的文件名称,这些名称会告诉你这个二进制文件的作用的.

同样,如果希望查看二进制文件调用到的静态库文件都有哪些的话,可以使用nm -Du cr1来实现.

3. 当然我们也可以通过使用dump命令来得到任何一个二进制文件的选定部分信息
$ /usr/ccs/bin/dump -c ./cr1 | more
dump命令的参数说明:
-c Dump出字符串表
-C Dump出C++符号表
-D Dump出调试信息
-f Dump出每个文件的头
-h Dump出section的头
-l Dump出行号信息
-L Dump出动态与静态链接库部分内容
-o Dump出每个程序的可执行头
-r Dump出重定位信息
-s 用十六进制信息Dump出section的内容
-t Dump符号表.

4. 可以使用file命令得到二进制文件的信息
$ file cr1

5. 如果还是不清楚的话,那么我们可以使用ldd命令
$ ldd cr1
比如说输出为:
...
libsocket.so.1 => /usr/lib/libsocket.so.1
librpcsvc.so.1 => /usr/lib/librpcsvc.so.1
...

那么我们就可以知道这个程序与网络库相关,我们就可以知道它的大概功能了.

我们也可以能过adb命令来得到一个二进制文件的执行过程.
比如说:
$ adb cr1
:r
Using device /dev/hme0 (promiscuous mode)
192.168.2.119 -> web TCP D=22 S=1111 Ack=2013255208
Seq=1407308568 Len=0 Win=17520
web -> 192.168.2.119 TCP D=1111 S=22 Push Ack=1407308568

我们知道这个程序是一个sniffer.

6. 如果你确定要运行这个程序的话,你可以先通过:
$ truss -f -o cr.out ./cr1
listening on hme0
^C
$

truss命令可以帮你打开系统的信号与调用输出.你就可以知道这个程序到底干了什么.

有了上面这些工具的话,我们就可以大概了解到一个未知的二进制程序到底是干什么的.

最后提示大家,运行不了解的二进制程序有严重的安全问题,请大家小心.

Posted by vitter at February 21, 2006 02:16 PM

如何分析一个二进制未知进程信息?

在unix下,所有的事物都是文件,进程也是.文件的位置在 /proc/[PID]/object/a.out.但是这样的文件并不能由find命令找到.

假设我们当前有如下的进程:

# ps -ef | more
UID PID PPID C STIME TTY TIME CMD
...
root 22889 16318 0 10:09:25 pts/1 0:00 ./srg
...

我们使用strings命令就可以知道这个程序的作用:
$ strings /proc/22889/object/a.out | more

如果我们用strings不能得到这个进程的作用的话,我们可以尝试先suspend这个进程:
$ kill -STOP 22889
然后我们使用:
$ /usr/ucb/ps | grep T
来查看已被停止进程信息,当然我们可以通过 kill -CONT 22889来恢复这个进程的运行. 我们可以通过gcore来对这个进程作一个core dump:
$ gcore 22889
生成的core.22889是这个进程的变量与堆栈信息,我们可以通过对这些信息进行分析:
$ strings core.22889 | more

我们也可以使用adb命令来对一个进程进行分析:
$ adb /proc/22889/object/a.out
这样可以有以下回复:
# adb /proc/22889/object/a.out -
main:b
:r
breakpoint at:
main: save %sp, -0xf8, %sp
...
:s
stopped at:
main+4: clr %l0
:s
stopped at:
main+8: sethi %hi(0x38400), %o0
$m
? map
...
b11 = ef632f28 e11 = ef6370ac f11 = 2f28 `/usr/lib/libsocket.so.1'
$q

这样我们就可以得到这个进程在汇编下的表示,通过分析汇编结构,我们就可以知道这个程序的作用是什么了.

也可以通过truss来对正在运行的进程进行分析:
$ truss -vall -f -o /tmp/outfile -p 22889

如果你希望查看某个进程的运行环境的话,你可以:
$ /usr/ucb/ps auxeww 22889
结果会是如下的结构:

# /usr/ucb/ps auxeww 22889
USER PID %CPU %MEM SZ RSS TT S START TIME COMMAND
root 22889 0.0 0.4 1120 896 pts/1 S 14:15:27 0:00 -
sh _=/usr/bin/csh
MANPATH=/usr/share/man:/usr/local/man HZ=
PATH=/usr/sbin:/usr/bin:/usr/local/bin:/usr/ccs/bin:/usr/local/sbin:
/opt/NSCPcom/ LOGNAME=root SHELL=/bin/ksh HOME=/
LD_LIBRARY_PATH=/usr/openwin/lib:/usr/local/lib TERM=xterm TZ=

查看某个进程的内存地址:
$ ps -ealf | grep 22889
以及内存的使用情况:
$ ps -e -opid,vsz,rss,args
PID VSZ RSS COMMAND
...
22889 3792 1728 ./srg

我们可以知道,这个进程使用了3792K的虚拟内存,其中有1728K内存留在物理内存中.


为了查询一个进程的进程结构,我们可以:
# /etc/crash
然后用p命令得到进程的slot, 并使用 p -f 来对某个进程的proc结构进行查询.

我们可以使用:
$ /usr/proc/bin/pfiles 22889
来查看这个进程打开了哪些文件

当然也可以通过
# mdb -p 22889
来得到这个进程调用的各个模块的信息

Feedback

# re: Core Dump杂记  回复  更多评论   

2010-08-12 17:41 by MalloryOsborn
I guess that to receive the <a href="http://bestfinance-blog.com">loans</a> from creditors you should have a good reason. Nevertheless, once I have got a credit loan, because I was willing to buy a bike.

# re: Core Dump杂记  回复  更多评论   

2010-08-29 06:22 by essays help
I regularly tested some essay example and found out that this company is the respectable among them. I am return client for two years and find the work of this custom essays company team productive.

# re: Core Dump杂记  回复  更多评论   

2011-07-06 00:37 by thesis
I think that you have to be awarded by the dissertation service for your best knowledge just about this post. Not a lot of people will be able to accomplish the same high quality custom dissertation.

# re: Core Dump杂记  回复  更多评论   

2011-07-06 03:24 by buy dissertation
I think it's captivating, because it displays a very academic-focussed attitude. Preserving the incorruptibility of the academic system seems to be a arrangement, although directly banning reimbursed ads for such a service seems a forceless response. When the concern is known by your friends who were captivated with the results of the collaboration, about this address that for the thesis quality.

# re: Core Dump杂记  回复  更多评论   

2013-04-17 22:50 by Essayontime.com rewiew
Have no idea which company to select to receive aid from? Glance over EssaysProfessors testimonials, and make a judicious choice.

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理