{"id":517,"date":"2018-07-16T05:30:02","date_gmt":"2018-07-16T05:30:02","guid":{"rendered":"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=517"},"modified":"2019-05-16T09:41:13","modified_gmt":"2019-05-16T09:41:13","slug":"gnu-debugger-gdb","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/chapter\/gnu-debugger-gdb\/","title":{"rendered":"GNU Debugger (GDB)"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/KpjxqvaZF-o\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>Introduction<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">It is common phenomena that during computer program development and testing, several times the computer program may not generate correct output for a given set of input. Moreover, it is common experience of several computer programmers that the computer program may not behave as it should for the given set of input. Also, many of us would have surely faced a situation of abnormal program termination during program development. In such cases, it becomes necessary for the programmer to find out the root cause for erroneous output or unexpected behavior of the computer program.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Finding the cause of error and resolving the error is not only important but also unavoidable in the domain of computer science and information technology.<\/p>\r\n\r\n<\/div>\r\n<strong style=\"text-align: initial; font-size: 1em;\">2.\u00a0 What is debugging?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">in 1940s, Admiral Grace Hopper and her team coined two terms: \u2018bug\u2019 and \u2018debugging\u2019. In computer programming domain, the term bug is used to refer some technical error. Whereas, solving the technical errors is referred as debugging.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">In order to rectify errors in a computer program and to make it bug-free program, it becomes essential for a programmer to know about the cause of errors in the program. It means that programmer must know about the set of problematic statement or statements which are responsible for the erroneous behavior by the computer program. <\/span><em style=\"text-align: initial; font-size: 1em;\">The process of finding source<\/em> <em style=\"text-align: initial; font-size: 1em;\">of errors or bugs in a computer program is known as debugging. <\/em><span style=\"text-align: initial; font-size: 1em;\">Often, the debugging becomes challenging task for programmers for resolving logical errors.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">It is known that there are two types of errors: syntax errors and logical errors. With help of the compilation tools, it is easy to find the source of syntax errors as normally the compiler at the time of program compilation, reports about the syntax errors. So, the programmer is not required to put additional efforts for finding syntax errors in the computer program.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">However, finding source of non-syntactical errors often become a tedious job for programmers. Many times, it becomes very difficult to find errors in the self-written source code. In earlier days, programmers used to manually wander through the source code for detecting the cause of bugs from erroneous code; and such manual wandering used continue until the errors were found. The debugging process not only requires a highly skilled programmer but also depends on the complexity of the computer program.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">Nowadays several automated debugging software are available in market. Automated debugging tools are also known as debuggers. Debuggers are computer programs that widely help in testing and debugging other programs. They run other programs, empower the programmer to govern control over these programs; and thereby debuggers facilitate programmer to examine variables (which have been used in the program) for identifying error. Debuggers largely help programmers in expediting debugging computer programs.<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">Debuggers nowadays are integrated with the Integrated Development Environment (IDE). Such debuggers are also known as source level debuggers. While debugging, the source level debuggers indicate the location of errors in the source code. Whereas the other type of debuggers which are not integrated with IDE, indicate the line number where an error exists. GNU Debugger is one of the best example of such editors.<\/span><\/p>\r\n\r\n<div>\r\n\r\n<strong>3.\u00a0 GNU Debugger<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">GNU Debugger is one of the most popular debugger for UNIX &amp; LINUX family of systems for debugging programs; and study what is happening inside the program at the time of program execution. It is available under GNU Project. The GNU Debugger is also known as GDB. GDB is used for debugging programs written in various programming languages including C, C++, D, Go, Java, Fortran, Pascal etc.<\/p>\r\n&nbsp;\r\n\r\nThe feature-rich GNU Debugger software pack facilitates programmer in various error detection scenarios:\r\n\r\n<\/div>\r\n<ul>\r\n \t<li style=\"text-align: justify;\">Discovering the source of logical errors in a program is difficult just by looking at the source code. The GDB can be helpful in such cases.<\/li>\r\n \t<li style=\"text-align: justify;\">Often, the programmer desires to know value of particular variable(s) at specific point during program execution. The GDB provides facility to inspect particular variable(s) at program run time.<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify;\">Furthermore, while debugging the program, GDB allows to change values of variables to experiment the effect on program\u2019s behavior.<\/p>\r\n\r\n<ul>\r\n \t<li style=\"text-align: justify;\">During program execution, the GNU Debugger allows to test particular expression on command line.<\/li>\r\n \t<li style=\"text-align: justify;\">Sometimes, programs crash abnormally, which generally results into core dump. In such cases it becomes necessary for programmer to detect the statement or expression which is responsible for the abnormal program crash. The GDB helps in finding cause for abnormal program termination.<\/li>\r\n \t<li style=\"text-align: justify;\">Many times, execution of function fails due to error(s). In such cases, programmer would obviously wish to recognize the line number of program which contains call to the erroneous function. The GDB is beneficial in solving such cases.<\/li>\r\n<\/ul>\r\nHowever, the GDB can be used with only executable program binaries and not with the program source code.\r\n<ol start=\"4\">\r\n \t<li><strong> How does GDB function?<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">GDB may be used either to understand the behavior of currently running program for the sake of identifying logical errors; or to analyze the coredump generated due to the abnormal program termination.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The GDB can be used in two ways. In one way, the programmer may let the program execute up to a specific point, then pause the program and inspect values of desired variables at that point. Whereas the other approach of GDB usage facilitates to step through the program line by line and inspect values of desired variables at particular line while stepping through the program.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">For finding the cause of error and stepping through a binary executable program, the GNU Debugger uses Symbol table. Symbol table is generated by gcc compiler. The symbol table maps instructions in the compiled binary executable to their corresponding line, variable or function in the source code, such as:<\/p>\r\n&nbsp;\r\n\r\nProgram instruction =&gt; item name, item type, source file, line number\u2026\r\n<ol start=\"5\">\r\n \t<li><strong> Make GDB available in your system<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">Issue the gdb on command-line to check whether the GNU Debugger GDB is installed in your system not. If the GDB is already available in your system, the gdb shell will be displayed as shown in Figure 1.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-518 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A.jpg\" alt=\"\" width=\"720\" height=\"206\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 1: gdb is available<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">If the GDB is not available in your system, an error message \u2018gdb: command not found\u2019 will be reported on command line. In such case, you may install GDB in one of the two ways. One way to install GDB is install prebuilt binaries. Whereas other way is to download GDB source code; compile the source code and install it.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The first approach of installation is straight forward. Use the following two commands to install prebuild GDB binaries from preconfigured repositories.<\/p>\r\n\r\n<ul>\r\n \t<li># yum update all<\/li>\r\n \t<li># yum install gdb-8.0<\/li>\r\n \t<li># debuginfo-install glibc-&lt;appropriate version&gt;<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify;\">On the other side, the second approach offers more flexibility; it involves downloading the latest source code; if required customize it as per your requirements; compile the source code and install the resultant binaries.<\/p>\r\n\r\n<ol>\r\n \t<li>Download the GDB source code.<\/li>\r\n<\/ol>\r\n<ul>\r\n \t<li># wget \u201chttps:\/\/ftp.gnu.org\/gnu\/gdb\/gdb-8.0.tar.gz\u201d<\/li>\r\n<\/ul>\r\n<ol start=\"2\">\r\n \t<li>Extract the downloaded GDB source code (compressed file) in the previous step.<\/li>\r\n<\/ol>\r\n<ul>\r\n \t<li># tar -xvzf gdb-8.0.tar.gz<\/li>\r\n<\/ul>\r\n<ol start=\"4\">\r\n \t<li style=\"text-align: justify;\">Customize the extracted GDB source code (if required). Configure the source code (GDB comes with prebuilt configure script that helps automating preparing GDB for installation) and compile it.\r\n<ul>\r\n \t<li># cd gdb-8.0<\/li>\r\n \t<li># .\/configure<\/li>\r\n \t<li># make<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li>Install GDB.<\/li>\r\n<\/ol>\r\n<ul>\r\n \t<li># make install<\/li>\r\n \t<li># gdb \u2013version<\/li>\r\n<\/ul>\r\n<p style=\"text-align: justify;\">Successful completion of the above mentioned steps will result in availability of the GNU Debugger in your system.<\/p>\r\n\r\n<ol start=\"6\">\r\n \t<li><strong> Some commonly used GDB commands<\/strong><\/li>\r\n<\/ol>\r\n<p style=\"text-align: justify;\">Being a command line software, the GNU Debugger offers a rich pool of facilities at the gdb shell. Some of the commonly used commands in gdb shell are described in following Table 1:<\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-519 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A1.png\" alt=\"\" width=\"452\" height=\"516\" \/><\/p>\r\n&nbsp;\r\n\r\n<strong>Debugging programs using GDB<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">This section explains how to debug program written in C\/C++ language. As described earlier in the \u2018How GDB functions?\u2019 section, let us recall that the GNU Debugger can be used mainly for two purposes:<\/p>\r\n&nbsp;\r\n\r\n(i) For understanding behavior of currently running program for the sake of identifying logical errors and\/or inspecting variables\/expressions\/functions.\r\n\r\n(ii) For analyzing the automatically generated core-dump due to abnormal program termination.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us see how to debug a particular running program. In order to debug the C\/C++ programs with GDB, it is recommended to compile and build the program with the debugging symbol table enabled. For generating symbol table, use \u2013g option while compiling the program using gcc as shown below:<\/p>\r\n&nbsp;\r\n\r\n# gcc \u2013g someProgram.c \u2013o someProgram.out\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The above command will compile the source file someProgram.c to a binary executable file someProgram.out. Presence of the option \u2013g will ensure generation of symbol table which will enable the as well for debugging purpose. However one should remember that failing to provide the \u2013g option while compiling the program, will surely generate the executable file (in case source file contains no errors); but no suitable support will be available in gdb while debugging such cases (Figure 2).<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-520 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-2.jpg\" alt=\"\" width=\"731\" height=\"239\" \/><\/p>\r\n\r\n<div>\r\n<p style=\"text-align: center;\">Figure 2: Effect of program compilation without generating symbol table<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Now our binary executable someProgram.out is ready for debugging. For debugging purpose, the executable should be run in gdb shell instead of running it directly on bash shell, as shown in the following command:<\/p>\r\n\r\n<\/div>\r\n# gdb someProgram.out <em>gdb<\/em><em>)<\/em>\r\n\r\n<em>(in this case someProgram.out will run inside<\/em>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">While the program is running inside GDB, use various GDB commands (Table 1) for analyzing and\/or controlling program behavior.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-521 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-2.jpg\" alt=\"\" width=\"676\" height=\"324\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 3: Erroneous program to calculate factorial of a number<\/p>\r\n<strong>Example 1<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us understand usage of the GNU Debugger using the example shown in Figure 3. Figure 3 describes a program factorial.c for calculating factorial of a given number; the program is erroneous however as it contains logical error. Total three variables are used in the program factorial.c. A variable \u2018n\u2019 is used to store value of a number whose factorial is required to be calculated. For instance, the variable \u2018n\u2019 contains value 5, i.e. the current version of program will calculate factorial of 5. A variable \u2018factorial\u2019 is used to store the computed result factorial of a value stored in the variable \u2018n\u2019; \u2018factorial\u2019 is initialized with 1. Role of variable \u2018i\u2019 is to act as a loop variable.<\/p>\r\n&nbsp;\r\n\r\nLet us compile the program factorial.c and generate symbol table (Figure 4):\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-522 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-2.jpg\" alt=\"\" width=\"629\" height=\"109\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 4: Compile source file and generate symbol table<\/p>\r\n&nbsp;\r\n\r\nLaunch GNU Debugger to debug the executable factorial.out (Figure 5):\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-523 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-2.jpg\" alt=\"\" width=\"699\" height=\"236\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 5: Launch GDB for factorial.out<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us set a breakpoint on the function main()(Figure 6). See that command \u2018b main\u2019 is used to set breakpoint. GDB shows resultant output mentioning the breakpoint set at the address containing the function main(). The output also mentions the source file name and line number of the main()function in the source.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-524 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-1.jpg\" alt=\"\" width=\"473\" height=\"56\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 6: Set breakpoint on the function main()<\/p>\r\nNow instruct GDB to start running the program (Figure 7):\r\n\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-525 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-1.jpg\" alt=\"\" width=\"564\" height=\"109\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 7: Start running the program<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Figure 7 indicates that as breakpoint was set on the function main()(Figure 6), gdb stops program execution, and now it is waiting for further instruction from user. Now step through the program using command \u2018s\u2019 upto line number 12 (Figure 8).<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-526 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A9-1.jpg\" alt=\"\" width=\"644\" height=\"145\" \/><\/p>\r\n\r\n<div>\r\n<p style=\"text-align: center;\"><strong>Figure 8: step through the program<\/strong><\/p>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify;\">Inspect the program variables n, factorial and i by printing them on gdb shell prompt using the \u2018p\u2019 command (Figure 9):<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-527 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A10-1.jpg\" alt=\"\" width=\"429\" height=\"109\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 9: Inspect program variables<\/p>\r\n<p style=\"text-align: justify;\">We may step through the program upto line number 15 and inspect the variables again. Also observe that now the execution control has come out from the loop, i.e. the control has iterated the do-while loop only once (Figure 10).<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Values of \u2018factorial\u2019 and \u2018i\u2019 are not acceptable as they should be 120 and 0 after successful completion of the do-while loop. However, the output value of \u2018i\u2019 seems to be doubtful and smells a logical error. After the loop is completed, value of \u2018i\u2019 should be 0, but the actual output value of \u2018i\u2019 differs from the expected value of \u2018i\u2019. It gives a hint that there is some problem with loop condition. Due to wrong implementation of the loop condition (i &lt;= 1), the program is not behaving as it should. Instead, the correct loop condition should be (i &gt;= 1). Finally, using the GNU Debugger we have identified source for the logical error.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-528 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A11-1.jpg\" alt=\"\" width=\"603\" height=\"200\" \/><\/p>\r\n<p style=\"text-align: center;\"><em>Figure 10<\/em>: Step through the program further and inspect variables<\/p>\r\n&nbsp;\r\n\r\n<strong>Example 2<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Now let us take one more example C++ program to understand how to deal with user-defined functions in GDB (Figure 11).<\/p>\r\n<img class=\"size-full wp-image-529 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A12-1.jpg\" alt=\"\" width=\"587\" height=\"394\" \/>\r\n<p style=\"text-align: center;\"><strong>Figure 11: C++ program with user-defined function<\/strong><\/p>\r\n&nbsp;\r\n\r\nCompile the C++ program shown in Figure 11 with the \u2013g option to enable debugging.\r\n\r\n# g++ -g detectError.cc \u2013o detectError.x\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Start debugging the detectError.x program and set breakpoint at the main() function. Run the program and step to line number 14. Stepping further to next line number 15, involves a call to user-defined function divide(), which will land the debugger inside the divide function i.e. line number 7. Continuing line-by-line stepping through the divide()function will eventually complete the function execution and will eventually turn the debugging control back to the parent function main() i.e. at line number 15 (Figure 12).<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-530 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A13-1.jpg\" alt=\"\" width=\"547\" height=\"217\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 12: step through the program<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Further stepping through the main(), function will again move the gdb control to line 7 into the detectError() fuction. However, you may skip tracing the function using the gdb command \u2018c\u2019. Inspect the values parameters of the detectError()function on gdb shell (Figure 13).<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-531 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A14-1.jpg\" alt=\"\" width=\"599\" height=\"359\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 13: Inspect function parameters and skip tracing function<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Use \u2018where\u2019 command to know about related functions causing crash and corresponding line numbers in functions. Use \u2018list\u2019 (or \u2018l\u2019) command to view the context of crash (Figure 14).<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-532 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A15-1.jpg\" alt=\"\" width=\"562\" height=\"271\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 14: Usage of where and list commands<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">While debugging in the gdb shell, value of variables may be modified using \u2018set\u2019 command, e.g. set d = 9. Use up (or u) and down (or d) commands for moving up or down in the function stack.<\/p>\r\n<p style=\"text-align: justify;\">Having understood how to debug running programs, now let us see how to deal with abnormal program termination resulting into coredump. Following Example 3 describes a scenario representing program crash and coredump.<\/p>\r\n&nbsp;\r\n\r\n<strong>Example 3<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Source code of the faulty C++ program coredump.cc is shown in Figure 15. The program consists of a user defined function setVal (int *pInt, int val) with two parameters: int *pInt and int val. Job of the setVal() function is just to store value of the integer parameter val at memory location pointed by the integer pointer pInt. The setVal() function is called twice in main(): once for assigning value 7 to integer variable x (line no. 14) and once for assigning value 9 to integer pointer p (line no. 18). Compile the program with \u2013g option, observe execution and abnormal termination of program (Figure 16).<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-533 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A16-1.jpg\" alt=\"\" width=\"629\" height=\"397\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\">Figure 15: A faulty program<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-534 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A17-2.jpg\" alt=\"\" width=\"547\" height=\"106\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 16: Coredump due to abnormal program termination<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In figure 16, it is seen that the program crashes abnormally and core is dumped. Let us debug program and coredump to find out the cause and location of error. The coredump debug output is shown in Figure 17. In Figure 17 it is seen that stepping through the program up to line no. 17 and then inside the function call at line no. 6, the program crashes due to a signal SIGSEGV. In Linux, the SIGSEGV signal represents segmentation fault indicating that the program tried to access (dereference) an invalid memory location which was either not allowed to access or allocated at all to the program. It means that there is some problem with the value of the formal parameter pInt (pointer to some memory location) of the function setVal()i.e. the memory location which was passed to the function as parameter could be invalid. Investigating the related actual parameter \u2018int* p\u2019 in the function call (line no. 17 and 18) reveals that the variable *p is not initialized at all. It means the pointer p possessed some garbage memory-address, i.e. the pointer p was pointing to some invalid\/inaccessible memory location. Thus the source of error is found in the program using the GNU Debugger.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-535 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A18-1.jpg\" alt=\"\" width=\"603\" height=\"432\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 17: Program termination due to Segmentation fault<\/p>\r\n&nbsp;\r\n\r\n<strong>Summary<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Identifying the cause of error and resolving the error is one of the important and unavoidable phases in application development. The process of finding source of errors or bugs in a computer program is known as debugging. Identifying source of logical and non-syntactical errors becomes challenging task programmers. Nowadays there are many debugger tools available. GNU Debugger is a widely accepted software for UNIX &amp; LINUX family of systems for debugging programs written in various programming languages. GDB is used for investigating behavior of currently running program for inspecting variables\/expressions\/functions for given set of input.<\/p>\r\n\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on GNU Debugger (GDB)<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/KpjxqvaZF-o\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<strong>References and Further Reading<\/strong>\r\n<ul>\r\n \t<li>GDB Pocket Reference, Arnold Robbins, O\u2019Reilly Publication<\/li>\r\n \t<li>The Art of Debugging with GDB and DDD, Norman Matloff, Peter Salzman, O\u2019Reilly Publication<\/li>\r\n \t<li>Web resource: GDB: The GNU Project Debugger - Official Documentation, https:\/\/www.gnu.org\/software\/gdb\/documentation\/<\/li>\r\n<\/ul>","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/KpjxqvaZF-o\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>Introduction<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">It is common phenomena that during computer program development and testing, several times the computer program may not generate correct output for a given set of input. Moreover, it is common experience of several computer programmers that the computer program may not behave as it should for the given set of input. Also, many of us would have surely faced a situation of abnormal program termination during program development. In such cases, it becomes necessary for the programmer to find out the root cause for erroneous output or unexpected behavior of the computer program.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Finding the cause of error and resolving the error is not only important but also unavoidable in the domain of computer science and information technology.<\/p>\n<\/div>\n<p><strong style=\"text-align: initial; font-size: 1em;\">2.\u00a0 What is debugging?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">in 1940s, Admiral Grace Hopper and her team coined two terms: \u2018bug\u2019 and \u2018debugging\u2019. In computer programming domain, the term bug is used to refer some technical error. Whereas, solving the technical errors is referred as debugging.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">In order to rectify errors in a computer program and to make it bug-free program, it becomes essential for a programmer to know about the cause of errors in the program. It means that programmer must know about the set of problematic statement or statements which are responsible for the erroneous behavior by the computer program. <\/span><em style=\"text-align: initial; font-size: 1em;\">The process of finding source<\/em> <em style=\"text-align: initial; font-size: 1em;\">of errors or bugs in a computer program is known as debugging. <\/em><span style=\"text-align: initial; font-size: 1em;\">Often, the debugging becomes challenging task for programmers for resolving logical errors.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">It is known that there are two types of errors: syntax errors and logical errors. With help of the compilation tools, it is easy to find the source of syntax errors as normally the compiler at the time of program compilation, reports about the syntax errors. So, the programmer is not required to put additional efforts for finding syntax errors in the computer program.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">However, finding source of non-syntactical errors often become a tedious job for programmers. Many times, it becomes very difficult to find errors in the self-written source code. In earlier days, programmers used to manually wander through the source code for detecting the cause of bugs from erroneous code; and such manual wandering used continue until the errors were found. The debugging process not only requires a highly skilled programmer but also depends on the complexity of the computer program.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">Nowadays several automated debugging software are available in market. Automated debugging tools are also known as debuggers. Debuggers are computer programs that widely help in testing and debugging other programs. They run other programs, empower the programmer to govern control over these programs; and thereby debuggers facilitate programmer to examine variables (which have been used in the program) for identifying error. Debuggers largely help programmers in expediting debugging computer programs.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">Debuggers nowadays are integrated with the Integrated Development Environment (IDE). Such debuggers are also known as source level debuggers. While debugging, the source level debuggers indicate the location of errors in the source code. Whereas the other type of debuggers which are not integrated with IDE, indicate the line number where an error exists. GNU Debugger is one of the best example of such editors.<\/span><\/p>\n<div>\n<p><strong>3.\u00a0 GNU Debugger<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">GNU Debugger is one of the most popular debugger for UNIX &amp; LINUX family of systems for debugging programs; and study what is happening inside the program at the time of program execution. It is available under GNU Project. The GNU Debugger is also known as GDB. GDB is used for debugging programs written in various programming languages including C, C++, D, Go, Java, Fortran, Pascal etc.<\/p>\n<p>&nbsp;<\/p>\n<p>The feature-rich GNU Debugger software pack facilitates programmer in various error detection scenarios:<\/p>\n<\/div>\n<ul>\n<li style=\"text-align: justify;\">Discovering the source of logical errors in a program is difficult just by looking at the source code. The GDB can be helpful in such cases.<\/li>\n<li style=\"text-align: justify;\">Often, the programmer desires to know value of particular variable(s) at specific point during program execution. The GDB provides facility to inspect particular variable(s) at program run time.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Furthermore, while debugging the program, GDB allows to change values of variables to experiment the effect on program\u2019s behavior.<\/p>\n<ul>\n<li style=\"text-align: justify;\">During program execution, the GNU Debugger allows to test particular expression on command line.<\/li>\n<li style=\"text-align: justify;\">Sometimes, programs crash abnormally, which generally results into core dump. In such cases it becomes necessary for programmer to detect the statement or expression which is responsible for the abnormal program crash. The GDB helps in finding cause for abnormal program termination.<\/li>\n<li style=\"text-align: justify;\">Many times, execution of function fails due to error(s). In such cases, programmer would obviously wish to recognize the line number of program which contains call to the erroneous function. The GDB is beneficial in solving such cases.<\/li>\n<\/ul>\n<p>However, the GDB can be used with only executable program binaries and not with the program source code.<\/p>\n<ol start=\"4\">\n<li><strong> How does GDB function?<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">GDB may be used either to understand the behavior of currently running program for the sake of identifying logical errors; or to analyze the coredump generated due to the abnormal program termination.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The GDB can be used in two ways. In one way, the programmer may let the program execute up to a specific point, then pause the program and inspect values of desired variables at that point. Whereas the other approach of GDB usage facilitates to step through the program line by line and inspect values of desired variables at particular line while stepping through the program.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">For finding the cause of error and stepping through a binary executable program, the GNU Debugger uses Symbol table. Symbol table is generated by gcc compiler. The symbol table maps instructions in the compiled binary executable to their corresponding line, variable or function in the source code, such as:<\/p>\n<p>&nbsp;<\/p>\n<p>Program instruction =&gt; item name, item type, source file, line number\u2026<\/p>\n<ol start=\"5\">\n<li><strong> Make GDB available in your system<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Issue the gdb on command-line to check whether the GNU Debugger GDB is installed in your system not. If the GDB is already available in your system, the gdb shell will be displayed as shown in Figure 1.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-518 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A.jpg\" alt=\"\" width=\"720\" height=\"206\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A.jpg 720w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A-300x86.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A-65x19.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A-225x64.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A-350x100.jpg 350w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 1: gdb is available<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">If the GDB is not available in your system, an error message \u2018gdb: command not found\u2019 will be reported on command line. In such case, you may install GDB in one of the two ways. One way to install GDB is install prebuilt binaries. Whereas other way is to download GDB source code; compile the source code and install it.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The first approach of installation is straight forward. Use the following two commands to install prebuild GDB binaries from preconfigured repositories.<\/p>\n<ul>\n<li># yum update all<\/li>\n<li># yum install gdb-8.0<\/li>\n<li># debuginfo-install glibc-&lt;appropriate version&gt;<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">On the other side, the second approach offers more flexibility; it involves downloading the latest source code; if required customize it as per your requirements; compile the source code and install the resultant binaries.<\/p>\n<ol>\n<li>Download the GDB source code.<\/li>\n<\/ol>\n<ul>\n<li># wget \u201chttps:\/\/ftp.gnu.org\/gnu\/gdb\/gdb-8.0.tar.gz\u201d<\/li>\n<\/ul>\n<ol start=\"2\">\n<li>Extract the downloaded GDB source code (compressed file) in the previous step.<\/li>\n<\/ol>\n<ul>\n<li># tar -xvzf gdb-8.0.tar.gz<\/li>\n<\/ul>\n<ol start=\"4\">\n<li style=\"text-align: justify;\">Customize the extracted GDB source code (if required). Configure the source code (GDB comes with prebuilt configure script that helps automating preparing GDB for installation) and compile it.\n<ul>\n<li># cd gdb-8.0<\/li>\n<li># .\/configure<\/li>\n<li># make<\/li>\n<\/ul>\n<\/li>\n<li>Install GDB.<\/li>\n<\/ol>\n<ul>\n<li># make install<\/li>\n<li># gdb \u2013version<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">Successful completion of the above mentioned steps will result in availability of the GNU Debugger in your system.<\/p>\n<ol start=\"6\">\n<li><strong> Some commonly used GDB commands<\/strong><\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Being a command line software, the GNU Debugger offers a rich pool of facilities at the gdb shell. Some of the commonly used commands in gdb shell are described in following Table 1:<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-519 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A1.png\" alt=\"\" width=\"452\" height=\"516\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1.png 452w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-263x300.png 263w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-65x74.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-225x257.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A1-350x400.png 350w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Debugging programs using GDB<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">This section explains how to debug program written in C\/C++ language. As described earlier in the \u2018How GDB functions?\u2019 section, let us recall that the GNU Debugger can be used mainly for two purposes:<\/p>\n<p>&nbsp;<\/p>\n<p>(i) For understanding behavior of currently running program for the sake of identifying logical errors and\/or inspecting variables\/expressions\/functions.<\/p>\n<p>(ii) For analyzing the automatically generated core-dump due to abnormal program termination.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us see how to debug a particular running program. In order to debug the C\/C++ programs with GDB, it is recommended to compile and build the program with the debugging symbol table enabled. For generating symbol table, use \u2013g option while compiling the program using gcc as shown below:<\/p>\n<p>&nbsp;<\/p>\n<p># gcc \u2013g someProgram.c \u2013o someProgram.out<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The above command will compile the source file someProgram.c to a binary executable file someProgram.out. Presence of the option \u2013g will ensure generation of symbol table which will enable the as well for debugging purpose. However one should remember that failing to provide the \u2013g option while compiling the program, will surely generate the executable file (in case source file contains no errors); but no suitable support will be available in gdb while debugging such cases (Figure 2).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-520 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-2.jpg\" alt=\"\" width=\"731\" height=\"239\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-2.jpg 731w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-2-300x98.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-2-65x21.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-2-225x74.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A3-2-350x114.jpg 350w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/p>\n<div>\n<p style=\"text-align: center;\">Figure 2: Effect of program compilation without generating symbol table<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Now our binary executable someProgram.out is ready for debugging. For debugging purpose, the executable should be run in gdb shell instead of running it directly on bash shell, as shown in the following command:<\/p>\n<\/div>\n<p># gdb someProgram.out <em>gdb<\/em><em>)<\/em><\/p>\n<p><em>(in this case someProgram.out will run inside<\/em><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">While the program is running inside GDB, use various GDB commands (Table 1) for analyzing and\/or controlling program behavior.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-521 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-2.jpg\" alt=\"\" width=\"676\" height=\"324\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-2.jpg 676w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-2-300x144.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-2-65x31.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-2-225x108.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A4-2-350x168.jpg 350w\" sizes=\"auto, (max-width: 676px) 100vw, 676px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 3: Erroneous program to calculate factorial of a number<\/p>\n<p><strong>Example 1<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us understand usage of the GNU Debugger using the example shown in Figure 3. Figure 3 describes a program factorial.c for calculating factorial of a given number; the program is erroneous however as it contains logical error. Total three variables are used in the program factorial.c. A variable \u2018n\u2019 is used to store value of a number whose factorial is required to be calculated. For instance, the variable \u2018n\u2019 contains value 5, i.e. the current version of program will calculate factorial of 5. A variable \u2018factorial\u2019 is used to store the computed result factorial of a value stored in the variable \u2018n\u2019; \u2018factorial\u2019 is initialized with 1. Role of variable \u2018i\u2019 is to act as a loop variable.<\/p>\n<p>&nbsp;<\/p>\n<p>Let us compile the program factorial.c and generate symbol table (Figure 4):<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-522 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-2.jpg\" alt=\"\" width=\"629\" height=\"109\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-2.jpg 629w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-2-300x52.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-2-65x11.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-2-225x39.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A5-2-350x61.jpg 350w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 4: Compile source file and generate symbol table<\/p>\n<p>&nbsp;<\/p>\n<p>Launch GNU Debugger to debug the executable factorial.out (Figure 5):<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-523 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-2.jpg\" alt=\"\" width=\"699\" height=\"236\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-2.jpg 699w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-2-300x101.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-2-65x22.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-2-225x76.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A6-2-350x118.jpg 350w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 5: Launch GDB for factorial.out<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us set a breakpoint on the function main()(Figure 6). See that command \u2018b main\u2019 is used to set breakpoint. GDB shows resultant output mentioning the breakpoint set at the address containing the function main(). The output also mentions the source file name and line number of the main()function in the source.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-524 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-1.jpg\" alt=\"\" width=\"473\" height=\"56\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-1.jpg 473w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-1-300x36.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-1-65x8.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-1-225x27.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A7-1-350x41.jpg 350w\" sizes=\"auto, (max-width: 473px) 100vw, 473px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 6: Set breakpoint on the function main()<\/p>\n<p>Now instruct GDB to start running the program (Figure 7):<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-525 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-1.jpg\" alt=\"\" width=\"564\" height=\"109\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-1.jpg 564w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-1-300x58.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-1-65x13.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-1-225x43.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A8-1-350x68.jpg 350w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 7: Start running the program<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Figure 7 indicates that as breakpoint was set on the function main()(Figure 6), gdb stops program execution, and now it is waiting for further instruction from user. Now step through the program using command \u2018s\u2019 upto line number 12 (Figure 8).<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-526 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A9-1.jpg\" alt=\"\" width=\"644\" height=\"145\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A9-1.jpg 644w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A9-1-300x68.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A9-1-65x15.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A9-1-225x51.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A9-1-350x79.jpg 350w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/p>\n<div>\n<p style=\"text-align: center;\"><strong>Figure 8: step through the program<\/strong><\/p>\n<\/div>\n<p style=\"text-align: justify;\">Inspect the program variables n, factorial and i by printing them on gdb shell prompt using the \u2018p\u2019 command (Figure 9):<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-527 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A10-1.jpg\" alt=\"\" width=\"429\" height=\"109\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A10-1.jpg 429w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A10-1-300x76.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A10-1-65x17.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A10-1-225x57.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A10-1-350x89.jpg 350w\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 9: Inspect program variables<\/p>\n<p style=\"text-align: justify;\">We may step through the program upto line number 15 and inspect the variables again. Also observe that now the execution control has come out from the loop, i.e. the control has iterated the do-while loop only once (Figure 10).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Values of \u2018factorial\u2019 and \u2018i\u2019 are not acceptable as they should be 120 and 0 after successful completion of the do-while loop. However, the output value of \u2018i\u2019 seems to be doubtful and smells a logical error. After the loop is completed, value of \u2018i\u2019 should be 0, but the actual output value of \u2018i\u2019 differs from the expected value of \u2018i\u2019. It gives a hint that there is some problem with loop condition. Due to wrong implementation of the loop condition (i &lt;= 1), the program is not behaving as it should. Instead, the correct loop condition should be (i &gt;= 1). Finally, using the GNU Debugger we have identified source for the logical error.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-528 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A11-1.jpg\" alt=\"\" width=\"603\" height=\"200\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A11-1.jpg 603w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A11-1-300x100.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A11-1-65x22.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A11-1-225x75.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A11-1-350x116.jpg 350w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p style=\"text-align: center;\"><em>Figure 10<\/em>: Step through the program further and inspect variables<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 2<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Now let us take one more example C++ program to understand how to deal with user-defined functions in GDB (Figure 11).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-529 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A12-1.jpg\" alt=\"\" width=\"587\" height=\"394\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A12-1.jpg 587w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A12-1-300x201.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A12-1-65x44.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A12-1-225x151.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A12-1-350x235.jpg 350w\" sizes=\"auto, (max-width: 587px) 100vw, 587px\" \/><\/p>\n<p style=\"text-align: center;\"><strong>Figure 11: C++ program with user-defined function<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Compile the C++ program shown in Figure 11 with the \u2013g option to enable debugging.<\/p>\n<p># g++ -g detectError.cc \u2013o detectError.x<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Start debugging the detectError.x program and set breakpoint at the main() function. Run the program and step to line number 14. Stepping further to next line number 15, involves a call to user-defined function divide(), which will land the debugger inside the divide function i.e. line number 7. Continuing line-by-line stepping through the divide()function will eventually complete the function execution and will eventually turn the debugging control back to the parent function main() i.e. at line number 15 (Figure 12).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-530 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A13-1.jpg\" alt=\"\" width=\"547\" height=\"217\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A13-1.jpg 547w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A13-1-300x119.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A13-1-65x26.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A13-1-225x89.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A13-1-350x139.jpg 350w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 12: step through the program<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Further stepping through the main(), function will again move the gdb control to line 7 into the detectError() fuction. However, you may skip tracing the function using the gdb command \u2018c\u2019. Inspect the values parameters of the detectError()function on gdb shell (Figure 13).<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-531 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A14-1.jpg\" alt=\"\" width=\"599\" height=\"359\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A14-1.jpg 599w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A14-1-300x180.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A14-1-65x39.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A14-1-225x135.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A14-1-350x210.jpg 350w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 13: Inspect function parameters and skip tracing function<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Use \u2018where\u2019 command to know about related functions causing crash and corresponding line numbers in functions. Use \u2018list\u2019 (or \u2018l\u2019) command to view the context of crash (Figure 14).<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-532 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A15-1.jpg\" alt=\"\" width=\"562\" height=\"271\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A15-1.jpg 562w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A15-1-300x145.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A15-1-65x31.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A15-1-225x108.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A15-1-350x169.jpg 350w\" sizes=\"auto, (max-width: 562px) 100vw, 562px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 14: Usage of where and list commands<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">While debugging in the gdb shell, value of variables may be modified using \u2018set\u2019 command, e.g. set d = 9. Use up (or u) and down (or d) commands for moving up or down in the function stack.<\/p>\n<p style=\"text-align: justify;\">Having understood how to debug running programs, now let us see how to deal with abnormal program termination resulting into coredump. Following Example 3 describes a scenario representing program crash and coredump.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Example 3<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Source code of the faulty C++ program coredump.cc is shown in Figure 15. The program consists of a user defined function setVal (int *pInt, int val) with two parameters: int *pInt and int val. Job of the setVal() function is just to store value of the integer parameter val at memory location pointed by the integer pointer pInt. The setVal() function is called twice in main(): once for assigning value 7 to integer variable x (line no. 14) and once for assigning value 9 to integer pointer p (line no. 18). Compile the program with \u2013g option, observe execution and abnormal termination of program (Figure 16).<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-533 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A16-1.jpg\" alt=\"\" width=\"629\" height=\"397\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A16-1.jpg 629w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A16-1-300x189.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A16-1-65x41.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A16-1-225x142.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A16-1-350x221.jpg 350w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\">Figure 15: A faulty program<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-534 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A17-2.jpg\" alt=\"\" width=\"547\" height=\"106\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A17-2.jpg 547w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A17-2-300x58.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A17-2-65x13.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A17-2-225x44.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A17-2-350x68.jpg 350w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 16: Coredump due to abnormal program termination<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In figure 16, it is seen that the program crashes abnormally and core is dumped. Let us debug program and coredump to find out the cause and location of error. The coredump debug output is shown in Figure 17. In Figure 17 it is seen that stepping through the program up to line no. 17 and then inside the function call at line no. 6, the program crashes due to a signal SIGSEGV. In Linux, the SIGSEGV signal represents segmentation fault indicating that the program tried to access (dereference) an invalid memory location which was either not allowed to access or allocated at all to the program. It means that there is some problem with the value of the formal parameter pInt (pointer to some memory location) of the function setVal()i.e. the memory location which was passed to the function as parameter could be invalid. Investigating the related actual parameter \u2018int* p\u2019 in the function call (line no. 17 and 18) reveals that the variable *p is not initialized at all. It means the pointer p possessed some garbage memory-address, i.e. the pointer p was pointing to some invalid\/inaccessible memory location. Thus the source of error is found in the program using the GNU Debugger.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-535 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/A18-1.jpg\" alt=\"\" width=\"603\" height=\"432\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A18-1.jpg 603w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A18-1-300x215.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A18-1-65x47.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A18-1-225x161.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/A18-1-350x251.jpg 350w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 17: Program termination due to Segmentation fault<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Identifying the cause of error and resolving the error is one of the important and unavoidable phases in application development. The process of finding source of errors or bugs in a computer program is known as debugging. Identifying source of logical and non-syntactical errors becomes challenging task programmers. Nowadays there are many debugger tools available. GNU Debugger is a widely accepted software for UNIX &amp; LINUX family of systems for debugging programs written in various programming languages. GDB is used for investigating behavior of currently running program for inspecting variables\/expressions\/functions for given set of input.<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on GNU Debugger (GDB)<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/KpjxqvaZF-o\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>References and Further Reading<\/strong><\/p>\n<ul>\n<li>GDB Pocket Reference, Arnold Robbins, O\u2019Reilly Publication<\/li>\n<li>The Art of Debugging with GDB and DDD, Norman Matloff, Peter Salzman, O\u2019Reilly Publication<\/li>\n<li>Web resource: GDB: The GNU Project Debugger &#8211; Official Documentation, https:\/\/www.gnu.org\/software\/gdb\/documentation\/<\/li>\n<\/ul>\n","protected":false},"author":4,"menu_order":35,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-narayan-joshi"],"pb_section_license":""},"chapter-type":[],"contributor":[60],"license":[],"class_list":["post-517","chapter","type-chapter","status-publish","hentry","contributor-dr-narayan-joshi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":6,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/517\/revisions"}],"predecessor-version":[{"id":729,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/517\/revisions\/729"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/517\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/media?parent=517"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapter-type?post=517"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/contributor?post=517"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/license?post=517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}