Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb disassemble one line

Tags:

c

gcc

gdb

I want to disassemble only one particular line of code in gdb; to do this, I need the memory address of said line. How can I get the address of a particular line of code in gdb? Or better yet, is there a command in gdb to disassemble by line number?

like image 264
Bhubhu Hbuhdbus Avatar asked Jun 03 '12 22:06

Bhubhu Hbuhdbus


2 Answers

Put a break on the line you want to disassemble and then, you could try to get the current instruction with.

disp/i $pc

This always works for me, when I debug binaries with no debug info. Also one could simply get the current pc either by print $pc or info registers or simply use the x instruction. e.g.:

x/10i address  //displays the first 10 instructions in assembly starting from address

or

x/10i register //displays the first 10 instructions starting from address stored in register
like image 107
skyel Avatar answered Oct 11 '22 01:10

skyel


You can use: set disassemble-next-line on to diassemble by line number. Then use whatever technique you want to set a breakpoint at the specific line you want to view.

like image 20
Gabriel Southern Avatar answered Oct 11 '22 03:10

Gabriel Southern