Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching to assembly in gdb

Tags:

assembly

gdb

Is there is any way to switch to assembly when debugging a C or C++ program in gdb ? (Given that all source files and their corresponding assembly files are available)

like image 213
Ben Avatar asked Feb 26 '09 08:02

Ben


People also ask

Does gdb work on assembly?

gdb is the GNU source-level debugger that is standard on linux (and many other unix) systems. It can be used both for programs written in high-level languages like C and C++ and for assembly code programs; this document concentrates on the latter.

How do I get out of layout ASM gdb?

You can always leave or enter TUI at any time durring debug session. For example you can do it with ctrl + x a key binding.

What does layout ASM do?

asm​will display the assembly and command windows. split​will display the source, assembly, and command windows. regs​will display the register, source, and command windows when in src layout. When in asm or split layout, will display the register, assembler, and command windows.

What is Stepi in gdb?

stepi: Step one instruction exactly. nexti: Step one instruction, but proceed through subroutine calls. since we are dealing with instructions and machine code here (the smallest part of a program in execution) I can't figure out what the subroutine calls are. c++ c debugging gdb.


2 Answers

You can switch to asm layout in gdb:

(gdb) layout asm 

See here for more information.

like image 118
ks1322 Avatar answered Sep 20 '22 14:09

ks1322


There is a way to disassemble a function or a certain section of code, is that what you are after?

The command to do so would be disassemble <function name> or a memory location.

Is this what you are referring to?

(gdb) help disassemble Disassemble a specified section of memory. Default is the function surrounding the pc of the selected frame. With a single argument, the function surrounding that address is dumped. Two arguments are taken as a range of memory to dump. 
like image 42
X-Istence Avatar answered Sep 19 '22 14:09

X-Istence