简体   繁体   中英

How to use gdb to debug into a C program's corresponding disassembly?

Using VC can bring up disassembly window and travel across it. But using gdb seems not so direct:

Eg I've got a myadd.c

void main(){
   int i=0;
   int j=i+1;
   j+=2;
}

gcc -g myadd.c

gdb a.out

b 2 //set break point at int j=1+1;

Now I can use "disassemble" command to see disassembly code. My requirement is to debug "into" this disassembly code like VC could. I tried 's' command, it directly goes into next "C" statement, not disassembly statement.

How to do that?

To jump to the next assembly instruction, use stepi (short si ) instead.

See this for more information, especially how to use display/i to show the next machine instruction.

For a reasonably nice assembly view, use la p ( layout prev ) and step with si ( stepi ). Use Cx a to return to/from regular gdb prompt. In some cases, other layouts may be useful as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM