Take a global array as an example to illustrate how to programmatically print all variables in gdb:
Write variable traversal code
Create the search.gdb file and write the following:
define print_hash_table
set $cnt =1
set $use=2
while $cnt
set $hash_entry=(g_hash_entry_t *)(hash_table.table + 123 * $cnt)
if $hash_entry.valid == 0x1
p /x *$hash_entry
end
if $cnt < 1024
set $cnt = $cnt + 1
else
loop_break
end
end
end
Instructions
gdb process process.core
source search.gdb
print_hash_table