Tuesday, August 3, 2010

Gnu Debugger - GDB

para executar

$ gdb --args python editje-bin

quando aparecer o segmentation fault, pressionar [Ctrl+x] [a]

e ira aparecer um editor de texto no ponto do exato do código fonte onde ocorreu a falha.

[Ctrl+x] [a]  open / close editor to see code

[Ctrl+x] [1] see only C code

[Ctrl+x] [2]  see the C and assembly code

[Ctrl+x] [s]  Toogle one key mode - if you type for example s or n you don`t need to press enter
                    type [Ctrl+x] [s] again - you go back to normal prompt mode  

layout next

Display the next layout.

layout prev

Display the previous layout.

layout src

Display the source window only.

layout asm

Display the assembly window only.

layout split

Display the source and assembly window.

layout regs

Display the register window together with the source or assembly window.

focus next | prev | src | asm | regs | split

Set the focus to the named window. This command allows to change the active window so that scrolling keys can be affected to another window.

refresh

Refresh the screen. This is similar to using C-L key.

update

Update the source window and the current execution point.

winheight name +count

winheight name -count

Change the height of the window name by count lines. Positive counts increase the height, while negative counts decrease it.

http://developer.apple.com/mac/library/documentation/DeveloperTools/gdb/gdb/gdb_23.html
http://davis.lbl.gov/Manuals/GDB/gdb_21.html

Executar em ordem inversa

bt -- List the call stack frames
frame [n] -- Select a frame in the stack trace, use bt to list the frames numbers first
reverse-continue ('rc') -- Continue program being debugged but run it in reverse
reverse-finish -- Execute backward until just before the selected stack frame is called
reverse-next ('rn') -- Step program backward, proceeding through subroutine calls.
reverse-nexti ('rni') -- Step backward one instruction, but proceed through called subroutines.
reverse-step ('rs') -- Step program backward until it reaches the beginning of a previous source line
reverse-stepi -- Step backward exactly one instruction
set exec-direction (forward/reverse) -- Set direction of execution.
All subsequent execution commands (continue, step, until etc.) will run the program being debugged in the selected direction.
set print repeats 0 set print pretty on
set print element 0 -- Remove size limitation for printing a structure
finish -- Exit current function, going to first line after calling the function


Lista ultimas linhas executadas


list


.gdb

# http://sourceware.org/gdb/wiki/FAQ: to disable the
# "---Type to continue, or q to quit---"
# in batch mode:
set width 0
set height 0
set verbose off

# at entry point - cmd1
b main
commands 1
print argc
continue
end

# printf line - cmd2
b test.c:17
commands 2
p i
p b
continue
end

# int b = line - cmd3
b test.c:16
commands 3
p i
p b
continue
end

# show arguments for program
show args
printf "Note, however: in batch mode, arguments will be ignored!\n"

# note: even if arguments are shown;
# must specify cmdline arg for "run"
# when running in batch mode! (then they are ignored)
# below, we specify command line argument "2":
run 2 # run

#start # alternative to run: runs to main, and stops
#continue

set follow-fork-mode child       #when fork occurs follow child
info threads   # show threads
thread 1    # make thread 1 the current

https://sourceware.org/gdb/onlinedocs/gdb/Forks.html

$ gcc -g test.c -o test.exe
$ gdb --command=test.gdb --args ./test.exe 4

Makefile

$ make -n -- Force show compile command lines

No comments:

Blog Archive