跳转至

Software Debug


Overview

GDB

Build

Bash
g++ -g fun.cpp

Start GDB

Bash
gdb a.out [--tui] # or open TUI by Ctrl-X-O after entering gdb

Usage

Bash
(gdb) directory
(gdb) show directories

(gdb) set args xxx
(gdb) show args

(gdb) i r

(gdb) set print pretty
(gdb) p /d var # /x /o /t /f /c 
(gdb) p &var
(gdb) p var = 20
(gdb) p sizeof(long)
(gdb) set print array on

(gdb) x addr

(gdb) bt
(gdb) info frame
(gdb) info args
(gdb) info locals
(gdb) info catch

Debug Utils

  • dmesg

    Bash
    dmesg | tail
    

  • readelf

  • strace

  • addr2line

    Bash
    # 根据 函数地址,查看函数名
    addr2line -e a.out 0x4004e5 -f [--demangle=gnu-v3]
    

  • nm: list symbols from object files

    Bash
    nm libhello.so
    

  • strip

  • Backward-cpp: a beautiful stack trace pretty printer for C++

  • od: dump files in octal and other formats

  • objdump: display information from object files

    Bash
    # 查看.so文件的依赖关系
    objdump -x libxxx.so | grep NEEDED
    
    # 查看动态库和静态库是32位,还是64位
    file *.so  # 动态库
    objdump -x *.a  # 静态
    

  • ldd: print shared object dependencies

    Bash
    ldd /bin/lnlibc.so.6
    

  • WinDbg

    • 不仅可以用于Kernel模式调试和用户模式调试,还可以调试Dump文件
    • Dump文件是进程的内存镜像,可以把程序的执行状态通过调试器保存到dump文件中
  • SxsTrace: 跟踪调试应用程序

Bug Manager

  • bugclose: 云端BUG管理工具
  • Bugzilla is server software designed to help you manage software development.