1

I'm writing a GDB script in python to print some debug information of the application. The thing is multiple architectures are supported: x86, alpha, aarch64, and probably some more later. The function printing the debug information varies from the architecture.

So in fact I've got the following functions:

def print_info_x86():
   #...


def print_info_aarch64():
   #...


def print_info_alpha():
   #...

And I want to achieve something like the following:

def print_info():
   if arch == 'x86':
      print_info_x86()
   #etc..

Is there a way to do that? There is a GDB command show architecture and it's possible to extract it from objdump -a, but is there a simpler way to understand what architecture the binary was compiled for in GDB?

1 Answer 1

2

https://sourceware.org/gdb/onlinedocs/gdb/Architectures-In-Python.html

something like this:

f = gdb.selected_frame()
a = f.architecture()
print(a.name())
Sign up to request clarification or add additional context in comments.

3 Comments

You probably meant frame = gdb.selected_frame(), not f = gdb.selected_frame()
@SomeName copy-paste copied the invokation form the documentation
I would probably use gdb.selected_inferior().architecture().name() instead, so I don't need a running process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.