Attach.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Attach</title>
  16. <meta name="description" content="Debugging with GDB: Attach">
  17. <meta name="keywords" content="Debugging with GDB: Attach">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Running.html#Running" rel="up" title="Running">
  26. <link href="Kill-Process.html#Kill-Process" rel="next" title="Kill Process">
  27. <link href="Input_002fOutput.html#Input_002fOutput" rel="previous" title="Input/Output">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Attach"></a>
  59. <div class="header">
  60. <p>
  61. 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="previous">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>
  62. </div>
  63. <hr>
  64. <a name="Debugging-an-Already_002drunning-Process"></a>
  65. <h3 class="section">4.7 Debugging an Already-running Process</h3>
  66. <a name="index-attach-1"></a>
  67. <a name="index-attach"></a>
  68. <dl compact="compact">
  69. <dt><code>attach <var>process-id</var></code></dt>
  70. <dd><p>This command attaches to a running process&mdash;one that was started
  71. outside <small>GDB</small>. (<code>info files</code> shows your active
  72. targets.) The command takes as argument a process ID. The usual way to
  73. find out the <var>process-id</var> of a Unix process is with the <code>ps</code> utility,
  74. or with the &lsquo;<samp>jobs -l</samp>&rsquo; shell command.
  75. </p>
  76. <p><code>attach</code> does not repeat if you press <tt class="key">RET</tt> a second time after
  77. executing the command.
  78. </p></dd>
  79. </dl>
  80. <p>To use <code>attach</code>, your program must be running in an environment
  81. which supports processes; for example, <code>attach</code> does not work for
  82. programs on bare-board targets that lack an operating system. You must
  83. also have permission to send the process a signal.
  84. </p>
  85. <p>When you use <code>attach</code>, the debugger finds the program running in
  86. the process first by looking in the current working directory, then (if
  87. the program is not found) by using the source file search path
  88. (see <a href="Source-Path.html#Source-Path">Specifying Source Directories</a>). You can also use
  89. the <code>file</code> command to load the program. See <a href="Files.html#Files">Commands to
  90. Specify Files</a>.
  91. </p>
  92. <a name="set-exec_002dfile_002dmismatch"></a><p>If the debugger can determine that the executable file running in the
  93. process it is attaching to does not match the current exec-file loaded
  94. by <small>GDB</small>, the option <code>exec-file-mismatch</code> specifies how to
  95. handle the mismatch. <small>GDB</small> tries to compare the files by
  96. comparing their build IDs (see <a href="Separate-Debug-Files.html#build-ID">build ID</a>), if available.
  97. </p>
  98. <dl compact="compact">
  99. <dd><a name="index-exec_002dfile_002dmismatch"></a>
  100. <a name="index-set-exec_002dfile_002dmismatch"></a>
  101. </dd>
  102. <dt><code>set exec-file-mismatch &lsquo;<samp>ask|warn|off</samp>&rsquo;</code></dt>
  103. <dd>
  104. <p>Whether to detect mismatch between the current executable file loaded
  105. by <small>GDB</small> and the executable file used to start the process. If
  106. &lsquo;<samp>ask</samp>&rsquo;, the default, display a warning and ask the user whether to
  107. load the process executable file; if &lsquo;<samp>warn</samp>&rsquo;, just display a
  108. warning; if &lsquo;<samp>off</samp>&rsquo;, don&rsquo;t attempt to detect a mismatch.
  109. If the user confirms loading the process executable file, then its symbols
  110. will be loaded as well.
  111. </p>
  112. <a name="index-show-exec_002dfile_002dmismatch"></a>
  113. </dd>
  114. <dt><code>show exec-file-mismatch</code></dt>
  115. <dd><p>Show the current value of <code>exec-file-mismatch</code>.
  116. </p>
  117. </dd>
  118. </dl>
  119. <p>The first thing <small>GDB</small> does after arranging to debug the specified
  120. process is to stop it. You can examine and modify an attached process
  121. with all the <small>GDB</small> commands that are ordinarily available when
  122. you start processes with <code>run</code>. You can insert breakpoints; you
  123. can step and continue; you can modify storage. If you would rather the
  124. process continue running, you may use the <code>continue</code> command after
  125. attaching <small>GDB</small> to the process.
  126. </p>
  127. <dl compact="compact">
  128. <dd><a name="index-detach"></a>
  129. </dd>
  130. <dt><code>detach</code></dt>
  131. <dd><p>When you have finished debugging the attached process, you can use the
  132. <code>detach</code> command to release it from <small>GDB</small> control. Detaching
  133. the process continues its execution. After the <code>detach</code> command,
  134. that process and <small>GDB</small> become completely independent once more, and you
  135. are ready to <code>attach</code> another process or start one with <code>run</code>.
  136. <code>detach</code> does not repeat if you press <tt class="key">RET</tt> again after
  137. executing the command.
  138. </p></dd>
  139. </dl>
  140. <p>If you exit <small>GDB</small> while you have an attached process, you detach
  141. that process. If you use the <code>run</code> command, you kill that process.
  142. By default, <small>GDB</small> asks for confirmation if you try to do either of these
  143. things; you can control whether or not you need to confirm by using the
  144. <code>set confirm</code> command (see <a href="Messages_002fWarnings.html#Messages_002fWarnings">Optional Warnings and
  145. Messages</a>).
  146. </p>
  147. <hr>
  148. <div class="header">
  149. <p>
  150. 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="previous">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>
  151. </div>
  152. </body>
  153. </html>