{"id":167,"date":"2013-04-22T14:17:28","date_gmt":"2013-04-22T14:17:28","guid":{"rendered":"http:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/?page_id=167"},"modified":"2016-07-04T16:50:46","modified_gmt":"2016-07-04T16:50:46","slug":"gdb","status":"publish","type":"page","link":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/software\/applications\/gdb\/","title":{"rendered":"gdb (GNU Debugger)"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>Typically a debugger is used to execute a program and pause under certain conditions (e.g. at specific line numbers) to examine the state of the program, e.g. to look at values associated with program variables. Using the debugger it is possible to step through execution of the program, line by line.<\/p>\n<h2>Restrictions on use<\/h2>\n<p>GDB can be used to debug programs written in C\/C++, Fortran and some other languages, see GDB documentation for more information. With Fortran it may be necessary to refer to some variables with a trailing underscore.<\/p>\n<p>Debugging sessions should use the interactive queue, do not run the debugger on the login node.<\/p>\n<h2>Set up procedure<\/h2>\n<p>Before using GDB a program must be compiled with the appropriate flag, e.g. <code>-g<\/code> for the Intel and GNU compilers. Note: the <code>-g<\/code> flag may change the default level of optimisation, check the compiler documentation for further information.<\/p>\n<h2>Running the application<\/h2>\n<p>A tutorial on gdb debugging is beyond the scope of this page. A tutorial can be found at <a href=\"http:\/\/www.unknownroad.com\/rtfm\/gdbtut\/gdbtoc.html\">http:\/\/www.unknownroad.com\/rtfm\/gdbtut\/gdbtoc.html<\/a>.<\/p>\n<p>The commands below show you how to start gdb correctly on the CSF. Please do not debug large complex programs on the login node.<\/p>\n<p>Debugging is an interactive process &#8211; you will usually want to enter commands in the debugger to step through your code, executing those instructions as you do so, check the value of variables, set breakpoints in the code etc. Hence you should use the interactive queue, using the SGE command <a href=\"\/csf2\/csf-user-documentation\/sge-interactive-jobs-qrsh\/\">qrsh<\/a> as shown below.<\/p>\n<h3>Debugging a Serial Program<\/h3>\n<p>To debug your serial executable (located in the current directory)<\/p>\n<pre>\r\nqrsh -cwd -V -l inter -l short gdb .\/my_program.exe\r\n<\/pre>\n<p>and wait to connect to a remote node before using GDB. In GDB, entering <code>r<\/code> will run your executable in the debugger. Enter <code>q<\/code> to quit GDB and return to the log in node.<\/p>\n<h3>Debugging an MPI Program<\/h3>\n<p>The following method can be used for small MPI jobs (a couple of cores). Running parallel jobs interactively is not normally permitted due to the small number of cores available for interactive use. We recommend using 2 cores to initially test your MPI code.<\/p>\n<p>The command below will open two <code>xterm<\/code> windows in which gdb will be running. You can enter commands in to both instances of gdb in each window. Your MPI processes will be being debugged by gdb in each window. Ensure you have the MPI modulefile loaded that you used when compiling the application.<\/p>\n<pre>\r\nqrsh -cwd -V -l inter -l short -pe smp.pe 2 mpirun -n 2 xterm -e gdb .\/my_mpi_program.exe\r\n<\/pre>\n<p>You will need to enter <code>r<\/code> in both <code>xterm<\/code> windows for the application to start working as normal inside the debugger.<\/p>\n<h2>Further info<\/h2>\n<p>Further information, including the GDB user manual, can be found <a href=\"http:\/\/www.gnu.org\/software\/gdb\/documentation\/\">here<\/a>.<\/p>\n<h2>Updates<\/h2>\n<p>None at this time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Typically a debugger is used to execute a program and pause under certain conditions (e.g. at specific line numbers) to examine the state of the program, e.g. to look at values associated with program variables. Using the debugger it is possible to step through execution of the program, line by line. Restrictions on use GDB can be used to debug programs written in C\/C++, Fortran and some other languages, see GDB documentation for more.. <a href=\"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/software\/applications\/gdb\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":31,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-167","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/pages\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/comments?post=167"}],"version-history":[{"count":5,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/pages\/167\/revisions"}],"predecessor-version":[{"id":3200,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/pages\/167\/revisions\/3200"}],"up":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/pages\/31"}],"wp:attachment":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf-apps\/wp-json\/wp\/v2\/media?parent=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}