04.06.2015 Views

Red Hat Developer Toolset 1.x User Guide - Linux

Red Hat Developer Toolset 1.x User Guide - Linux

Red Hat Developer Toolset 1.x User Guide - Linux

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

30 Chapter 3. GNU Debugger (GDB)<br />

To run the GNU Debugger on a program you want to debug, type the following at a shell prompt:<br />

scl enable devtoolset-1.1 'gdb file_name'<br />

This starts the gdb debugger in interactive mode and displays the default prompt, (gdb). To quit the<br />

debugging session and return to the shell prompt, run the following command at any time:<br />

quit<br />

Note that you can execute any command using the scl utility, causing it to be run with the <strong>Red</strong> <strong>Hat</strong><br />

<strong>Developer</strong> <strong>Toolset</strong> binaries used in preference to the <strong>Red</strong> <strong>Hat</strong> Enterprise <strong>Linux</strong> system equivalent. This<br />

allows you to run a shell session with <strong>Red</strong> <strong>Hat</strong> <strong>Developer</strong> <strong>Toolset</strong> gdb as default:<br />

scl enable devtoolset-1.1 'bash'<br />

Note<br />

To verify the version of gdb you are using at any point, type the following at a shell prompt:<br />

which gdb<br />

<strong>Red</strong> <strong>Hat</strong> <strong>Developer</strong> <strong>Toolset</strong>'s gdb executable path will begin with /opt. Alternatively, you can use<br />

the following command to confirm that the version number matches that for <strong>Red</strong> <strong>Hat</strong> <strong>Developer</strong><br />

<strong>Toolset</strong> gdb:<br />

gdb -v<br />

Example 3.3. Running the gdb Utility on the fibonacci Binary File<br />

Assuming that you have successfully compiled the fibonacci binary file as shown in Example 3.1,<br />

“Compiling a C Program With Debugging Information”, you can start debugging it with gdb by typing<br />

the following at a shell prompt:<br />

~]$ scl enable devtoolset-1.1 'gdb fibonacci'<br />

GNU gdb (GDB) <strong>Red</strong> <strong>Hat</strong> Enterprise <strong>Linux</strong> (7.4.50.20120120-43.el6)<br />

Copyright (C) 2012 Free Software Foundation, Inc.<br />

License GPLv3+: GNU GPL version 3 or later <br />

This is free software: you are free to change and redistribute it.<br />

There is NO WARRANTY, to the extent permitted by law. Type "show copying"<br />

and "show warranty" for details.<br />

This GDB was configured as "x86_64-redhat-linux-gnu".<br />

For bug reporting instructions, please see:<br />

.<br />

(gdb)<br />

3.4. Listing Source Code<br />

To view the source code of the program you are debugging, run the following command:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!