Tuesday, July 20, 2010

How to break point with gdb?

Use b command with one of the following:

b function_name
b line_number
b filename:function_name
b filename:line_number
b *0xAddress
b line_number if var==0
b +2
b -2

5 comments:

  1. break point has its own unique number starting 1.
    you can use 'condition' command to set condition to set break point.

    If you want to set break-point only one time you can use 'tb' command instead of 'b' command.

    If you want to clear break-point use 'clear' command or 'cl'.

    d command will clear all of the break-point.

    ReplyDelete
  2. If you want to enable or disable specific break-point you must know the number of break-point.

    gdb support 'info breakpoints' or short version 'info b'. by using 'info b' you can see all the break-points it also supports break-point number.

    you can use 'enable' or 'disable' command now.

    syntax:
    enable break-point-number
    disable break-point-number

    break-point number is useful when you are using many source files.

    ReplyDelete
  3. gdb command for program flow control

    r: run program
    r arg1 arg2: run with arguments
    k: kill debugging
    s: step into - stopped after run current line if it is function control entered the function inside.
    n: same with 's' command but do not enter the function inside.

    * s, n command will be followed by number ex) s 5 == s 5 times

    ** you can use Enter key to use continuouly s or n commnad.


    c: continue to meet the break-point

    ReplyDelete
  4. other important command to exit for statement or function.

    u: exit from loop such as for statement
    finish: go to the end of function.
    return: to exit without run remain code of the function.

    ReplyDelete
  5. si, ni command

    si, ni is same with s, n command but it execute only one instruction not statement.

    ReplyDelete