1<html lang="en"> 2<head> 3<title>Attach - 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="Running.html#Running" title="Running"> 9<link rel="prev" href="Input_002fOutput.html#Input_002fOutput" title="Input/Output"> 10<link rel="next" href="Kill-Process.html#Kill-Process" title="Kill Process"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 141998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 15Free Software Foundation, Inc. 16 17Permission is granted to copy, distribute and/or modify this document 18under the terms of the GNU Free Documentation License, Version 1.3 or 19any later version published by the Free Software Foundation; with the 20Invariant Sections being ``Free Software'' and ``Free Software Needs 21Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 22and with the Back-Cover Texts as in (a) below. 23 24(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 25this GNU Manual. Buying copies from GNU Press supports the FSF in 26developing GNU and promoting software freedom.''--> 27<meta http-equiv="Content-Style-Type" content="text/css"> 28<style type="text/css"><!-- 29 pre.display { font-family:inherit } 30 pre.format { font-family:inherit } 31 pre.smalldisplay { font-family:inherit; font-size:smaller } 32 pre.smallformat { font-family:inherit; font-size:smaller } 33 pre.smallexample { font-size:smaller } 34 pre.smalllisp { font-size:smaller } 35 span.sc { font-variant:small-caps } 36 span.roman { font-family:serif; font-weight:normal; } 37 span.sansserif { font-family:sans-serif; font-weight:normal; } 38--></style> 39<link rel="stylesheet" type="text/css" href="../cs.css"> 40</head> 41<body> 42<div class="node"> 43<a name="Attach"></a> 44<p> 45Next: <a rel="next" accesskey="n" href="Kill-Process.html#Kill-Process">Kill Process</a>, 46Previous: <a rel="previous" accesskey="p" href="Input_002fOutput.html#Input_002fOutput">Input/Output</a>, 47Up: <a rel="up" accesskey="u" href="Running.html#Running">Running</a> 48<hr> 49</div> 50 51<h3 class="section">4.7 Debugging an Already-running Process</h3> 52 53<p><a name="index-attach-133"></a><a name="index-attach-134"></a> 54 <dl> 55<dt><code>attach </code><var>process-id</var><dd>This command attaches to a running process—one that was started 56outside <span class="sc">gdb</span>. (<code>info files</code> shows your active 57targets.) The command takes as argument a process ID. The usual way to 58find out the <var>process-id</var> of a Unix process is with the <code>ps</code> utility, 59or with the ‘<samp><span class="samp">jobs -l</span></samp>’ shell command. 60 61 <p><code>attach</code> does not repeat if you press <RET> a second time after 62executing the command. 63</dl> 64 65 <p>To use <code>attach</code>, your program must be running in an environment 66which supports processes; for example, <code>attach</code> does not work for 67programs on bare-board targets that lack an operating system. You must 68also have permission to send the process a signal. 69 70 <p>When you use <code>attach</code>, the debugger finds the program running in 71the process first by looking in the current working directory, then (if 72the program is not found) by using the source file search path 73(see <a href="Source-Path.html#Source-Path">Specifying Source Directories</a>). You can also use 74the <code>file</code> command to load the program. See <a href="Files.html#Files">Commands to Specify Files</a>. 75 76 <p>The first thing <span class="sc">gdb</span> does after arranging to debug the specified 77process is to stop it. You can examine and modify an attached process 78with all the <span class="sc">gdb</span> commands that are ordinarily available when 79you start processes with <code>run</code>. You can insert breakpoints; you 80can step and continue; you can modify storage. If you would rather the 81process continue running, you may use the <code>continue</code> command after 82attaching <span class="sc">gdb</span> to the process. 83 84 85<a name="index-detach-135"></a> 86<dl><dt><code>detach</code><dd>When you have finished debugging the attached process, you can use the 87<code>detach</code> command to release it from <span class="sc">gdb</span> control. Detaching 88the process continues its execution. After the <code>detach</code> command, 89that process and <span class="sc">gdb</span> become completely independent once more, and you 90are ready to <code>attach</code> another process or start one with <code>run</code>. 91<code>detach</code> does not repeat if you press <RET> again after 92executing the command. 93</dl> 94 95 <p>If you exit <span class="sc">gdb</span> while you have an attached process, you detach 96that process. If you use the <code>run</code> command, you kill that process. 97By default, <span class="sc">gdb</span> asks for confirmation if you try to do either of these 98things; you can control whether or not you need to confirm by using the 99<code>set confirm</code> command (see <a href="Messages_002fWarnings.html#Messages_002fWarnings">Optional Warnings and Messages</a>). 100 101 </body></html> 102 103