Thursday, February 7, 2013

How to use GDB debugger

                                 -------------------GDB-----------------------------

1. gcc -g program.c
2. gdb ./a.out
3. break main
4. run
5. list ( show the all line of the program.c)
6. list 5,10 ( show the line form 5 to 10 )
7. bt ( back trace )
8. whatis variable_name (it will give the datatype of variable)
9. bt n ( print only the innermost n frames)
10. bt -n ( print only the outermost n frames)
11. fn ( select frame number n)
12. f addr ( select the frame at address addr)
13. up n ( move n frames up the stack )
14. down n ( move n frames down the stack )
15. info f ( print info about the frame )
    info b ( to list the number of breakpoints )   
16. break function ( Set a breakpoin at entry to function)
17. break -offset, break +offset ( set a break point some number of lines forward or backward to the position)
18. break linenum ( set the breakpoint at particular linenumber)
19. break filename:linenum ( set a breakpoin at line linenum in sourece file filename)
20. delete <breakpoint_number>
    clear <function>
21. Enable/Disable breakpoints
    a) enable <breakpoint_number>
    b) disable <breakpoint_number>
22. print $bpnum ( It will give the number of break points
23. watch expr (set a watchpint for an exeression. gdb will break when    expr is written into by the program and its value changes.
23. rewatch expr ( set a watchpoint that will brea when watch expr is read by the program.
24. awatch   ---()
25. info  watchpoint

26. continue[ignore-count] ( REsume program execution, at the address where your program last stopped. The optional argument ignore-count allows you to specify a further numbe ro ftimes to ignore a breakpoint at this location.

27. step [count]
    Continue running your program until control reaches a different source line, then stop it and return control to GDB.With the optional argument, it wil continue running as in step, but do so count times.
   
28. next[count]
    Continue to the next sourece line in the current( innermost) stack frame. This is similar to STEP, but function alls that appear within the line of code are executed without stopping . An optional argument count is a repeat count.
   
29 . finish ( continue running until just after function in the selected stack frame returns. Print the returned value( if any).

30. until ( continue running until a source line past the current line, in the current stack frame, is reached. This command is used to avoid single stepping throught a loop mor than once.

31. jump linespec ( Resume execution at line linespec. Execution stops again immediately if ther is a break ping there.

32. jump *address ( Resume execution at the instruction at address .
33. info local ( Show the
34  info reg ( Show all the machine register )

************************************************************************
**) SEGMENTATION FAULT:: It is often caused by trying to access a memory location that is not in the address space of the process.
**) BUS ERROR :: It is typically caused by trying to access an object with an improperly aligned address. (Ex: tring to fetch an int from address 1)
**) ILLEGAL INSTRUCTION:: It is typically occurs when execution branches into data. This sometimes happens when the stack is overwritten.
**) Arithmetic exception :: It is typically caused by integer  division by zero.

*************************************************************************
            LAUNCHING GDBSERVER IN TARGET PLATFORM:
    
     TCP/Ip
     1. gdbserver host:port <application name >
        example gdbserver 10.102.68.51:1233 hello
     2. COM port
        gdbserver commdevice <application name >
        example gdbserver /dev/com1 telephony

    LAUNCHING GDB IN HOST PLATFORM
  
   1. gdb telephony
   2. target remote /dev/com1
        OR
   1. (gdb)target remote <targetip>2345
   (gdb) continue (don't run once again. it is already running in target machine ).

  

No comments:

Post a Comment

Qualcomm Short Term

  113 is the SL. 1st Target by mid July.

Total Pageviews