Linux高级调试与优化——同时抓取coredump和maps文件
Linux内核源码 Documentation/sysctl/kernel.txt core_pattern:
core_pattern: core_pattern is used to specify a core dumpfile pattern name.
. max length characters; default value is "core"
. core_pattern is used as a pattern template for the output filename;
certain string patterns (beginning with '%') are substituted with
their actual values.
. backward compatibility with core_uses_pid:
If core_pattern does not include "%p" (default does not)
and core_uses_pid is set, then .PID will be appended to
the filename.
. corename format specifiers:
%<NUL> '%' is dropped
%% output one '%'
%p pid
%P global pid (init PID namespace)
%i tid
%I global tid (init PID namespace)
%u uid
%g gid
%d dump mode, matches PR_SET_DUMPABLE and
/proc/sys/fs/suid_dumpable
%s signal number
%t UNIX time of dump
%h hostname
%e executable filename (may be shortened)
%E executable path
%<OTHER> both are dropped
. If the first character of the pattern is a '|', the kernel will treat
the rest of the pattern as a command to run. The core dump will be
written to the standard input of that program instead of to a file.
步骤
1)编写coredump.sh脚本,放到/usr/local/目录
#!bin/bash #/proc/<pid>/maps
cat /proc/$/maps > /tmp/maps_of_$ #coredump
dd > /tmp/core_$1_$2_$
2)执行以下命令配置coredump
ulimit -c unlimited echo "|/usr/local/coredump.sh %p %e %s" > /proc/sys/kernel/core_pattern
完成配置,这样发生应用程序异常之后,如果触发coredump,就会抓取/proc/<pid>/maps文件并转储coredump文件。
测试
1)触发coredump
root@chgao-virtual-machine:/media/new/linyao/debugging/SIGFPE# ./test
Floating point exception
2)进入/tmp查看是否抓取到coredump和maps文件
root@chgao-virtual-machine:/tmp# ls
core_8124_test_8 maps_of_8124
root@chgao-virtual-machine:/tmp# file core_8124_test_8
core_8124_test_8: ELF -bit LSB core file x86-, version (SYSV), SVR4-style, from './test'
root@chgao-virtual-machine:/tmp# file maps_of_8124
maps_of_8124: ASCII text
3)查看maps文件
root@chgao-virtual-machine:/tmp# cat maps_of_8124
- r-xp fc: /media/new/linyao/debugging/SIGFPE/test
- r--p fc: /media/new/linyao/debugging/SIGFPE/test
- rw-p fc: /media/new/linyao/debugging/SIGFPE/test
7fad5d07a000-7fad5d23a000 r-xp : /lib/x86_64-linux-gnu/libc-2.23.so
7fad5d23a000-7fad5d43a000 ---p 001c0000 : /lib/x86_64-linux-gnu/libc-2.23.so
7fad5d43a000-7fad5d43e000 r--p 001c0000 : /lib/x86_64-linux-gnu/libc-2.23.so
7fad5d43e000-7fad5d440000 rw-p 001c4000 : /lib/x86_64-linux-gnu/libc-2.23.so
7fad5d440000-7fad5d444000 rw-p :
7fad5d444000-7fad5d46a000 r-xp : /lib/x86_64-linux-gnu/ld-2.23.so
7fad5d64b000-7fad5d64e000 rw-p :
7fad5d669000-7fad5d66a000 r--p : /lib/x86_64-linux-gnu/ld-2.23.so
7fad5d66a000-7fad5d66b000 rw-p : /lib/x86_64-linux-gnu/ld-2.23.so
7fad5d66b000-7fad5d66c000 rw-p :
7ffc833d2000-7ffc833f3000 rw-p : [stack]
7ffc833f5000-7ffc833f8000 r--p : [vvar]
7ffc833f8000-7ffc833fa000 r-xp : [vdso]
ffffffffff600000-ffffffffff601000 r-xp : [vsyscall]
4)使用gdb调试coredump文件
root@chgao-virtual-machine:/media/new/linyao/debugging/SIGFPE# gdb ./test /tmp/core_8124_test_8
GNU gdb (Ubuntu 7.11.-0ubuntu1~16.5) 7.11.
Copyright (C) Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 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"...
Reading symbols from ./test...done.
[New LWP ] warning: the debug information found in "/lib64/ld-2.23.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch). Core was generated by `./test'.
Program terminated with signal SIGFPE, Arithmetic exception.
# 0x00000000004004f3 in main (argc=, argv=0x7ffc833f1658) at test.c:
result = a / b;
(gdb) info registers
rax 0x2
rbx 0x0
rcx 0x0
rdx 0x0
rsi 0x7ffc833f1658
rdi 0x1
rbp 0x7ffc833f1570 0x7ffc833f1570
rsp 0x7ffc833f1570 0x7ffc833f1570
r8 0x400570
r9 0x7fad5d454ab0
r10 0x846
r11 0x7fad5d09a740
r12 0x4003e0
r13 0x7ffc833f1650
r14 0x0
r15 0x0
rip 0x4004f3 0x4004f3 <main+>
eflags 0x10246 [ PF ZF IF RF ]
cs 0x33
ss 0x2b
ds 0x0
es 0x0
fs 0x0
gs 0x0
(gdb) bt
# 0x00000000004004f3 in main (argc=, argv=0x7ffc833f1658) at test.c:
Linux高级调试与优化——同时抓取coredump和maps文件的更多相关文章
- Linux高级调试与优化——gdb调试命令
		
番外 2019年7月26日至27日,公司邀请<软件调试>和<格蠹汇编——软件调试案例集锦>两本书的作者张银奎老师进行<Linux高级调试与优化>培训,有幸聆听张老师 ...
 - Linux高级调试与优化——内存管理
		
1.物理地址和虚拟地址 Linux采用页表机制管理内存,32位系统中页大小一般为4KB,物理内存被划分为连续的页,每一个页都有一个唯一的页号. 为了程序的的可移植性,进程往往需要运行在flat mem ...
 - Linux高级调试与优化——信号量机制与应用程序崩溃
		
背景介绍 Linux分为内核态和用户态,用户态通过系统调用(syscall)进入内核态执行. 用户空间的glibc库将Linux内核系统调用封装成GNU C Library库文件(兼容ANSI &am ...
 - Linux高级调试与优化——内存泄漏实战分析
		
最近在整理Linux调试方面的文档,正好碰到了一个内存泄漏踩栈的问题,借此机会记录一下分析过程. 首先,发现问题之后,赶紧看一下产生coredump文件没有,果不其然,产生了coredump,果断上g ...
 - Linux高级调试与优化——ptrace
		
ptrace (process trace) #include <sys/ptrace.h> long ptrace(enum __ptrace_request request, pid_ ...
 - Linux高级调试与优化——用户态堆
		
内存问题是软件世界的住房问题 嵌入式Linux系统中,物理内存资源通常比较紧张,而不同的进程可能不停地分配和释放不同大小的内存,因此需要一套高效的内存管理机制. 内存管理可以分为三个层次,自底向上分别 ...
 - Linux高级调试与优化——Address Sanitizer
		
Address Sanitizer ASAN最早可以追溯到 LLVM 的 sanitizers项目(https://github.com/google/sanitizers),这个项目包含了Addre ...
 - Linux高级调试与优化——进程管理和调度
		
进程管理 进程和文件是Linux操作系统的两个最基本的抽象. 进程是处于执行期的程序,进程不仅仅局限于一段可执行程序代码,通常还包含其他资源,如打开的文件.挂起的信号.内核内部数据.处理器状态.进程地 ...
 - "用wow64exts调试64位任务管理器抓取的32位程序的dump"
		
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:"用wow64exts调试64位任务管理器抓取的32位程序的dump".
 
随机推荐
- 14 Scrapy中selenium的应用
			
在通过scrapy框架进行某些网站数据爬取的时候,往往会碰到页面动态数据加载的情况发生,如果直接使用scrapy对其url发请求,是绝对获取不到那部分动态加载出来的数据值.但是通过观察我们会发现,通过 ...
 - SpringMVC基础03——常用注解之@RequestMapping
			
1.用法 SpringMVC使用@RequestMapping注解,为控制器指定可以处理哪些URL请求,并且可以指定处理请求的类型(POST/GET),如果@RequestMapping没有指定请求的 ...
 - python、第八篇:索引原理与慢查询优化
			
一 介绍 1. 为何要有索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,在生产环境中,我们遇到最多的,也是最容易出问题的,还是一些复杂的查询操作,因此对查 ...
 - poj 2081 Recaman's Sequence (dp)
			
Recaman's Sequence Time Limit: 3000MS Memory Limit: 60000K Total Submissions: 22566 Accepted: 96 ...
 - 一、Nginx多站点配置
			
一.下载 目录文件: 二.运行方式 (1)直接双击nginx.exe,双击后一个黑色的弹窗一闪而过 (2)打开cmd命令窗口,切换到nginx解压目录下,输入命令 nginx.exe 或者 start ...
 - Lua语言基本语法~运算符
			
Lua 变量 变量在使用前,必须在代码中进行声明,即创建该变量. 编译程序执行代码之前编译器需要知道如何给语句变量开辟存储区,用于存储变量的值. Lua 变量有三种类型:全局变量.局部变量.表中的域. ...
 - 牛客练习赛44  A	小y的序列 (模拟,细节)
			
链接:https://ac.nowcoder.com/acm/contest/634/A 来源:牛客网 小y的序列 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语 ...
 - 一个tornado框架下的文件上传案例
			
html部分----使用了form表单,注意三要素 method="post" action="/loaddata" enctype="multip ...
 - IDEA创建spring加struts2项目
			
选择spring和struts,注意版本,不同的struts版本,过滤器的位置不一样 选择存放位置,并点击完成创建项目,在创建过程中会自动下载相关jar 初始化完成后的目录结构为 修复生成的web.x ...
 - Docker安装Mysql和Nginx
			
1. 序言 将应用容器化更方便于管理,昨天辛辛苦苦安装在宿主机上的,今天狠心重置服务器,学下docker练练手. 2. Get start 2.1 安装Docker 公司的云用的是ubuntu,我自己 ...