Debugging in Linux
One way to debug in Linux would be to use gdb.
This program can run and debug most programs you can write.
setting up to debug a program
First, you need to build the binary in such a way that allows the program to be debugged.
This can be done by passing gcc or g++ the -g flag.
attach
attach [PID]
This command allows gdb to attach itself to another process.
[c]ontinue
This continues and stops at the next break point.
[b]ack[t]race
This prints the back trace (stack). The call
[b]reak
break [function|label|filename:number|linenumber|address]
filename:number- This will set a break point at the line number in a givin file.label- This will set a break point at theline fallowing the labelfilename:number- This will set a break point at the line number in a givin file.
[d]elete
delete [break_point_number]
This deletes a break point number.
disassemble
disassemble [label]
This command disassembles the assembly code at a certain label.
[i]nfo
info [name]
[b]reak- list all break points[fu]nctions- List all of the function signatures[f]rame- Lists the current stack frame information[r]egisters- list all of the registers[s]tack- This prints all of the text
layout
layout [layout name]
This changes the current layout.
There are 4 different layouts src, asm, split and regs
src- soure code split with the gdb command promptasm- the ows the assembly and the gdb command promptsplit- This shows the both the source code, assemby and the gdb command prompt.regs- THis displlays all of the CPU registers
[n]ext
next [count]
This runs how ever many lines of code is specified. This will step over any functions.
[r]un
run args1 arg2 ... < file_in.txt > file_out.txt
This command runt the binary. Pass any arguments to this and it passes them on to the child program
[s]tep
step count
This single steps to the next line or the next n instructions