Custom GDB commands for memory editing and inspection, linked list traversal, and allocation tracking
gdb ./program
source gdbextension-gdb.gdb
runReplace ./program with the executable you want to debug
Both files must be in the same directory:
gdbextension-gdb.gdbgdbextension-gdb.py
Go to a location (line number, function name, address, or file:line pair) within your program
Command
go2 <LOCATION>Examples
go2 88
go2 main
go2 program.c:88
go2 *0x555555555439
Write SIZE bytes of VALUE into memory starting at DESTINATION
Command
memset <DESTINATION> <VALUE> <SIZE>Examples
memset memset_buf 0x41 16
memset memset_buf 65 16
memset &memset_buf[4] 0xff 8
Copy SIZE bytes from SOURCE to DESTINATION
Command
memmove <DESTINATION> <SOURCE> <SIZE>Examples
memmove dst_buf src_buf 32
memmove &buf[4] &buf[0] 16
memmove buf+8 buf 12
Print a linked list starting from HEAD. Assumes each node has the structure:
int val;
node_t *next;
Command
linked_list_print <HEAD>Examples
linked_list_print head
linked_list_print list_head
linked_list_print node
Searches a memory range for every occurrence of a byte pattern
Command
memsearch <SEARCH> <SEARCH_SIZE> <PATTERN> <PATTERN_SIZE>Examples
memsearch search_buf 64 pattern_buf 4
memsearch buf 100 &target 1
memsearch buf 256 pattern 8
Prints memory as hex bytes and printable ASCII characters
Command
hexdump [MEMORY] [LINES] [BYTES_PER_LINE]Examples
hexdump buf
hexdump buf 10
hexdump buf 10 8
hexdump
Initializes allocation tracking by installing wrapper breakpoints and prints all currently tracked dynamic allocations
Command
malloc_track_init
malloc_track_listExample
source gdbextension-gdb.gdb
break main
run
malloc_track_init
continue
malloc_track_list