我的.gdbinit

############################################################
#########  GDBINIT FILE FOR JERRY MAX VERSION 1.0 ##########
############################################################

# Display 
############################################################
define dip
display /i $pc
end
document dip
print next introduction after each cmd
end
############################################################
define ls
set listsize 20
list
end
document ls
show source file with 20 lines
end
############################################################


# Info 
############################################################
define ia
info args
end
document ia
pirnt args val
end
############################################################
define il
info locals
end
document il
print local variables
end
############################################################
define ir
info reg
end
document ir
print register val
end
############################################################
define it
info threads
end
document it
pirnt threads
end
############################################################
define ifun
info function $arg0
end
document ifun
print functions with regular exp param or all functions
usage: ifun funname
end
############################################################
define ivar
info variables $arg0
end
document ivar
print variables with regular exp param or all vars
usage: ivar varname
end
############################################################
define ilib
info sharedlibrary $arg0
end
document ilib
print sharedlibrary with regular exp param or all libs
usage: ilib libname
end
############################################################
define isig
info signals $arg0
end
document isig
print signal info of signame
usage: isig signame
end
############################################################
define isigs
info signals
end
document isigs
print all signals info
end
############################################################
define r32
printf " eip:%08X\n", $eip
printf " eax:%08X  ebx:%08X  ecx:%08X  edx:%08X\n", $eax, $ebx, $ecx, $edx
printf " esi:%08X  edi:%08X  esp:%08X  ebp:%08X\n", $esi, $edi, $esp, $ebp
printf " cs:%04X  ds:%04X  es:%04X\n", $cs, $ds, $es
printf " fs:%04X  gs:%04X  ss:%04X\n", $fs, $gs, $ss
printf " eflags:%08X\n", $eflags
print $eflags 
end
document r32
print cpu registers(32bit)
end
############################################################

# Memory eXamming
############################################################
define xb
x /32xb $arg0
end
document xb
print memory with 32 byte
usage: xb addr
end
############################################################
define xh
x /32xh $arg0
end
document xh
print memory with 32 double-byte
usage: xh addr
end
############################################################
define xw
x /32xw $arg0
end
document xw
print memory with 32 quad-byte
usage: xw addr
end
############################################################
define xg
x /32xg $arg0
end
document xg
print memory with 32 eight-byte
usage: xg addr
end
############################################################
define xf
x /32f $arg0 
end
document xf
print memory with 32 float number
usage: xf addr
end
############################################################
define xs
x /s $arg0 
end
document xs
print memory with c-style strings
usage: xs addr
end
############################################################
define xc
x /32bc $arg0
end
document xc
print memory with 32 byte ascii
usage: xc addr
end
############################################################
define xi
x /10i $arg0
end
document xi
disassembly 10 introductions
usage: xi addr
end
############################################################
define xic
x /10i $pc
end
document xic
disassembly 10 introductions under current eip
end
############################################################

# Next and Step 
############################################################
define nl
next
info locals
end
document nl
print local variables after next
end
############################################################
define na
next
info args
end
document na 
print args val after next
end
############################################################
define sl
step
info locals
end
document sl
print local variables after step
end
############################################################
define sa
step
info args
end
document sa
print args val after step
end
############################################################
define nn
next
info locals
info args
end
document nn
print local variables and args val after next
end
############################################################
define ss
step
info locals
info args
end
document ss
print local variables and args val after step
end
############################################################
define np
next
p/x $arg0
p/x $arg1
p/x $arg2
p/x $arg3
end
document np
print params val after next (4 params at most)
usage: np param1 param2 param3 param4 
end
############################################################
define sp
step
p/x $arg0
p/x $arg1
p/x $arg2
p/x $arg3
end
document sp 
print param val after step (4 params at most)
usage: sp param1 param2 param3 param4 
end
############################################################

# Stack and Frame
############################################################
define sf
echo +------------------------ stack info ------------------------+\n
info stack
echo +------------------------ frame info ------------------------+\n
info frame
echo +------------------------------------------------------------+\n
end
document sf
print current stack frame info
end
############################################################

# Breakpoint
############################################################
define bl
info breakpoints
end
document bl
show bp list
end
############################################################
define bm
break main
end
document bm
add bp to main
end
############################################################
define bc
clear $arg0
end
document bc
clear bp at function/address
usage: bc param
end
############################################################
define be
enable $arg0
end
document be
enable bp N 
usage: be bp'id
end
############################################################
define bd
disable $arg0
end
document bd
disable bp N
usage: bd bp'id
end
############################################################
define tb
set $SHOW_CONTEXT = 1
tbreak $arg0
end
document tb
set a temporary bp on address
usage: tb addr
end
############################################################
define ba
set $SHOW_CONTEXT = 1
awatch $arg0
end
document ba
set a read/write breakpoint on address
usage: ba addr
end
############################################################
define dab
delete breakpoints
end
document dab
delete all breakpoints!
end
############################################################


# Shell
##########################################################t#
define cs
shell clear
end
document cs
clear screen
end
############################################################
define re
refresh
end
############################################################


# Threads and Process
############################################################
define setfreeze
set scheduler-locking on
end
document setfreeze
freeze other threads when current thread break
end
############################################################
define setunfreeze
set scheduler-locking off
end
document setunfreeze
unfreeze other threads when current thread break
end
############################################################
define setforkchild
set follow-fork-mode child
end
document setforkchild
set follow child process when fork
end
############################################################
define setforkparent
set follow-fork-mode parent
end
document setforkparent
set follow child process when parent
end

############################################################




### 如何编辑和配置 GDB 的 `.gdbinit` 文件 `.gdbinit` 是 GDB 启动时会自动加载的一个初始化文件,用于设置调试环境或自定义功能。以下是关于如何编辑和配置此文件的相关说明: #### 编辑 `.gdbinit` 文件 可以通过任何文本编辑器来修改 `.gdbinit` 文件。通常情况下,该文件位于用户的主目录下(即 `~/.gdbinit`)。如果不存在,则可以创建一个新的文件。 示例命令如下: ```bash touch ~/.gdbinit # 创建新的 .gdbinit 文件 nano ~/.gdbinit # 使用 nano 编辑器打开并编辑 ``` #### 配置 `.gdbinit` 文件的功能 `.gdbinit` 文件支持多种配置选项,可以根据需求添加不同的指令或脚本来增强 GDB 功能。以下是一些常见的用途及其配置方式: 1. **手动加载特定的 GDB 脚本** 可以通过 `-x` 参数在启动时指定 `.gdbinit` 文件的位置[^1],或者直接将 `source` 命令写入 `.gdbinit` 中以便自动加载其他脚本。 示例代码: ```bash source ~/stl_views_1.0.3.gdb ``` 2. **自定义命令** 用户可以在 `.gdbinit` 文件中定义自己的快捷命令。例如,清屏命令可以通过以下方式实现[^2]: ```bash define cls shell clear end ``` 3. **STL 容器查看工具** 对于 C++ STL 类型的数据结构(如 `std::vector`),可以直接利用现成的辅助脚本简化打印过程[^3]。例如,在 `.gdbinit` 文件中加入以下内容即可启用 `pvector` 命令: ```bash python import sys sys.path.insert(0, '/path/to/gdb_printers') from libstdcxx.v6.printers import register_libstdcxx_printers register_libstdcxx_printers(None) end ``` 4. **多项目管理下的灵活配置** 在复杂的工程项目中,可能需要针对不同目标提供独立的 GDB 设置。这时可以通过条件判断或其他机制动态调整行为[^4]。比如: ```bash set auto-load safe-path /project/specific/path/ ``` 以上方法能够显著提升开发体验,并使调试工作更加高效。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值