September 05, 2017

Useful commands of GDB and GDB peda

$ gcc -g -o main main.c: Compile with debug information.

$ file [File path]: Select a file for debug.

$ list [Number]: Print "[Number]" lines of the program's source code.

$ list 10, list main.c:function1

$ set disassembly-flaver intel: Set assembly code to intel syntax.

$ set disassembly-flaver att: Set assembly code to AT&T syntax.

$ set [Variable] or [*Memory] = [Value]

$ set number1 = 1

$ set *((int *)0x8048000) = 51

$ set *0x8048500 = 0x5A1F70

$ set disable-randomization [on/off] : On or off the ASLR. 

$ disassemble [Function]: Disassemble the function.

  * $ disas [Function]

$ disas [Address], +[Bytes]: Disassemble the address.

  * $ disas 0x80481f1, +16

 

$ break *0x400fd8: Set a breakpoint in the memory.

$ break *main+241, break main.c:function1, break 30

$ break [Function]: Set a breakpoint at the function.

$ info breakpoints: Print the breakpoints list.

$ delete: Delete all breakpoints.

$ disable breakpoints 1 4: Disable first and fourth breakpoints

$ enable breakpoints 1 4: Enable first and fourth breakpoints

$ ignore breakpoints 1 10: Ignore the first breakpoint 10 times.

$ watch [Variable name]: Break when the variable is written.

$ rwatch [Variable name]: Break when the variable is read.

$ awatch [Variable name]: Break when the variable is read or written.

$ run [argv1] [argv2]: Run up to the first breakpoint, Rerunning if running, Printing of error point.
$ kill: Exit the currently running program.

$ next: Run the next line(step over)(C code).

$ nexti: Run the next line(step over)(Assembly code).

$ next 5(nexti 5): Running the following five lines

$ step: Run the next line including subroutine(step in)(C code).

$ stepi: Run the next line including subroutine(step in)(Assembly code).

$ continue: Run up to the next breakpoint.

$ until: Exit the current loop.

$ finish: Run up to the end of the current function(step out).

$ info files: Print loaded symbols.

$ info locals: Print local variables.

$ info variables: Print global variables.

$ info registers: Print all registers value.

$ info sharedlibrary: Print mapped shared libraries.

$ print [Variable name]: Print the variable value.

$ print [Variable name]=[Value]: Write a value in the variable.

$ print $[Register name]: Print a register value.

$ print $[Register name]=[Value]: Write a value in the register.

print/t: Binary
print/o: Octal
print/d: Decimal
print/x: Hexadecimal


$ x/[Number][Unit size][Display format] [Memory address]: Print the value in the memory address.

[Display format] : Specifying the output format of the read value.
x: Hexadecimal(default)o: Octal
d: Decimal
s: String
i: Machine instruction(Assembly language)

[Unit size] : Specifying the unit of memory to be read.
b: Byte
h: 2 bytes
w: 4 bytes
g: 8 bytes

[Number] : Specifying the number of values to read. Unsigned integer.
$ x/x $rbp-0x38, x/wx 0x00401570

 

$ info signals: Print the kind of signal that can be transmitted.

$ signal [Signal]: Transmit a signal to the program.

$ shell: Run a shell in the state of running the process by GDB.

$ run < [File]: Input data of the file to the program with the pipeline.