Wednesday, December 1, 2004

GDB Basic-Howto v0.1

-What is Gdb?

Gdb is a debugger, it will let us to see what is happening inside a program.

-What programs can be debugged?

GDB supports C, C++, Fortran, Java, assembly, and Modula-2.

Basics of GDB:

-First you need to compile your program with the -ggdb, so this way,

GDB knows the names of your variables and what each line of your program says. If we use gcc for compiling our programs we use:

#gcc -o myprogram myprogram.c -ggdb

-Now we are able to load the file in the gdb:

#gdb myprogram



(gbd)file myprogram

Once the file is loaded in the GDB we have a lot of possible actions,

we are going to see the ones that i use most.

*list: print lines from a source file. by default it prints 10 lines.

there are various way of printing:

(gdb)list linenum

Print lines centered around line number linenum in the current source file.

(gdb)list startline,numlines

Print numlines starting from startline in the current source file.

(gdb)list function

Print lines centered around the beginning of function function.

(gdb)set listsize count

Make the list command display count source lines (unless the list argument explicitly specifies some other number).

*disassem: display memory as machine instructions (disassembly)

(gdb)disas main

show the machine instructions for the function main

*break: Breakpoints are set with the break command, a breakpoint stop the program at the desired point:

(gdb) break linenum

Set a breakpoint at line linenum in the current source file.

The current source file is the last file whose source text was printed.

The breakpoint will stop your program just before it executes any of the code on that line.

(gbd) break *address

Set a breakpoint at address address. You can use this to set breakpoints in parts of your program which do not have debugging information or source files.

After breaking the execution we could:

-Continue the execution: continue or c

-Execute until another line reached: step or s

-Step by machine execution instead of source line: stepi or si

-Execute next line, include any function call: next or n

-Execute next machine instruction: nexti or ni

-Resume the execution at specified line or address: jump line or jump address

*info registers: it shows the values of the registers in that moment of the execution.

*print: It evaluates and prints the value of an expression of the language your program is written in.

(gdb) print $ebp

it shows the address where is ebp

(gdb) print $esp

it shows the address where is esp

*x: examine memory in any of several formats, independently of your program's data types. It shows the content of a variable.

(gdb)x/24 $esp

it will show 24 words addresses starting from $esp

(gdb)x $ebp+4

it shows the return address

(gdb)x/24 $ebp

it shows the sorrounding addresses from $ebp

(gdb)x 0xbffffa0c

it shows the content at that address

No comments:

Wfuzz 2.2.0 released

I'm pleased to announce a new version of WFuzz! Wfuzz has been created to facilitate the task in web applications assessments and it...