Posts 有关linux配置 core dump 调试等一些问题
Post
Cancel

有关linux配置 core dump 调试等一些问题

1. 有关linux 配置文件

1
主要区分 全局配置 用户配置 over
  1. profile 全局, 全用户配置

一般不建议在/etc/profile文件中添加环境变量,因为在这个文件中添加的设置会对所有用户起作用。

  1. bashrc

    • 系统级 /etc/bashrc,对所有用户生效
    • 用户级 ~/.bashrc,仅对当前用户生效。
  2. bash_profile

bash_profile只对单一用户有效,文件存储位于~/.bash_profile

配置读取顺序: 先全局 后用户。

可以自定义一个环境变量文件,比如在某个项目下定义uusama.profile,在这个文件中使用export定义一系列变量,然后在~/.profile文件后面加上:sourc uusama.profile,这样你每次登陆都可以在Shell脚本中使用自己定义的一系列变量。

也可以使用alias命令定义一些命令的别名,比如alias rm=”rm -i”(双引号必须),并把这个代码加入到~/.profile中,这样你每次使用rm命令的时候,都相当于使用rm -i命令,非常方便。

链接,这个写的比较好

2. 有关core dump

  1. 大小配置

    1
    2
    
     ulimit -c  // 查询
     ulimit -c unlimited  // 设置
    
  2. core 路径

    1
    
     cat /proc/sys/kernel/core_pattern
    

调试记录

源文件

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
        int *p=NULL;
        *p=10;
        cout<<*p<<"\n";
        return 0;
}

编译

1
$ g++ -g test.cpp -o test

运行产生core 文件

1
2
~/core_dump$ ./test 
Segmentation fault (core dumped)

core 文件调试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/mnt/wslg/dumps$ gdb ~/core_dump/test core.test 
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 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"...
Reading symbols from /home/xm/core_dump/test...done.
[New LWP 1010]
BFD: /usr/lib/debug/.build-id/18/78e6b475720c7c51969e69ab2d276fae6d1dee.debug: unable to initialize decompress status for section .debug_aranges
BFD: /usr/lib/debug/.build-id/18/78e6b475720c7c51969e69ab2d276fae6d1dee.debug: unable to initialize decompress status for section .debug_aranges

warning: File "/usr/lib/debug/.build-id/18/78e6b475720c7c51969e69ab2d276fae6d1dee.debug" has no build-id, file skipped
BFD: /usr/lib/debug/.build-id/fe/91b4090ea04c1559ff71dd9290062776618891.debug: unable to initialize decompress status for section .debug_aranges
BFD: /usr/lib/debug/.build-id/fe/91b4090ea04c1559ff71dd9290062776618891.debug: unable to initialize decompress status for section .debug_aranges

warning: File "/usr/lib/debug/.build-id/fe/91b4090ea04c1559ff71dd9290062776618891.debug" has no build-id, file skipped
BFD: /usr/lib/debug/.build-id/45/87364908de169dec62ffa538170118c1c3a078.debug: unable to initialize decompress status for section .debug_aranges
BFD: /usr/lib/debug/.build-id/45/87364908de169dec62ffa538170118c1c3a078.debug: unable to initialize decompress status for section .debug_aranges

warning: File "/usr/lib/debug/.build-id/45/87364908de169dec62ffa538170118c1c3a078.debug" has no build-id, file skipped
Core was generated by `./test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000056159fbcd1c1 in main () at test.cpp:7
7               *p=10;
(gdb) bt
#0  0x000056159fbcd1c1 in main () at test.cpp:7
(gdb) l
2       #include <iostream>
3       #include <cstdio>
4       using namespace std;
5       int main() {
6               int *p=NULL;
7               *p=10;
8               cout<<*p<<"\n";
9               return 0;
10      }
11
(gdb) 
  • info f 打印当前栈信息

  • info args 打印出当前函数的参数名及其值。

  • info locals 打印出当前函数中所有局部变量及其值。

  • info catch 打印出当前的函数中的异常处理信息。

This post is licensed under CC BY 4.0 by the author.

Contents

Trending Tags