# GDB (GNU debugger) config
# vim: ft=gdb:noml:
set confirm off
set startup-quietly on
# set startup-with-shell off
set listsize 24

set history save on
set history size 1000
set history filename ~/.local/share/gdb/history
# python
# import os
# histfile = os.path.join(os.environ["XDG_DATA_HOME"], "gdb/history")
# gdb.execute('set history filename ' + histfile)

# can scroll back in my terminal, and pagination
# is annoyting when setting mass breakpoints
set pagination off
set style enabled on
set breakpoint pending on

# print | charset
set print symbol-filename on
set print pretty on
set print array on
# set print object on
# set print static-members off
# set charset ASCII

# files | load gdbinit files wherever they are when we drop into gdb.
# source /home/myuser/.gdb/py-modules/add-syspath.py
# add-auto-load-safe-path /home/myuser/.gdb
# add-auto-load-scripts-directory /home/myuser/.gdb/auto-load
# source /home/house/.gdb/py-modules/frame.py
set auto-load safe-path /

# prompt | color prompt doesnt work in TUI mode
set prompt gdb>
# # set prompt \001\033[1;36m\002(gdb) \001\033[0m\002
# set prompt \033[31mgdb $ \033[0m
# prompt | bold green "gdb" in parentheses. trailing whitespace is necessary.
# set extended-prompt (\[\e[01;32m\]gdb\e[00m\]) 

# output | set default output base to hex.
set output-radix 16

# disassemble | always disassemble next command/instruction.
# set disassembly-flavor intel
# very useful when debugging code without debug information.
set disassemble-next-line on

# signals | dont stop on SIGUSR1 and instead let the program handle it.
# [1]: https://peeterjoot.wordpress.com/2010/07/07/avoiding-gdb-signal-noise/
handle SIGUSR1 noprint nostop

layout src

# functions | define functions
define hook-stop
  printf "\n\n\n"
  info locals
  refresh
end

## hexdump command
# note we use printf and sed here to output \r characters needed in -tui mode.
# this is easier than messing with `shell stty onlcr` as that could
# impact the terminal after exiting a non -tui gdb session.
define hd
    dump binary memory /tmp/dump.bin $arg0 $arg0+$arg1
    shell printf '\r\n'; od -Ax -tx1z -v /tmp/dump.bin | sed 's/$/\r/'
end

## var
define var
    if $argc == 0
        info variables
    end
    if $argc == 1
        info variables $arg0
    end
    if $argc > 1
        help var
    end
end
document var
Print all global and static variable names (symbols), or those matching REGEXP.
Usage: var <REGEXP>
end
