Gdb

De Mathux
Aller à : navigation, rechercher

Print Global variable

In gdb "info variables" list all global and static variable names Could also check "info locals" which list local variables of current stack frame or "info adress <symbol>"

to save all globals in a file (my_global_var)

./gdb myprog
set logging file my_global_var
set logging on
info variables
set logging off
q

prepare a file with gdb commands to print every variables except pointer

#!/bin/sh
rm command_gdb;
echo "set print array on" >>command_gdb;
echo "set print pretty on" >> command_gdb;
echo "set logging on" >> command_gdb ;
for i in $(more my_global_var | grep -v ":" | grep -v "*" | awk ' { print ( $(NF) ) }'| awk -F";" '{print $1}'| sed 's/\([.^[]*\)\[.*\]/\1/); do echo "print $i" >> command_gdb; done


prepare a file with gdb commands to print every var

#!/bin/sh
rm command_gdb_pt;
echo "set print array on" >>command_gdb_pt;
echo "set print pretty on" >> command_gdb_pt;
echo "set logging on" >> command_gdb_pt ;
for i in $(more global_var_isp | grep -v ":" | grep "*" | awk ' { print ( $(NF) ) }'|sed 's/\*\(.*\);/\1/'| sed 's/\([.^[]*\)\[.*\]/\1/); do echo "print $i" >> command_gdb_pt; done


get variables values

gdb ./myprog
b init_func
r
#break 1
set logging file var_before
source -v command_gdb
set logging file off
c
#Do stuff
#break
set logging file var_after
source -v command_gdb
set logging file off