骑麦兜看落日

[Linux]GDB源码调试

字数统计: 318阅读时长: 1 min
2018/09/10 Share

strip命令

linux的strip指令可以丢弃文件的符号信息

gcc通过-g参数保留符号信息

可以通过file命令查看文件是否去掉符号


安装dbg

查看更新源cat /etc/apt/sources.list,这里使用清华的镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

deb为binary仓库,deb-src为源码仓库

由于需要源码仓库,所以把deb-src的注释去掉

安装libc6-dbg

1
2
sudo apt install libc6-dbg  
sudo apt install libc6-dbg:i386

下载源码

1
sudo apt source libc6-dev

Debug

在gdb中用directory指定源码地址

1
directory ~/glibc-2.23/example

参考资料

CATALOG
  1. 1. strip命令
  2. 2. 安装dbg
  3. 3. 下载源码
  4. 4. Debug
  5. 5. 参考资料