1<html lang="en"> 2<head> 3<title>Invoking GDB - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Invocation.html#Invocation" title="Invocation"> 9<link rel="next" href="Quitting-GDB.html#Quitting-GDB" title="Quitting GDB"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12Copyright (C) 1988-2013 Free Software Foundation, Inc. 13 14Permission is granted to copy, distribute and/or modify this document 15under the terms of the GNU Free Documentation License, Version 1.3 or 16any later version published by the Free Software Foundation; with the 17Invariant Sections being ``Free Software'' and ``Free Software Needs 18Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 19and with the Back-Cover Texts as in (a) below. 20 21(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 22this GNU Manual. Buying copies from GNU Press supports the FSF in 23developing GNU and promoting software freedom.'' 24--> 25<meta http-equiv="Content-Style-Type" content="text/css"> 26<style type="text/css"><!-- 27 pre.display { font-family:inherit } 28 pre.format { font-family:inherit } 29 pre.smalldisplay { font-family:inherit; font-size:smaller } 30 pre.smallformat { font-family:inherit; font-size:smaller } 31 pre.smallexample { font-size:smaller } 32 pre.smalllisp { font-size:smaller } 33 span.sc { font-variant:small-caps } 34 span.roman { font-family:serif; font-weight:normal; } 35 span.sansserif { font-family:sans-serif; font-weight:normal; } 36--></style> 37<link rel="stylesheet" type="text/css" href="../cs.css"> 38</head> 39<body> 40<div class="node"> 41<a name="Invoking-GDB"></a> 42<p> 43Next: <a rel="next" accesskey="n" href="Quitting-GDB.html#Quitting-GDB">Quitting GDB</a>, 44Up: <a rel="up" accesskey="u" href="Invocation.html#Invocation">Invocation</a> 45<hr> 46</div> 47 48<h3 class="section">2.1 Invoking <span class="sc">gdb</span></h3> 49 50<p>Invoke <span class="sc">gdb</span> by running the program <code>gdb</code>. Once started, 51<span class="sc">gdb</span> reads commands from the terminal until you tell it to exit. 52 53 <p>You can also run <code>gdb</code> with a variety of arguments and options, 54to specify more of your debugging environment at the outset. 55 56 <p>The command-line options described here are designed 57to cover a variety of situations; in some environments, some of these 58options may effectively be unavailable. 59 60 <p>The most usual way to start <span class="sc">gdb</span> is with one argument, 61specifying an executable program: 62 63<pre class="smallexample"> gdb <var>program</var> 64</pre> 65 <p class="noindent">You can also start with both an executable program and a core file 66specified: 67 68<pre class="smallexample"> gdb <var>program</var> <var>core</var> 69</pre> 70 <p>You can, instead, specify a process ID as a second argument, if you want 71to debug a running process: 72 73<pre class="smallexample"> gdb <var>program</var> 1234 74</pre> 75 <p class="noindent">would attach <span class="sc">gdb</span> to process <code>1234</code> (unless you also have a file 76named <samp><span class="file">1234</span></samp>; <span class="sc">gdb</span> does check for a core file first). 77 78 <p>Taking advantage of the second command-line argument requires a fairly 79complete operating system; when you use <span class="sc">gdb</span> as a remote 80debugger attached to a bare board, there may not be any notion of 81“process”, and there is often no way to get a core dump. <span class="sc">gdb</span> 82will warn you if it is unable to attach or to read core dumps. 83 84 <p>You can optionally have <code>gdb</code> pass any arguments after the 85executable file to the inferior using <code>--args</code>. This option stops 86option processing. 87<pre class="smallexample"> gdb --args gcc -O2 -c foo.c 88</pre> 89 <p>This will cause <code>gdb</code> to debug <code>gcc</code>, and to set 90<code>gcc</code>'s command-line arguments (see <a href="Arguments.html#Arguments">Arguments</a>) to ‘<samp><span class="samp">-O2 -c foo.c</span></samp>’. 91 92 <p>You can run <code>gdb</code> without printing the front material, which describes 93<span class="sc">gdb</span>'s non-warranty, by specifying <code>-silent</code>: 94 95<pre class="smallexample"> gdb -silent 96</pre> 97 <p class="noindent">You can further control how <span class="sc">gdb</span> starts up by using command-line 98options. <span class="sc">gdb</span> itself can remind you of the options available. 99 100<p class="noindent">Type 101 102<pre class="smallexample"> gdb -help 103</pre> 104 <p class="noindent">to display all available options and briefly describe their use 105(‘<samp><span class="samp">gdb -h</span></samp>’ is a shorter equivalent). 106 107 <p>All options and command line arguments you give are processed 108in sequential order. The order makes a difference when the 109‘<samp><span class="samp">-x</span></samp>’ option is used. 110 111<ul class="menu"> 112<li><a accesskey="1" href="File-Options.html#File-Options">File Options</a>: Choosing files 113<li><a accesskey="2" href="Mode-Options.html#Mode-Options">Mode Options</a>: Choosing modes 114<li><a accesskey="3" href="Startup.html#Startup">Startup</a>: What <span class="sc">gdb</span> does during startup 115</ul> 116 117 </body></html> 118 119