This is my current .gdbinit setup for binary exploitation and reverse engineering. It loads pwndbg, switches disassembly to Intel syntax, follows child processes after fork, and automatically opens separate tmux panes for disassembly, stack, backtrace, registers, and an IPython scratch pane.
Requirements
Install these first:
gdbpwndbgtmuxipythonoptional, only used for the scratch pane
The config assumes pwndbg is installed at:
/usr/share/pwndbg/gdbinit.pyIf your pwndbg install path is different, change the first line of the config.
Install
Put the following content in ~/.gdbinit:
source /usr/share/pwndbg/gdbinit.pyset history save onset follow-fork-mode childset disassembly-flavor intel
set $mybase1 = 0x0000555555554000set $mybase = 0x7ffff7ffc000
pythonimport osimport atexitimport pwndbgfrom pwndbg.commands.context import contextoutput
if 'TMUX' in os.environ: created_panes = []
def create_pane(split_cmd): output = os.popen(split_cmd).read().strip() if not output: return None, None21 collapsed lines
pane_id, tty = output.split(":") created_panes.append(pane_id) return pane_id, tty
p_disasm_id, p_disasm_tty = create_pane('tmux split-window -vb -P -F "#{pane_id}:#{pane_tty}" -l 75% -d "cat -"') p_stack_id, p_stack_tty = create_pane(f'tmux split-window -v -P -F "#{{pane_id}}:#{{pane_tty}}" -l 40% -t {p_disasm_id} -d "cat -"') p_bt_id, p_bt_tty = create_pane('tmux split-window -h -P -F "#{pane_id}:#{pane_tty}" -t -1 -l 30% -d "cat -"') p_regs_id, p_regs_tty = create_pane(f'tmux split-window -h -P -F "#{{pane_id}}:#{{pane_tty}}" -t {p_stack_id} -l 30% -d "cat -"') p_ipy_id, p_ipy_tty = create_pane('tmux split-window -h -P -F "#{pane_id}:#{pane_tty}" -l 30% -d "ipython"')
if p_disasm_tty: contextoutput("disasm", p_disasm_tty, True, 'top', False) if p_stack_tty: contextoutput("stack", p_stack_tty, True, 'top', False) if p_bt_tty: contextoutput("backtrace", p_bt_tty, True, 'top', False) if p_regs_tty: contextoutput("regs", p_regs_tty, True, 'top', False)
if p_stack_tty: contextoutput("legend", p_stack_tty, True) if p_regs_tty: contextoutput("expressions", p_regs_tty, True, 'top', False)
def cleanup_panes(): for pid in created_panes: os.system(f"tmux kill-pane -t {pid} >/dev/null 2>&1")
atexit.register(cleanup_panes)else: print("\n[\033[33m*\033[0m] Not running inside TMUX. Standard pwndbg output will be used.")
pwndbg.config.context_disasm_lines.value = 25pwndbg.config.context_stack_lines.value = 18endUsage
Start a tmux session first:
tmuxThen run GDB or pwndbg normally:
gdb ./challor:
pwndbg ./challWhen GDB starts inside tmux, the config creates panes for:
disasm: current instruction contextstack: stack view plus pwndbg legendbacktrace: call stackregs: registers and expressionsipython: scratch Python shell
When GDB exits, the created tmux panes are killed automatically through the atexit cleanup hook.
If GDB is not running inside tmux, no panes are created and pwndbg falls back to the normal inline context output.
Important Lines
set history save onKeeps GDB command history across sessions.
set follow-fork-mode childAfter fork(), GDB follows the child process. This is useful for fork-based CTF services where the vulnerable logic runs in the child.
set disassembly-flavor intelUses Intel syntax instead of AT&T syntax.
pwndbg.config.context_disasm_lines.value = 25pwndbg.config.context_stack_lines.value = 18Controls how much disassembly and stack context pwndbg prints.
Base Address Helpers
These two lines are personal scratch variables:
set $mybase1 = 0x0000555555554000set $mybase = 0x7ffff7ffc000They are not required. I use them as quick base-address anchors while debugging PIE binaries or shared libraries. You can remove them or replace them with values from piebase, vmmap, or a leak.
Example usage:
x/10i $mybase1 + 0x1234b *($mybase1 + 0x19e3)Adjusting The Layout
The pane sizes are controlled by tmux split-window -l:
'tmux split-window -vb ... -l 75% ...''tmux split-window -v ... -l 40% ...''tmux split-window -h ... -l 30% ...'Change these percentages if the panes are too large or too small for your monitor.
If you do not want the IPython pane, remove this line:
p_ipy_id, p_ipy_tty = create_pane('tmux split-window -h -P -F "#{pane_id}:#{pane_tty}" -l 30% -d "ipython"')Troubleshooting
If GDB prints Not running inside TMUX, start tmux first and launch GDB from inside it.
If pwndbg fails to load, verify the path:
ls /usr/share/pwndbg/gdbinit.pyIf ipython fails, install it or remove the IPython pane line.
If the panes stay open after a crash, close them manually:
tmux kill-pane -t <pane_id>