dbx使用

1、当程序发生Segmentation fault错误时,会生成core文件,用dbx定位那行代码引起的
$ dbx pgm core
Type 'help' for help.
warning: The core file is not a fullcore. Some info may
not be available.
[using memory image in core]
reading symbolic information ...

Segmentation fault in main at line 122
122       printf("pint: %dn", *pint); //要在这里输出源码,cc编译时必须指定-g选项
2、当程序运行进入死循环不退出时,attach进程,定位程序正在执行的代码位置
例如pgm程序一直运行不结束
$ ps -ef|grep pgm
usr1 1347736 483328 115 11:28:58 pts/1 0:06 pgm
usr1 1507512 667666   0 11:29:06 pts/7 0:00 grep pgm
$ dbx -a 1347736
Waiting to attach to process 1347736 ...
Successfully attached to pgm.
Type 'help' for help.
reading symbolic information ...
stopped in unnamed block in main at line 26
   26   while (1){
(dbx) quit //pgm程序同时会结束运行,但可以先detach这个进程再退出。
4)查看运行中变量值,dump当前proc中的所有变量
(dbx) dump
main(), line 40 in "pgm.c"
pint = 0x2ff22ba0
pintvar = 5
pstring = ""
__func__ = "main"
(dbx)
如果需要查看某个内存地址值,命令:address/mode
例如pint指针地址(pint_addr: 804399856),二进制为:0x2ff22af0,
(dbx) 0x2ff22af0/D   //按十进制打印一个长字
0x2ff22af0: 5

$man ulimit

ulimit Command

Purpose

       Sets or reports user resource limits.

Syntax

       ulimit [ -H ] [ -S ] [ -a ] [ -c ] [ -d ] [ -f ] [ -m ] [ -n ] [ -r ] [ -s ] [ -t ] [-u ][ Limit ]

Description

       The ulimit command sets or reports user process resource limits, as defined in the /etc/security/limits file. This file
       contains these default limits:

       fsize = 2097151
       core = 2097151
       cpu = -1
       data = 262144
       rss = 65536
       stack = 65536
       nofiles = 2000
       threads = -1
       nproc = -1

       These values are used as default settings when a new user is added to the system. The values are set with the mkuser
       command when the user is added to the system, or changed with the chuser command.

       Limits are categorized as either soft or hard. With the ulimit command, you can change your soft limits, up to the maximum
       set by the hard limits. You must have root user authority to change resource hard limits.

test $ ulimit -c
0
test $ ulimit -c 1000
test $ ulimit -c
1000

#&g_test/16x 显示从 g_test 的地址开始处,连续 16 个 WORD(?byte)的取值

列举寄存器内容:

(dbx) registers

 

显示寄存器中变量值,例如显示$r0的值 

(dbx)p $r0

0x100001bc