7.2. Preparing a Program for Debugging

Compiling Programs with Debugging Information

To compile a C program with debugging information that can be read by the GNU Debugger, make sure the gcc compiler is run with the -g option. To do so on the command line, use a command in the following form:
scl enable devtoolset-4 'gcc -g -o output_file input_file...'
Similarly, to compile a C++ program with debugging information, run:
scl enable devtoolset-4 'g++ -g -o output_file input_file...'

Example 7.1. Compiling a C Program With Debugging Information

Consider a source file named fibonacci.c that has the following contents:
#include <stdio.h>
#include <limits.h>

int main (int argc, char *argv[]) {
  unsigned long int a = 0;
  unsigned long int b = 1;
  unsigned long int sum;

  while (b < LONG_MAX) {
    printf("%ld ", b);
    sum = a + b;
    a = b;
    b = sum;

  return 0;
To compile this program on the command line using GCC from Red Hat Developer Toolset with debugging information for the GNU Debugger, type:
~]$ scl enable devtoolset-4 'gcc -g -o fibonacci fibonacci.c'
This creates a new binary file called fibonacci in the current working directory.

Installing Debugging Information for Existing Packages

To install debugging information for a package that is already installed on the system, type the following at a shell prompt as root:
debuginfo-install package_name
Note that the yum-utils package must be installed for the debuginfo-install utility to be available on your system.

Example 7.2. Installing Debugging Information for the glibc Package

To install debugging information for the glibc package, type:
~]# debuginfo-install glibc
Loaded plugins: product-id, refresh-packagekit, subscription-manager
--> Running transaction check
---> Package glibc-debuginfo.x86_64 0:2.17-105.el7 will be installed