i.e. instead of giving push $rbp
for example. it show the steps for executing such instruction like this
sub esp, 4 ; "allocate" space for the new stack item
mov [esp], X ; put new stack item value X in
No, because push
is a single machine instruction so it wouldn't be accurate disassembly. If you need more detail than that, read the manual for the instruction in question.
Having a disassembler annotate instructions with pseudocode in comments (or on mouseover tooltips in a GUI) might be interesting, but I couldn't imagine anyone writing one that even has an option to just silently replace push
with 2 other instructions everywhere it occurs. (And it would make disassembly more bloated.)
BTW, that specific emulation isn't even correct. sub
modifies FLAGS, unlike push
. And it would be rsp
and 8
in 64-bit mode, for push %rbp
(AT&T) / push rbp
(Intel). Can a “PUSH” instruction's operation be performed using other instructions? points out some other ways in which a multi-instruction emulation might not be exactly equivalent.
Any other sequence would have different code-size so it wouldn't line up with the addresses in GDB's disassembly, so that's another huge reason not to do it.
If you want asm instructions annotated with help, consider looking at your compiler's asm output on the Godbolt compiler explorer; it does have ISA reference pop-ups on mouseover for x86 instructions. I think it's on by default. The option is in More -> Settings -> Show asm description on hover.
See this for example where I compiled in 32-bit mode so I could get it to push
. (I didn't think of disabling optimization in 64-bit mode until after copy/pasting the link :P)
The popup for push
is:
Decrements the stack pointer and then stores the source operand on the top of the stack. Address and operand sizes are determined and used as follows
More information available in the context menu.
So it's the first paragraph of the Description section from Intel's vol.2 manual. If you right click on the push instruction, it pops up the full text of the Description section from Intel's doc, with a link to http://www.felixcloutier.com/x86/PUSH.html.
But unfortunately they're just the wordy Description section, not a quick pseudocode for more complex instructions that have implicit operands like idiv
or cdq
.
Previous iterations of this feature maybe had something more compact; IDK, if you use asm regularly you don't need it for simple instructions, and when you do need to look something up it's typically more complicated than what popup help would give you.
The feature you're imagining could be useful as popups for beginners, but in GDB would make things more cluttered and nobody that uses or develops GDB would want it in the form you're describing.
There aren't many x86 instructions where you can usefully expand to "simpler" instructions. e.g. you don't want imul
to expand to a a shift-and-add loop, or a naive simple add loop, I hope? But lea
could be emulated with up to 4 mov/shift/add instructions.
Would cdq
really be easier to understand if written as mov edx,eax
/ sar edx,31
? More likely a description of what it does would be more useful.