blob: e22b49b2c751d96526d512fc5b548700648a841f [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software" and "Free Software Needs
Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: "You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom." -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Debugging with GDB: Attach</title>
<meta name="description" content="Debugging with GDB: Attach">
<meta name="keywords" content="Debugging with GDB: Attach">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Running.html#Running" rel="up" title="Running">
<link href="Kill-Process.html#Kill-Process" rel="next" title="Kill Process">
<link href="Input_002fOutput.html#Input_002fOutput" rel="prev" title="Input/Output">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Attach"></a>
<div class="header">
<p>
Next: <a href="Kill-Process.html#Kill-Process" accesskey="n" rel="next">Kill Process</a>, Previous: <a href="Input_002fOutput.html#Input_002fOutput" accesskey="p" rel="prev">Input/Output</a>, Up: <a href="Running.html#Running" accesskey="u" rel="up">Running</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Debugging-an-Already_002drunning-Process"></a>
<h3 class="section">4.7 Debugging an Already-running Process</h3>
<a name="index-attach-1"></a>
<a name="index-attach"></a>
<dl compact="compact">
<dt><code>attach <var>process-id</var></code></dt>
<dd><p>This command attaches to a running process&mdash;one that was started
outside <small>GDB</small>. (<code>info files</code> shows your active
targets.) The command takes as argument a process ID. The usual way to
find out the <var>process-id</var> of a Unix process is with the <code>ps</code> utility,
or with the &lsquo;<samp>jobs -l</samp>&rsquo; shell command.
</p>
<p><code>attach</code> does not repeat if you press <tt class="key">RET</tt> a second time after
executing the command.
</p></dd>
</dl>
<p>To use <code>attach</code>, your program must be running in an environment
which supports processes; for example, <code>attach</code> does not work for
programs on bare-board targets that lack an operating system. You must
also have permission to send the process a signal.
</p>
<p>When you use <code>attach</code>, the debugger finds the program running in
the process first by looking in the current working directory, then (if
the program is not found) by using the source file search path
(see <a href="Source-Path.html#Source-Path">Specifying Source Directories</a>). You can also use
the <code>file</code> command to load the program. See <a href="Files.html#Files">Commands to
Specify Files</a>.
</p>
<p>The first thing <small>GDB</small> does after arranging to debug the specified
process is to stop it. You can examine and modify an attached process
with all the <small>GDB</small> commands that are ordinarily available when
you start processes with <code>run</code>. You can insert breakpoints; you
can step and continue; you can modify storage. If you would rather the
process continue running, you may use the <code>continue</code> command after
attaching <small>GDB</small> to the process.
</p>
<dl compact="compact">
<dd><a name="index-detach"></a>
</dd>
<dt><code>detach</code></dt>
<dd><p>When you have finished debugging the attached process, you can use the
<code>detach</code> command to release it from <small>GDB</small> control. Detaching
the process continues its execution. After the <code>detach</code> command,
that process and <small>GDB</small> become completely independent once more, and you
are ready to <code>attach</code> another process or start one with <code>run</code>.
<code>detach</code> does not repeat if you press <tt class="key">RET</tt> again after
executing the command.
</p></dd>
</dl>
<p>If you exit <small>GDB</small> while you have an attached process, you detach
that process. If you use the <code>run</code> command, you kill that process.
By default, <small>GDB</small> asks for confirmation if you try to do either of these
things; you can control whether or not you need to confirm by using the
<code>set confirm</code> command (see <a href="Messages_002fWarnings.html#Messages_002fWarnings">Optional Warnings and
Messages</a>).
</p>
<hr>
<div class="header">
<p>
Next: <a href="Kill-Process.html#Kill-Process" accesskey="n" rel="next">Kill Process</a>, Previous: <a href="Input_002fOutput.html#Input_002fOutput" accesskey="p" rel="prev">Input/Output</a>, Up: <a href="Running.html#Running" accesskey="u" rel="up">Running</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>