{"id":537,"date":"2022-11-30T11:15:54","date_gmt":"2022-11-30T11:15:54","guid":{"rendered":"http:\/\/qedevelopment.co.uk\/?page_id=537"},"modified":"2022-12-05T16:05:08","modified_gmt":"2022-12-05T16:05:08","slug":"gdb-the-gnu-debugger","status":"publish","type":"page","link":"https:\/\/qedevelopment.co.uk\/?page_id=537","title":{"rendered":"GDB &#8211; The GNU Debugger"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_55 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a4576e35d9d4\"><span class=\"\"><span style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a4576e35d9d4\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#GDB_%E2%80%93_The_GNU_Debugger\" title=\"GDB &#8211; The GNU Debugger\">GDB &#8211; The GNU Debugger<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#gdb_demo_file\" title=\"gdb: demo file\">gdb: demo file<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Starting_to_Debug\" title=\"Starting to Debug\">Starting to Debug<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Executing_Code\" title=\"Executing Code\">Executing Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Halting_Execution\" title=\"Halting Execution\">Halting Execution<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Breakpoints\" title=\"Breakpoints\">Breakpoints<\/a><ul class='ez-toc-list-level-4'><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Adding_Breakpoints\" title=\"Adding Breakpoints\">Adding Breakpoints<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Deleting_Disabling_Breakpoints\" title=\"Deleting\/ Disabling Breakpoints\">Deleting\/ Disabling Breakpoints<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Watchpoint\" title=\"Watchpoint\">Watchpoint<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Catchpoint\" title=\"Catchpoint\">Catchpoint<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#ReadingWriting_Data\" title=\"Reading\/Writing Data\">Reading\/Writing Data<\/a><ul class='ez-toc-list-level-3'><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Working_with_Variables\" title=\"Working with Variables\">Working with Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Working_with_Memory\" title=\"Working with Memory \">Working with Memory <\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Dumping_Restoring_From_File\" title=\"Dumping \/ Restoring From File\">Dumping \/ Restoring From File<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\/#Navigating_the_Stack\" title=\"Navigating the Stack\">Navigating the Stack<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"GDB_%E2%80%93_The_GNU_Debugger\"><\/span>GDB &#8211; The GNU Debugger<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The GNU Debugger (GDB) is a utility which works with an application and allows a user to analyze what a piece of software is doing whilst it executes. Specifically GDB allows a user to:<\/p>\n\n\n\n<ul><li>start a program and specify command line options for that program on a local machine, or to start it on a remote machine and connect to that machine via a second.<\/li><li>stop the execution of a program when any one or more of a number of criteria are satisfied.<\/li><li>examine the status of a stopped program in terms of memory\/register content.<\/li><li>to change the content of both memory and registers of a stopped program.<\/li><\/ul>\n\n\n\n<p>In order to demonstrate some of the features gdb&#8217;s features we will be working with the following example code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#include&lt;stdio.h&gt;\n\nint call_02(int var) {\n  int *foo = NULL;\n\n  *foo = var * 2;\n  return *foo;\n}\n\nint call_01(int var) {\n  int temp;\n  temp = var + 1;\n  try {\n    call_02(temp);\n  } catch(\u2026) {\n    temp = temp + 3;\n  }\n  return temp;\n}\n\nint main(void) {\n  int var1 = 0;\n  int var2 = 2;\n \n  var2 = call_01(var1);\n  printf(\"%d\\n\",var2);\n  return 0;\n}<\/pre>\n\n\n<div class='w3eden'><!-- WPDM Link Template: Default Template -->\n\n<div class=\"link-template-default card mb-2\">\n    <div class=\"card-body\">\n        <div class=\"media\">\n            <div class=\"mr-3 img-48\"><img class=\"wpdm_icon\" alt=\"Icon\" src=\"data:image\/svg+xml;base64,ICAgICAgICAgICAgPHN2ZyBpZD0iTGF5ZXJfNmE0NTc2ZTM1OTY5MCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNTEyIDUxMjsiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDUxMiA1MTIiCiAgICAgICAgICAgICAgICAgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+PHN0eWxlCiAgICAgICAgICAgICAgICAgICAgICAgIHR5cGU9InRleHQvY3NzIj4KICAgICAgICAgICAgICAgICAgICAuc3RfNmE0NTc2ZTM1OTY5MF8wIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmlsbDogcmdiYSgzOCwgMTU3LCAyMzksIDAuMyk7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAuc3RfNmE0NTc2ZTM1OTY5MF8xIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmlsbDogcmdiYSgzOCwgMTU3LCAyMzksIDAuOSk7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAuc3RfNmE0NTc2ZTM1OTY5MF8yIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmlsbDogIzI2OWRlZjsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIC5zdF82YTQ1NzZlMzU5NjkwXzMgewogICAgICAgICAgICAgICAgICAgICAgICBmaWxsOiAjRkZGRkZGOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIDwvc3R5bGU+CiAgICAgICAgICAgICAgICA8ZyBpZD0iWE1MSURfMTY4XyI+CiAgICAgICAgICAgICAgICAgICAgPGcgaWQ9IlhNTElEXzgzXyI+CiAgICAgICAgICAgICAgICAgICAgICAgIDxwb2x5Z29uIGNsYXNzPSJzdF82YTQ1NzZlMzU5NjkwXzAiIGlkPSJYTUxJRF84N18iIHBvaW50cz0iMzMwLjcsNiA4Ny45LDYgODcuOSw1MDYgNDQ5LjIsNTA2IDQ0OS4yLDEyMi44ICAgIi8+CiAgICAgICAgICAgICAgICAgICAgICAgIDxwb2x5Z29uIGNsYXNzPSJzdF82YTQ1NzZlMzU5NjkwXzEiIGlkPSJYTUxJRF84Nl8iIHBvaW50cz0iMzMwLjcsNiA0NDkuMiwxMjIuOCAzMzAuNywxMjIuOCAgICIvPgogICAgICAgICAgICAgICAgICAgICAgICA8cmVjdCBjbGFzcz0ic3RfNmE0NTc2ZTM1OTY5MF8xIiBoZWlnaHQ9IjE1Ni4xIiBpZD0iWE1MSURfODVfIiB3aWR0aD0iMzI5IiB4PSI2Mi44IiB5PSIyOTguOCIvPgogICAgICAgICAgICAgICAgICAgICAgICA8cG9seWdvbiBjbGFzcz0ic3RfNmE0NTc2ZTM1OTY5MF8yIiBpZD0iWE1MSURfODRfIiBwb2ludHM9IjYyLjgsNDU0LjkgODcuOSw0NzYuMSA4Ny45LDQ1NC45ICAgIi8+CiAgICAgICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICAgICAgICAgIDxnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgaWQ9IlhNTElEXzMxMTNfIj4KICAgICAgICAgICAgICAgICAgICAgICAgPHRleHQgeD0iMjAlIiBmaWxsPSJ3aGl0ZSIgc3R5bGU9ImZvbnQtZmFtaWx5OiBzYW5zLXNlcmlmO2ZvbnQtc2l6ZTogNzI1JTtmb250LXdlaWdodDogYm9sZDsiCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHk9IjgyJSI+QzwvdGV4dD4KICAgICAgICAgICAgICAgICAgICA8L2c+CiAgICAgICAgICAgICAgICA8L2c+CiAgICAgICAgPC9zdmc+CiAgICAgICAgICAgIA==\" \/><\/div>\n            <div class=\"media-body\">\n                <h3 class=\"package-title\"><span class=\"ez-toc-section\" id=\"gdb_demo_file\"><\/span><a href='https:\/\/qedevelopment.co.uk\/?wpdmpro=gdb-demo-file'>gdb: demo file<\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n                <div class=\"text-muted text-small\"><i class=\"fas fa-copy\"><\/i> 1 file(s) <i class=\"fas fa-hdd ml-3\"><\/i> 0.35 KB<\/div>\n            <\/div>\n            <div class=\"ml-3\">\n                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl=\"https:\/\/qedevelopment.co.uk\/?wpdmpro=gdb-demo-file&wpdmdl=593&refresh=6a4576e3596b81782937315\">Download<\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n<\/div>\n\n\n\n<p>which can be compiled using the command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ g++ -g main.c<\/pre>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"Starting_to_Debug\"><\/span>Starting to Debug<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Starting the debug process going is as simple as entering the command followed by the location of the executable you want to debug. If you need to run with arguments then the command is slightly more involved as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ gdb --args &lt;executable&gt; &lt;arg1&gt; &lt;arg2&gt; &lt;arg3&gt; ...<\/pre>\n\n\n\n<p>An alternative to providing the arguments from the command line is to start gdb without arguments and supply then once gdb is running.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ gdb &lt;executable&gt;\n(gdb) r &lt;arg1&gt; &lt;arg2&gt; &lt;arg3&gt; ...<\/pre>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"Executing_Code\"><\/span>Executing Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are a number of ways in which you may want to execute code. At the most basic level you may want to execute a single machine instruction &#8220;stepi&#8221;. At a source code level you may want to step through a single line of source using the &#8220;step&#8221; command (abbreviated to s). In both cases a numeric argument can be appended which will be the number of times to step. To step through code but not enter any functions there is the &#8220;next&#8221; command (abbreviated n) which again can take a numeric argument. The command &#8220;nexti&#8221; provides the same functionality at the machine code level. If the user wants to exit the current function then there is the &#8220;finish&#8221; command (abbreviated as &#8220;fin&#8221;), whilst to exit a loop there is the &#8220;until&#8221; command (abbreviated as &#8220;u&#8221;) which executes until the source after the current line is reached or the specified location if an appropriate argument is given.<\/p>\n\n\n\n<p>To execute code from the current position until completion or the next breakpoint there is the command &#8220;continue&#8221; (abbreviated c), and to restart execution from the beginning the user enters &#8220;run&#8221; (abbreviated r).<\/p>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"Halting_Execution\"><\/span>Halting Execution<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Execution of the code can be halted at specific locations in the code dependent on a given criteria (breakpoints) or when a specified location is read or altered (watchpoints). It is also possible to halt an event such as the throwing of an exception (catchpoint).<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Breakpoints\"><\/span>Breakpoints<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Breakpoints are locations within the code at which the execution may be halted and control returned to gdb according to the specified criteria. When a breakpoint is hit gdb will return the location of that breakpoint together with the number of times it has been hit. It is possible to list the current breakpoints (active and inactive) using the command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) i b <\/pre>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Adding_Breakpoints\"><\/span>Adding Breakpoints<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Breakpoints are specified busing the &#8216;b&#8217; command followed by a location and an optional condition. The location can be specified as either a function, an offset from the current position, a line number in either the current or another specified file or an address. If the break command is used without and arguments then a breakpoint is added at the next instruction to be executed in the current stack frame. Commands are generally of the form shown below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) b &lt;location&gt; if &lt;condition&gt; <\/pre>\n\n\n\n<p>where location is of the form<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) b &lt;function&gt;\n(gdb) b &lt;file:function&gt;\n(gdb) b &lt;line number&gt;\n(gdb) b &lt;file:line number&gt;\n(gdb) b &lt;+offset&gt;\n(gdb) b &lt;-offset&gt;\n(gdb) b *&lt;address&gt;\n(gdb) b<\/pre>\n\n\n\n<p>Conditions are boolean expressions in the appropriate programming language e.g.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) b &lt;function&gt; if foofoo == -1\n(gdb) b &lt;file:line number&gt; if *pntr != 0<\/pre>\n\n\n\n<p>Conditions can be modified at any time using the condition command followed by the breakpoint number and the new condition.<\/p>\n\n\n\n<h4><span class=\"ez-toc-section\" id=\"Deleting_Disabling_Breakpoints\"><\/span>Deleting\/ Disabling Breakpoints<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Breakpoints can be deleted, disabled, or re-enabled on a singlar or multiple basis. Where a specific breakpoint is to be manipulated it must be identified by its number as indicated when listing breakpoints. Breakpoints 1, 3, and 4 could be deleted, disabled, and re-enabled as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) delete 1 3 4\n(gdb) disable 1 3 4\n(gdb) enable 1 3 4<\/pre>\n\n\n\n<p>If the numbers are omitted following any of these commands then all breakpoints will be deleted, disabled, or re-enabled.<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Watchpoint\"><\/span>Watchpoint<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Watchpoints are triggered when memory at a given address is manipulated in some way. A break on read\/write access to a memory location can be requested using the command below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) watch *&lt;address&gt;<\/pre>\n\n\n\n<p>Alternatively, it is also possible to request a break when a given value is written into a location.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) watch *&lt;address&gt; == &lt;value&gt;<\/pre>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Catchpoint\"><\/span>Catchpoint<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Setting catchpoints causes the debugger to stop execution as a result of a program event. Typically events are either throw or catch although other events are available under HP-UX. In the example below we have set a catchpoint on the throw event. This is triggered in call_02 when there is an attempt to use a NULL pointer. The output shows that the event was triggered by line 7 of the code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) catch throw\nCatchpoint 1 (throw)\n(gdb) r\nStarting program: a.out \nProgram received signal SIGSEGV, Segmentation fault.\n0x0000555555555166 in call_02 (var=1) at main.c:7\n7      *foo = var * 2;\n(gdb) bt\n0  0x0000555555555166 in call_02 (var=1) at main.c:7\n1  0x0000555555555192 in call_01 (var=0) at main.c:18\n2  0x00005555555551bb in main () at main.c:32<\/pre>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"ReadingWriting_Data\"><\/span>Reading\/Writing Data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Working_with_Variables\"><\/span>Working with Variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The variables local to a region can be viewed using the command info locals as shown below. Alternatively you could also request the display of specific variables and the state the way in which they are to be displayed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) b main.c:32\nBreakpoint 1 at 0x11b1: file main.c, line 32.\n(gdb) r\nStarting program: a.out \nBreakpoint 1, main () at main.c:32\n32      var2 = call_01(var1);\n(gdb) info locals\nvar1 = 0\nvar2 = 2<\/pre>\n\n\n\n<p>Variables can be modified using gdb. The example below shows how the value of var2 is modified to -1 and displayed using the &#8220;print&#8221; command (abbreviated to p). The example also shows that it is possible to cast this variable and display it in both decimal and hex formats.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) set var2=-1\n(gdb) p var2\n$6 = -1\n(gdb) p (unsigned int) var2\n$7 = 4294967295\n(gdb) p\/x (unsigned int) var2\n$8 = 0xffffff<\/pre>\n\n\n\n<table id=\"tablepress-10-no-2\" class=\"tablepress tablepress-id-10\">\n<thead>\n<tr class=\"row-1 odd\">\n\t<th class=\"column-1\">Specifier<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-hover\">\n<tr class=\"row-2 even\">\n\t<td class=\"column-1\">x<\/td><td class=\"column-2\">Print the binary representation in hexadecimal<\/td>\n<\/tr>\n<tr class=\"row-3 odd\">\n\t<td class=\"column-1\">d<\/td><td class=\"column-2\">Print the binary representation in decimal<\/td>\n<\/tr>\n<tr class=\"row-4 even\">\n\t<td class=\"column-1\">u<\/td><td class=\"column-2\">Print the binary representation as an unsigned decimal<\/td>\n<\/tr>\n<tr class=\"row-5 odd\">\n\t<td class=\"column-1\">o<\/td><td class=\"column-2\">Print the binary representation in octal<\/td>\n<\/tr>\n<tr class=\"row-6 even\">\n\t<td class=\"column-1\">t<\/td><td class=\"column-2\">Print the value in binary<\/td>\n<\/tr>\n<tr class=\"row-7 odd\">\n\t<td class=\"column-1\">a<\/td><td class=\"column-2\">Print an absolute address and as an offset from the nearest preceding symbol<\/td>\n<\/tr>\n<tr class=\"row-8 even\">\n\t<td class=\"column-1\">c<\/td><td class=\"column-2\">Print the numerical value and the character representation. If the value of the character is greater than the 7-bit ASCII value the character representation is replaced with an octal value.<\/td>\n<\/tr>\n<tr class=\"row-9 odd\">\n\t<td class=\"column-1\">f<\/td><td class=\"column-2\">Print the value in floating point representation<\/td>\n<\/tr>\n<tr class=\"row-10 even\">\n\t<td class=\"column-1\">s<\/td><td class=\"column-2\">Represent the data as a string<\/td>\n<\/tr>\n<tr class=\"row-11 odd\">\n\t<td class=\"column-1\">z<\/td><td class=\"column-2\">Print in hexadecimal format but with leading zeros<\/td>\n<\/tr>\n<tr class=\"row-12 even\">\n\t<td class=\"column-1\">i<\/td><td class=\"column-2\">Print the address and assembler for the given location (this format is only applicable for use with the x command).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-10-no-2 from cache -->\n\n\n\n<h3>Working with Memory<a href=\"http:\/\/\n&lt;table id=&quot;tablepress-10&quot; class=&quot;tablepress tablepress-id-10&quot;&gt;\n&lt;thead&gt;\n&lt;tr class=&quot;row-1 odd&quot;&gt;\n\t&lt;th class=&quot;column-1&quot;&gt;Specifier&lt;\/th&gt;&lt;th class=&quot;column-2&quot;&gt;Description&lt;\/th&gt;\n&lt;\/tr&gt;\n&lt;\/thead&gt;\n&lt;tbody class=&quot;row-hover&quot;&gt;\n&lt;tr class=&quot;row-2 even&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;x&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the binary representation in hexadecimal&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-3 odd&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;d&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the binary representation in decimal&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-4 even&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;u&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the binary representation as an unsigned decimal&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-5 odd&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;o&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the binary representation in octal&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-6 even&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;t&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the value in binary&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-7 odd&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;a&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print an absolute address and as an offset from the nearest preceding symbol&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-8 even&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;c&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the numerical value and the character representation. If the value of the character is greater than the 7-bit ASCII value the character representation is replaced with an octal value.&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-9 odd&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;f&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the value in floating point representation&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-10 even&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;s&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Represent the data as a string&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-11 odd&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;z&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print in hexadecimal format but with leading zeros&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;tr class=&quot;row-12 even&quot;&gt;\n\t&lt;td class=&quot;column-1&quot;&gt;i&lt;\/td&gt;&lt;td class=&quot;column-2&quot;&gt;Print the address and assembler for the given location (this format is only applicable for use with the x command).&lt;\/td&gt;\n&lt;\/tr&gt;\n&lt;\/tbody&gt;\n&lt;\/table&gt;\n&lt;!-- #tablepress-10 from cache --&gt;\"> <\/a><\/h3>\n\n\n\n<p>Displaying the contents of memory is achieved with the &#8216;x&#8217; command. The command can be used to display multiple words of data in a specified format and of a specified size. The command is entered in the format shown below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">x\/&lt;number of words to display&gt;&lt;size of a word&gt;&lt;style of display&gt;<\/pre>\n\n\n\n<p>The size of a word is requested according to the character in the table below<\/p>\n\n\n\n<table id=\"tablepress-11\" class=\"tablepress tablepress-id-11\">\n<thead>\n<tr class=\"row-1 odd\">\n\t<th class=\"column-1\">Modifier<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-hover\">\n<tr class=\"row-2 even\">\n\t<td class=\"column-1\">b<\/td><td class=\"column-2\">byte (8-bit value)<\/td>\n<\/tr>\n<tr class=\"row-3 odd\">\n\t<td class=\"column-1\">h<\/td><td class=\"column-2\">halfward (16-bit value)<\/td>\n<\/tr>\n<tr class=\"row-4 even\">\n\t<td class=\"column-1\">w<\/td><td class=\"column-2\">word (32-bit value)<\/td>\n<\/tr>\n<tr class=\"row-5 odd\">\n\t<td class=\"column-1\">g<\/td><td class=\"column-2\">giant word (64-bit value)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-11 from cache -->\n\n\n\n<p>Whilst the style of display is specified according to the characters already described in the previous section.<\/p>\n\n\n\n<h3><span class=\"ez-toc-section\" id=\"Dumping_Restoring_From_File\"><\/span>Dumping \/ Restoring From File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If there is a need to extract the contents of memory to file this can be achieved using the dump\/append commands. Commands are entered as show below, where the format specifier is used as described in the following table.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(gdb) dump &lt;format&gt; memory &lt;filename&gt; &lt;start address&gt; &lt;end address&gt;\n(gdb) restore &lt;filename&gt; &lt;format&gt; &lt;bias&gt; &lt;start&gt; &lt;end&gt;<\/pre>\n\n\n\n<table id=\"tablepress-12\" class=\"tablepress tablepress-id-12\">\n<thead>\n<tr class=\"row-1 odd\">\n\t<th class=\"column-1\">Format<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-hover\">\n<tr class=\"row-2 even\">\n\t<td class=\"column-1\">binary<\/td><td class=\"column-2\">Data is stored in raw binary format<\/td>\n<\/tr>\n<tr class=\"row-3 odd\">\n\t<td class=\"column-1\">ihex<\/td><td class=\"column-2\">Data is stored in Intel hex format<\/td>\n<\/tr>\n<tr class=\"row-4 even\">\n\t<td class=\"column-1\">srec<\/td><td class=\"column-2\">Data is stored in motorola s-record format<\/td>\n<\/tr>\n<tr class=\"row-5 odd\">\n\t<td class=\"column-1\">tekhex<\/td><td class=\"column-2\">Data is stored in Tektronix hex format<\/td>\n<\/tr>\n<tr class=\"row-6 even\">\n\t<td class=\"column-1\">verilog<\/td><td class=\"column-2\">Data is stored in Verilog hex format<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-12 from cache -->\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"Navigating_the_Stack\"><\/span>Navigating the Stack<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>When a breakpoint is hit such as in the catchpoint example earlier you may want to examine local variables from previous stack frames. Using the up and down commands allows you to move between stack frames. Both up and down commands can be followed by a value expressing the number of stack frames to step through.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GDB &#8211; The GNU Debugger The GNU Debugger (GDB) is a utility which works with an application and allows a user to analyze what a piece of software is doing whilst it executes. Specifically GDB allows a user to: start a program and specify command line options for that program on a local machine, or &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/qedevelopment.co.uk\/?page_id=537\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;GDB &#8211; The GNU Debugger&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"page-full.php","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/pages\/537"}],"collection":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=537"}],"version-history":[{"count":25,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/pages\/537\/revisions"}],"predecessor-version":[{"id":595,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/pages\/537\/revisions\/595"}],"wp:attachment":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}