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)
Asked
Active
Viewed 5.5k times
39
-
Related: https://stackoverflow.com/questions/1902901/show-current-assembly-instruction-in-gdb – Ciro Santilli OurBigBook.com Nov 06 '19 at 12:03
5 Answers
25
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.

X-Istence
- 16,324
- 6
- 57
- 74
11
In the new gdb version 7.0, the disassemble
command can take a new argument /m
which makes it emit mixed source and disassembly.

iblue
- 29,609
- 19
- 89
- 128

Michael Snyder
- 5,519
- 4
- 28
- 19
4
Using the disas command will probably do what you want.
According to the internal help, the disas command does the following:
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.

Paul Wicks
- 62,960
- 55
- 119
- 146
1
That question was also asked in cgdb's googlegroup https://groups.google.com/forum/?hl=de&fromgroups=#!topic/cgdb-users/E-jZCJiBAQQ
No answer yet on why layout asm doesnt work though
Edit: They posted recently and told that its a feature that isnt implemented yet. (check the link above)

JohnRW
- 748
- 7
- 22