3.2.5. Using GDB breakpoints to stop execution at defined code locations


During a debugging session, you often need to investigate only specific sections of code. Breakpoints are markers that instruct GDB to stop execution at a defined location. Because each breakpoint maps to a source line, you must specify the correct source file and line number when placing them.

Procedure

  • To place a breakpoint.

    1. Specify the name of the source code file and the line in that file:

      (gdb) br file:line
    2. When file is not present, name of the source file at the current point of execution is used:

      (gdb) br line
    3. Alternatively, use a function name to put the breakpoint on its start:

      (gdb) br function_name
    4. A program might encounter an error after a certain number of iterations of a task. To specify an additional condition to halt execution:

      (gdb) br file:line if condition

      Replace condition with a condition in the C or C++ language. The placeholders file and line match the syntax shown in the first breakpoint step in this procedure.

  • To inspect the status of all breakpoints and watchpoints:

    (gdb) info br
  • To remove a breakpoint by using its number as displayed in the output of info br:

    (gdb) delete number
  • To remove a breakpoint at a given location:

    (gdb) clear file:line
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部