注册
达梦core文件分析
技术分享/ 文章详情 /

达梦core文件分析

小灰灰_oO 2024/03/12 1203 3 0

一、什么是coredump

我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各种异常或者bug导致在运行过程中异常退出或者中止,并且在满足一定条件下(这里为什么说需要满足一定的条件呢?下面会分析)会产生一个叫做core的文件。

通常情况下,core文件会包含了程序运行时的内存,寄存器状态,堆栈指针,内存管理信息还有各种函数调用堆栈信息等,我们可以理解为是程序工作当前状态存储生成第一个文件,许多的程序出错的时候都会产生一个core文件,通过工具分析这个文件,我们可以定位到程序异常退出的时候对应的堆栈调用等信息,找出问题所在并进行及时解决。

二、配置coredump

1、查看生成core文件是否开启

$ ulimit -a -t: cpu time (seconds) unlimited -f: file size (blocks) unlimited -d: data seg size (kbytes) unlimited -s: stack size (kbytes) 8192 -c: core file size (blocks) 0 -m: resident set size (kbytes) unlimited -u: processes 14014 -n: file descriptors 65535 -l: locked-in-memory size (kbytes) 64 -v: address space (kbytes) unlimited -x: file locks unlimited -i: pending signals 14014 -q: bytes in POSIX msg queues 819200 -e: max nice 0 -r: max rt priority 0 -N 15: unlimited

core file size = 0,说明core文件没有开启

如果core没有开启,则不会生成core文件

2、临时设置core文件

使用ulimit -c [kbytes]可以设置系统允许生成的core文件大小

ulimit -c 0 不产生core文件 ulimit -c 500 设置core文件最大为500k ulimit -c unlimited 不限制core文件大小 $ ulimit -c unlimited #查看配置 $ ulimit -a -t: cpu time (seconds) unlimited -f: file size (blocks) unlimited -d: data seg size (kbytes) unlimited -s: stack size (kbytes) 8192 -c: core file size (blocks) unlimited -m: resident set size (kbytes) unlimited -u: processes 14014 -n: file descriptors 65535 -l: locked-in-memory size (kbytes) 64 -v: address space (kbytes) unlimited -x: file locks unlimited -i: pending signals 14014 -q: bytes in POSIX msg queues 819200 -e: max nice 0 -r: max rt priority 0 -N 15: unlimited

3、永久设置core文件

修改/etc/profile文件,添加参数

$ echo 'ulimit -c unlimited' >> /etc/profile $ source /etc/profile

4、查看/修改core的生成路径

4.1 查看core生成路径

$ cat /proc/sys/kernel/core_pattern /dmdata/core/core-%e-%p-%s

4.2 修改core生成路径

core文件统一生成指定到/dmdata/core目录下,产生的文件名为core-命令名-pid-信号

$ vi /etc/sysctl.conf kernel.core_pattern =/dmdata/core/core-%e-%p-%s $ sysctl -p #生效

core文件名参数列表

参数 说明
%p 添加pid(进程id)
%u 添加当前uid(用户id)
%g 添加当前gid(用户组id)
%s 添加导致产生core的信号
%t 添加core文件生成时的unix时间
%h 添加主机名
%e 添加导致产生core的命令名

三、手动杀掉DM生成Core

1、创建表

CREATE TABLE T(ID INT); INSERT INTO T SELECT LEVEL FROM DUAL CONNECT BY LEVEL <10000500;

2、使用kill -11强杀进程

$ ps -ef|grep dmdba dmdba 2837894 1 0 14:49 ? 00:00:01 /home/dmdba/dmdbms/bin/dmap dmdba 2848517 1 0 20:49 ? 00:00:05 /home/dmdba/dmdbms/bin/dmserver path=/dmdata/data/DAMENG/dm.ini -noconsole $ kill -11 2848517 # 生成了core文件 $ ls /dmdata/core/ core-dmserver-2848517-8

3、GDB分析core文件

3.1 GDB常用命令

命令 说明
bt 查看当前线程的栈信息
thread apply all bt 查看所有线程堆栈,通常会由此查看是否有自己实现的类或者so库。一般会把所有线程的详细栈信息输出到一个文件里面如thread_info.txt
thread id 将线程编号为 id 的线程设置为当前线程。
info threads [id…] 可以查看当前调试环境下存在的线程数以及各线程的具体信息,也可以通过指定线程的编号查看某个线程的具体信息。

3.2 读取core文件

$ gdb 产生core的命令名 core文件
$ gdb dmserver core-dmserver-2848517-8 GNU gdb (GDB) Red Hat Enterprise Linux 9.2-7.1.0.4.al8 Copyright (C) 2020 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-redhat-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 dmserver... Reading symbols from /home/dmdba/dmdbms/bin/dmserver_s.debug... ......

3.3 定义存储堆栈信息的文件名

(gdb) set logging file core_2848517.txt (gdb) set logging on Copying output to core_2848517.txt. Copying debug output to core_2848517.txt.

3.4 打印保存所有线程的堆栈信息

(gdb) thread apply all bt Thread 86 (Thread 0x7ff2e63e5640 (LWP 2848563)): ......

3.5 停止向txt文件中写入堆栈信息

(gdb) set logging off Done logging to core_2848517.txt.

4、使用dmrdc工具分析core文件,并生成SQL语句

$ dmrdc sfile=/dmdata/core/core-dmserver-2848517-8 dfile=/dmdata/core/core_sql dmrdc V8 Analysing: 0/3096002560 Analysing: 31457268/3096002560 Analysing: 62914536/3096002560 ...... Analysing: 3082812264/3096002560 6.116 s $ ls -l /dmdata/core total 676856 -rw-r--r-- 1 dmdba dinstall 62610 Mar 10 22:18 core_2848517.txt -rw------- 1 dmdba dinstall 3096002560 Mar 10 21:59 core-dmserver-2848517-8 -rw-r--r-- 1 dmdba dinstall 102 Mar 10 22:35 core_sql

5、查看core语句

$ cat core_sql !#%&*^$@[2852035]:INSERT INTO T SELECT LEVEL FROM DUAL CONNECT BY LEVEL <10000500;

结合dmrdc的结果对应的SQL语句(从dmrdc的结果中找对应的2852035线程号,去core_2848517.txt文件中查找线程2852035的堆栈信息进行分析。)

评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服