Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disassemble a memory range with GDB?

I'm trying to disassemble a program to see a syscall assembly instruction (the INT instruction, I believe) and the handler with GDB and have written a little program (see below) for it that opens and closes a file.

I was able to follow the call to fopen with GDB until it executed a call.

When I tried to tell GDB "disassemble 0x...." (address of call) it responded with 'No function contains specified address.'

Is it possible to force GDB to disassemble (or display it in assembler as good as possible) that memory address? If so, how?

#include <stdio.h> #include <stdlib.h>  int main() {     FILE* f;     f = fopen("main.c", "r");     if (!f) {        perror("open");       return -1;     }     fclose(f);     return 0; } 
like image 644
Patrick Avatar asked Aug 06 '09 07:08

Patrick


People also ask

How to see disassembly in GDB?

From within gdb press Ctrl x 2 and the screen will split into 3 parts. First part will show you the normal code in high level language. Second will show you the assembly equivalent and corresponding instruction Pointer .

What is disassemble GDB?

Function. Specifies the function to disassemble. If specified, the disassemble command will produce the disassembly output of the entire function. Address. Specifies the address inside a function to disassemble.

Which command is used to disassemble code?

The objdump command is generally used to inspect the object files and binary files. It prints the different sections in object files, their virtual memory address, logical memory address, debug information, symbol table, and other pieces of information. Here we'll see how we can use this tool to disassemble the files.


1 Answers

Yeah, disassemble is not the best command to use here. The command you want is "x/i" (examine as instructions):

(gdb) x/i 0xdeadbeef 
like image 174
Michael Snyder Avatar answered Sep 17 '22 19:09

Michael Snyder