Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Red Hat Enterprise Linux 9 Essentials Book now available.

Purchase a copy of Red Hat Enterprise Linux 9 (RHEL 9) Essentials

Red Hat Enterprise Linux 9 Essentials Print and eBook (PDF) editions contain 34 chapters and 298 pages

Preview Book

5.2.3. Conditional Breakpoints

In many real-world cases, a program may perform its task well during the first few thousand times; it may then start crashing or encountering errors during its eight thousandth iteration of the task. Debugging programs like this can be difficult, as it is hard to imagine a programmer with the patience to issue a continue command thousands of times just to get to the iteration that crashed.
Situations like this are common in real life, which is why GDB allows programmers to attach conditions to a breakpoint. For example, consider the following program:
simple.c
      #include <stdio.h>
      
      main()
      {
        int i;

        for (i = 0;; i++) {
          fprintf (stdout, "i = %d\n", i);
        }
      }
To set a conditional breakpoint at the GDB prompt:
      (gdb) br 8 if i == 8936
      Breakpoint 1 at 0x80483f5: file iterations.c, line 8.
      (gdb) r
With this condition, the program execution will eventually stop with the following output:
      i = 8931
      i = 8932
      i = 8933
      i = 8934
      i = 8935
      
      Breakpoint 1, main () at iterations.c:8
      8           fprintf (stdout, "i = %d\n", i);
Inspect the breakpoint information (using info br) to review the breakpoint status:
      (gdb) info br
      Num     Type           Disp Enb Address    What
      1       breakpoint     keep y   0x080483f5 in main at iterations.c:8
              stop only if i == 8936
              breakpoint already hit 1 time

 
 
  Published under the terms of the Creative Commons License Design by Interspire