Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb macro to determine the architecture of debugged program

Tags:

gdb

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.

like image 708
dbbd Avatar asked Sep 10 '12 22:09

dbbd


1 Answers

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!

like image 176
sirgeorge Avatar answered Sep 28 '22 04:09

sirgeorge