101 lines
5.1 KiB
HTML
101 lines
5.1 KiB
HTML
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Attach - Debugging with GDB</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html">
|
||
|
<meta name="description" content="Debugging with GDB">
|
||
|
<meta name="generator" content="makeinfo 4.13">
|
||
|
<link title="Top" rel="start" href="index.html#Top">
|
||
|
<link rel="up" href="Running.html#Running" title="Running">
|
||
|
<link rel="prev" href="Input_002fOutput.html#Input_002fOutput" title="Input/Output">
|
||
|
<link rel="next" href="Kill-Process.html#Kill-Process" title="Kill Process">
|
||
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
||
|
<!--
|
||
|
Copyright (C) 1988-2019 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.''
|
||
|
-->
|
||
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
||
|
<style type="text/css"><!--
|
||
|
pre.display { font-family:inherit }
|
||
|
pre.format { font-family:inherit }
|
||
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
||
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
||
|
pre.smallexample { font-size:smaller }
|
||
|
pre.smalllisp { font-size:smaller }
|
||
|
span.sc { font-variant:small-caps }
|
||
|
span.roman { font-family:serif; font-weight:normal; }
|
||
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="node">
|
||
|
<a name="Attach"></a>
|
||
|
<p>
|
||
|
Next: <a rel="next" accesskey="n" href="Kill-Process.html#Kill-Process">Kill Process</a>,
|
||
|
Previous: <a rel="previous" accesskey="p" href="Input_002fOutput.html#Input_002fOutput">Input/Output</a>,
|
||
|
Up: <a rel="up" accesskey="u" href="Running.html#Running">Running</a>
|
||
|
<hr>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section">4.7 Debugging an Already-running Process</h3>
|
||
|
|
||
|
<p><a name="index-attach-153"></a><a name="index-attach-154"></a>
|
||
|
<dl>
|
||
|
<dt><code>attach </code><var>process-id</var><dd>This command attaches to a running process—one that was started
|
||
|
outside <span class="sc">gdb</span>. (<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 ‘<samp><span class="samp">jobs -l</span></samp>’ shell command.
|
||
|
|
||
|
<p><code>attach</code> does not repeat if you press <RET> a second time after
|
||
|
executing the command.
|
||
|
</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>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>The first thing <span class="sc">gdb</span> does after arranging to debug the specified
|
||
|
process is to stop it. You can examine and modify an attached process
|
||
|
with all the <span class="sc">gdb</span> 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 <span class="sc">gdb</span> to the process.
|
||
|
|
||
|
|
||
|
<a name="index-detach-155"></a>
|
||
|
<dl><dt><code>detach</code><dd>When you have finished debugging the attached process, you can use the
|
||
|
<code>detach</code> command to release it from <span class="sc">gdb</span> control. Detaching
|
||
|
the process continues its execution. After the <code>detach</code> command,
|
||
|
that process and <span class="sc">gdb</span> 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 <RET> again after
|
||
|
executing the command.
|
||
|
</dl>
|
||
|
|
||
|
<p>If you exit <span class="sc">gdb</span> while you have an attached process, you detach
|
||
|
that process. If you use the <code>run</code> command, you kill that process.
|
||
|
By default, <span class="sc">gdb</span> 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>).
|
||
|
|
||
|
</body></html>
|
||
|
|