Enable Debugging with Debug Information
To debug applications and libraries, you must obtain debugging information.
Debug information overview Copy linkLink copied!
Debugging information links binary code to source code so you can inspect variables and execution flow. The GNU Compiler Collection (GCC) generates this data in the Debug With Arbitrary Record Format (DWARF) within ELF files, and the GNU Debugger (GDB) uses it to analyze program behavior.
Red Hat Enterprise Linux uses the ELF format for executable binaries, shared libraries, or debuginfo files. Within these ELF files, the DWARF format is used to hold the debug information.
To display DWARF information stored within an ELF file, run the readelf -w file command.
STABS (Symbol Table format) is an older, less capable debugging format, occasionally used with UNIX. For debugging on RHEL, use the DWARF format instead. GCC and GDB support STABS on a best-effort basis only. Tools such as Valgrind and elfutils do not support STABS.
Enable debug of C and C++ applications with the GCC Copy linkLink copied!
To debug C and C++ applications effectively, generate debugging information during compilation. Use GCC’s -g option to create this data. Debuggers use this data to map executable code to source lines for inspecting variables and logic.
Before you begin Copy linkLink copied!
- You have the
gccpackage installed.
Procedure Copy linkLink copied!
Results Copy linkLink copied!
- Test the code by using the
-fcompare-debugGCC option:$ gcc -fcompare-debug ...This option tests code compiled with and without debug information. If the resulting binaries are identical, the executable code is not affected by debugging options. By using the
-fcompare-debugoption significantly increases compilation time.
Debuginfo and debugsource packages Copy linkLink copied!
The debuginfo and debugsource packages contain debugging information and source code for programs and libraries. To debug Red Hat Enterprise Linux applications, install these packages from additional repositories.
- Debugging information package types
Debuginfo packages: Thedebuginfopackages provide debugging information needed to provide human-readable names for binary code features. These packages contain.debugfiles, which contain DWARF debugging information. These files are installed to the/usr/lib/debugdirectory.
Debugsource packages: The debugsource packages contain the source files used for compiling the binary code. With both debuginfo and debugsource packages installed, debuggers such as GDB or LLDB can relate the execution of binary code to the source code. The source code files are installed to the /usr/src/debug directory.
Get debuginfo packages for an application or library by using GDB Copy linkLink copied!
To obtain the necessary debuginfo packages for troubleshooting installed applications or libraries, use the GNU Debugger (GDB). It automatically detects missing symbols and identifies the specific packages needed. Follow GDB’s recommendations to install them for full debugging capabilities.
Before you begin Copy linkLink copied!
- The application or library you want to debug must be installed on the system.
- GDB and the
debuginfo-installtool must be installed on the system. For details, see Installing tools for debugging applications. - Repositories providing
debuginfoanddebugsourcepackages must be configured and enabled on the system. For details, see Enabling debug and source repositories.
Procedure Copy linkLink copied!
Get debuginfo packages for an application or library manually Copy linkLink copied!
To manually determine which debuginfo packages you need to install, locate the executable file and find the package that installs it.
Before you begin Copy linkLink copied!
- The application or library must be installed on the system.
- The application or library was installed from a package.
- The
debuginfo-installtool must be available on the system. For details, see Installing tools for debugging applications. - Channels providing the
debuginfopackages must be configured and enabled on the system. - If you use the
locatecommand in this procedure, themlocatepackage must be installed and its database must be current. Asroot, rundnf install mlocateif needed, then runupdatedb.
About this task Copy linkLink copied!
Prefer using GDB to determine the packages for installation when that is an option. For details, see Getting debuginfo packages for an application or library using GDB.
Use this manual procedure only if GDB cannot suggest which package to install.