{"id":322,"date":"2019-10-21T19:46:13","date_gmt":"2019-10-21T17:46:13","guid":{"rendered":"http:\/\/linuxboxen2.dk\/?p=322"},"modified":"2019-10-21T19:46:13","modified_gmt":"2019-10-21T17:46:13","slug":"gdb","status":"publish","type":"post","link":"https:\/\/www.linuxboxen.dk\/?p=322","title":{"rendered":"GDB"},"content":{"rendered":"<p>GDB(1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GNU Development Tools\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GDB(1)<\/p>\n<p>NAME<\/p>\n<p>gdb &#8211; The GNU Debugger<\/p>\n<p>SYNOPSIS<\/p>\n<p>gdb [-help] [-nh] [-nx] [-q] [-batch] [-cd=dir] [-f] [-b bps]<br \/>\n[-tty=dev] [-s symfile] [-e prog] [-se prog] [-c core]<br \/>\n[-p procID]<br \/>\n[-x cmds] [-d dir] [prog|prog procID|prog core]<\/p>\n<p>DESCRIPTION<\/p>\n<p>The purpose of a debugger such as GDB is to allow you to see what is<br \/>\ngoing on &#8220;inside&#8221; another program while it executes &#8212; or what<br \/>\nanother program was doing at the moment it crashed.<\/p>\n<p>GDB can do four main kinds of things (plus other things in support of<br \/>\nthese) to help you catch bugs in the act:<\/p>\n<p>\u00b7\u00a0\u00a0 Start your program, specifying anything that might affect its<br \/>\nbehavior.<\/p>\n<p>\u00b7\u00a0\u00a0 Make your program stop on specified conditions.<\/p>\n<p>\u00b7\u00a0\u00a0 Examine what has happened, when your program has stopped.<\/p>\n<p>\u00b7\u00a0\u00a0 Change things in your program, so you can experiment with<br \/>\ncorrecting the effects of one bug and go on to learn about<br \/>\nanother.<\/p>\n<p>You can use GDB to debug programs written in C,\u00a0C@t{++}, Fortran and<br \/>\nModula-2.<\/p>\n<p>GDB is invoked with the shell command &#8220;gdb&#8221;.\u00a0 Once started, it reads<br \/>\ncommands from the terminal until you tell it to exit with the GDB<br \/>\ncommand &#8220;quit&#8221;.\u00a0 You can get online help from GDB itself by using the<br \/>\ncommand &#8220;help&#8221;.<\/p>\n<p>You can run &#8220;gdb&#8221; with no arguments or options; but the most usual<br \/>\nway to start GDB is with one argument or two, specifying an<br \/>\nexecutable program as the argument:<\/p>\n<p>gdb program<\/p>\n<p>You can also start with both an executable program and a core file<br \/>\nspecified:<\/p>\n<p>gdb program core<\/p>\n<p>You can, instead, specify a process ID as a second argument, if you<br \/>\nwant to debug a running process:<\/p>\n<p>gdb program 1234<br \/>\ngdb -p 1234<\/p>\n<p>would attach GDB to process 1234 (unless you also have a file named<br \/>\n1234; GDB does check for a core file first).\u00a0 With option -p you can<br \/>\nomit the program filename.<\/p>\n<p>Here are some of the most frequently needed GDB commands:<\/p>\n<p>break [file:]functiop<br \/>\nSet a breakpoint at function (in file).<\/p>\n<p>run [arglist]<br \/>\nStart your program (with arglist, if specified).<\/p>\n<p>bt\u00a0 Backtrace: display the program stack.<\/p>\n<p>print expr<br \/>\nDisplay the value of an expression.<\/p>\n<p>c\u00a0\u00a0 Continue running your program (after stopping, e.g. at a<br \/>\nbreakpoint).<\/p>\n<p>next<br \/>\nExecute next program line (after stopping); step over any<br \/>\nfunction calls in the line.<\/p>\n<p>edit [file:]function<br \/>\nlook at the program line where it is presently stopped.<\/p>\n<p>list [file:]function<br \/>\ntype the text of the program in the vicinity of where it is<br \/>\npresently stopped.<\/p>\n<p>step<br \/>\nExecute next program line (after stopping); step into any<br \/>\nfunction calls in the line.<\/p>\n<p>help [name]<br \/>\nShow information about GDB command name, or general information<br \/>\nabout using GDB.<\/p>\n<p>quit<br \/>\nExit from GDB.<\/p>\n<p>For full details on GDB, see Using GDB: A Guide to the GNU Source-<br \/>\nLevel Debugger, by Richard M. Stallman and Roland H. Pesch.\u00a0 The same<br \/>\ntext is available online as the &#8220;gdb&#8221; entry in the &#8220;info&#8221; program.<\/p>\n<p>OPTIONS<\/p>\n<p>Any arguments other than options specify an executable file and core<br \/>\nfile (or process ID); that is, the first argument encountered with no<br \/>\nassociated option flag is equivalent to a -se option, and the second,<br \/>\nif any, is equivalent to a -c option if it&#8217;s the name of a file.<br \/>\nMany options have both long and short forms; both are shown here.<br \/>\nThe long forms are also recognized if you truncate them, so long as<br \/>\nenough of the option is present to be unambiguous.\u00a0 (If you prefer,<br \/>\nyou can flag option arguments with + rather than -, though we<br \/>\nillustrate the more usual convention.)<\/p>\n<p>All the options and command line arguments you give are processed in<br \/>\nsequential order.\u00a0 The order makes a difference when the -x option is<br \/>\nused.<\/p>\n<p>-help<br \/>\n-h\u00a0 List all options, with brief explanations.<\/p>\n<p>-symbols=file<br \/>\n-s file<br \/>\nRead symbol table from file file.<\/p>\n<p>-write<br \/>\nEnable writing into executable and core files.<\/p>\n<p>-exec=file<br \/>\n-e file<br \/>\nUse file file as the executable file to execute when appropriate,<br \/>\nand for examining pure data in conjunction with a core dump.<\/p>\n<p>-se=file<br \/>\nRead symbol table from file file and use it as the executable<br \/>\nfile.<\/p>\n<p>-core=file<br \/>\n-c file<br \/>\nUse file file as a core dump to examine.<\/p>\n<p>-command=file<br \/>\n-x file<br \/>\nExecute GDB commands from file file.<\/p>\n<p>-ex command<br \/>\nExecute given GDB command.<\/p>\n<p>-directory=directory<br \/>\n-d directory<br \/>\nAdd directory to the path to search for source files.<\/p>\n<p>-nh Do not execute commands from ~\/.gdbinit.<\/p>\n<p>-nx<br \/>\n-n\u00a0 Do not execute commands from any .gdbinit initialization files.<\/p>\n<p>-quiet<br \/>\n-q\u00a0 &#8220;Quiet&#8221;.\u00a0 Do not print the introductory and copyright messages.<br \/>\nThese messages are also suppressed in batch mode.<\/p>\n<p>-batch<br \/>\nRun in batch mode.\u00a0 Exit with status 0 after processing all the<br \/>\ncommand files specified with -x (and .gdbinit, if not inhibited).<br \/>\nExit with nonzero status if an error occurs in executing the GDB<br \/>\ncommands in the command files.<\/p>\n<p>Batch mode may be useful for running GDB as a filter, for example<br \/>\nto download and run a program on another computer; in order to<br \/>\nmake this more useful, the message<\/p>\n<p>Program exited normally.<\/p>\n<p>(which is ordinarily issued whenever a program running under GDB<br \/>\ncontrol terminates) is not issued when running in batch mode.<\/p>\n<p>-cd=directory<br \/>\nRun GDB using directory as its working directory, instead of the<br \/>\ncurrent directory.<\/p>\n<p>-fullname<br \/>\n-f\u00a0 Emacs sets this option when it runs GDB as a subprocess.\u00a0 It<br \/>\ntells GDB to output the full file name and line number in a<br \/>\nstandard, recognizable fashion each time a stack frame is<br \/>\ndisplayed (which includes each time the program stops).\u00a0 This<br \/>\nrecognizable format looks like two \\032 characters, followed by<br \/>\nthe file name, line number and character position separated by<br \/>\ncolons, and a newline.\u00a0 The Emacs-to-GDB interface program uses<br \/>\nthe two \\032 characters as a signal to display the source code<br \/>\nfor the frame.<\/p>\n<p>-b bps<br \/>\nSet the line speed (baud rate or bits per second) of any serial<br \/>\ninterface used by GDB for remote debugging.<\/p>\n<p>-tty=device<br \/>\nRun using device for your program&#8217;s standard input and output.<\/p>\n<p>SEE ALSO<\/p>\n<p>The full documentation for GDB is maintained as a Texinfo manual.\u00a0 If<br \/>\nthe &#8220;info&#8221; and &#8220;gdb&#8221; programs and GDB&#8217;s Texinfo documentation are<br \/>\nproperly installed at your site, the command<\/p>\n<p>info gdb<\/p>\n<p>should give you access to the complete manual.<\/p>\n<p>Using GDB: A Guide to the GNU Source-Level Debugger, Richard M.<br \/>\nStallman and Roland H. Pesch, July 1991.<\/p>\n<p>COPYRIGHT<\/p>\n<p>Copyright (c) 1988-2013 Free Software Foundation, Inc.<\/p>\n<p>Permission is granted to copy, distribute and\/or modify this document<br \/>\nunder the terms of the GNU Free Documentation License, Version 1.3 or<br \/>\nany later version published by the Free Software Foundation; with the<br \/>\nInvariant Sections being &#8220;Free Software&#8221; and &#8220;Free Software Needs<br \/>\nFree Documentation&#8221;, with the Front-Cover Texts being &#8220;A GNU Manual,&#8221;<br \/>\nand with the Back-Cover Texts as in (a) below.<\/p>\n<p>(a) The FSF&#8217;s Back-Cover Text is: &#8220;You are free to copy and modify<br \/>\nthis GNU Manual.\u00a0 Buying copies from GNU Press supports the FSF in<br \/>\ndeveloping GNU and promoting software freedom.&#8221;<\/p>\n<p>COLOPHON<\/p>\n<p>This page is part of the gdb (GNU debugger) project.\u00a0 Information<br \/>\nabout the project can be found at \u27e8http:\/\/www.gnu.org\/software\/gdb\/\u27e9.<br \/>\nIf you have a bug report for this manual page, see<br \/>\n\u27e8http:\/\/www.gnu.org\/software\/gdb\/bugs\/\u27e9.\u00a0 This page was obtained from<br \/>\nthe project&#8217;s upstream Git read-only mirror of the CVS repository<br \/>\n(git:\/\/sourceware.org\/git\/gdb.git) on 2014-12-30.\u00a0 If you discover<br \/>\nany rendering problems in this HTML version of the page, or you<br \/>\nbelieve there is a better or more up-to-date source for the page, or<br \/>\nyou have corrections or improvements to the information in this<br \/>\nCOLOPHON (which is not part of the original manual page), send a mail<br \/>\nto\u00a0man-pages@man7.org<\/p>\n<p>gdb-7.6.50.20131021-cvs\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2013-12-12\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GDB(1)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GDB(1)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GNU Development Tools\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GDB(1) NAME gdb &#8211; The GNU Debugger SYNOPSIS gdb [-help] [-nh] [-nx] [-q] [-batch] [-cd=dir] [-f] [-b bps] [-tty=dev] [-s symfile] [-e prog] [-se prog] [-c core] [-p procID] [-x cmds] [-d dir] [prog|prog procID|prog core] DESCRIPTION The purpose of a debugger such as GDB is to allow you to see [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","footnotes":""},"categories":[8],"tags":[],"class_list":["post-322","post","type-post","status-publish","format-standard","hentry","category-shell"],"a3_pvc":{"activated":false,"total_views":0,"today_views":0},"_links":{"self":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/posts\/322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=322"}],"version-history":[{"count":0,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=\/wp\/v2\/posts\/322\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxboxen.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}