I need to write some gdb macros that need to different between 32 and 64 bit architectures. I'm looking for a way to determine in gdb whether the debugged executable is 32 or 64 bit.
info target includes info about file type
e.g. file type elf32-i386
but this is embedded in a longer output.
Being new to gdb macros, I don't know how to process that output, or find another way to get this.
Please, no python gdb for the time being.
Here is your solution, not 'contaminated' with python:
define set-program-arch
set logging file tmp.gdb
set logging overwrite on
set logging redirect on
set logging on
set pagination off
info target
set pagination on
set logging off
set logging redirect off
set logging overwrite off
shell echo -n 'set $program_arch="' > tmp2.gdb
shell grep 'file type' tmp.gdb | sed "s/\.$//g" | cut -d ' ' -f 4 | tr -d '\n' >> tmp2.gdb
shell echo '"' >> tmp2.gdb
source tmp2.gdb
shell rm -f tmp2.tmp tmp.gdb
end
This sets variable program_arch to ELF type of the binary being debugged (e.g. elf64-x86-64). Enjoy!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With