You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 satır
7.9KB

  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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Attach (Debugging with GDB)</title>
  17. <meta name="description" content="Attach (Debugging with GDB)">
  18. <meta name="keywords" content="Attach (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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="prev" title="Input/Output">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Attach"></a>
  58. <div class="header">
  59. <p>
  60. 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>
  61. </div>
  62. <hr>
  63. <a name="Debugging-an-Already_002drunning-Process"></a>
  64. <h3 class="section">4.7 Debugging an Already-running Process</h3>
  65. <a name="index-attach-1"></a>
  66. <a name="index-attach"></a>
  67. <dl compact="compact">
  68. <dt><code>attach <var>process-id</var></code></dt>
  69. <dd><p>This command attaches to a running process&mdash;one that was started
  70. outside <small>GDB</small>. (<code>info files</code> shows your active
  71. targets.) The command takes as argument a process ID. The usual way to
  72. find out the <var>process-id</var> of a Unix process is with the <code>ps</code> utility,
  73. or with the &lsquo;<samp>jobs -l</samp>&rsquo; shell command.
  74. </p>
  75. <p><code>attach</code> does not repeat if you press <tt class="key">RET</tt> a second time after
  76. executing the command.
  77. </p></dd>
  78. </dl>
  79. <p>To use <code>attach</code>, your program must be running in an environment
  80. which supports processes; for example, <code>attach</code> does not work for
  81. programs on bare-board targets that lack an operating system. You must
  82. also have permission to send the process a signal.
  83. </p>
  84. <p>When you use <code>attach</code>, the debugger finds the program running in
  85. the process first by looking in the current working directory, then (if
  86. the program is not found) by using the source file search path
  87. (see <a href="Source-Path.html#Source-Path">Specifying Source Directories</a>). You can also use
  88. the <code>file</code> command to load the program. See <a href="Files.html#Files">Commands to
  89. Specify Files</a>.
  90. </p>
  91. <a name="set-exec_002dfile_002dmismatch"></a><p>If the debugger can determine that the executable file running in the
  92. process it is attaching to does not match the current exec-file loaded
  93. by <small>GDB</small>, the option <code>exec-file-mismatch</code> specifies how to
  94. handle the mismatch. <small>GDB</small> tries to compare the files by
  95. comparing their build IDs (see <a href="Separate-Debug-Files.html#build-ID">build ID</a>), if available.
  96. </p>
  97. <dl compact="compact">
  98. <dd><a name="index-exec_002dfile_002dmismatch"></a>
  99. <a name="index-set-exec_002dfile_002dmismatch"></a>
  100. </dd>
  101. <dt><code>set exec-file-mismatch &lsquo;<samp>ask|warn|off</samp>&rsquo;</code></dt>
  102. <dd>
  103. <p>Whether to detect mismatch between the current executable file loaded
  104. by <small>GDB</small> and the executable file used to start the process. If
  105. &lsquo;<samp>ask</samp>&rsquo;, the default, display a warning and ask the user whether to
  106. load the process executable file; if &lsquo;<samp>warn</samp>&rsquo;, just display a
  107. warning; if &lsquo;<samp>off</samp>&rsquo;, don&rsquo;t attempt to detect a mismatch.
  108. If the user confirms loading the process executable file, then its symbols
  109. will be loaded as well.
  110. </p>
  111. <a name="index-show-exec_002dfile_002dmismatch"></a>
  112. </dd>
  113. <dt><code>show exec-file-mismatch</code></dt>
  114. <dd><p>Show the current value of <code>exec-file-mismatch</code>.
  115. </p>
  116. </dd>
  117. </dl>
  118. <p>The first thing <small>GDB</small> does after arranging to debug the specified
  119. process is to stop it. You can examine and modify an attached process
  120. with all the <small>GDB</small> commands that are ordinarily available when
  121. you start processes with <code>run</code>. You can insert breakpoints; you
  122. can step and continue; you can modify storage. If you would rather the
  123. process continue running, you may use the <code>continue</code> command after
  124. attaching <small>GDB</small> to the process.
  125. </p>
  126. <dl compact="compact">
  127. <dd><a name="index-detach"></a>
  128. </dd>
  129. <dt><code>detach</code></dt>
  130. <dd><p>When you have finished debugging the attached process, you can use the
  131. <code>detach</code> command to release it from <small>GDB</small> control. Detaching
  132. the process continues its execution. After the <code>detach</code> command,
  133. that process and <small>GDB</small> become completely independent once more, and you
  134. are ready to <code>attach</code> another process or start one with <code>run</code>.
  135. <code>detach</code> does not repeat if you press <tt class="key">RET</tt> again after
  136. executing the command.
  137. </p></dd>
  138. </dl>
  139. <p>If you exit <small>GDB</small> while you have an attached process, you detach
  140. that process. If you use the <code>run</code> command, you kill that process.
  141. By default, <small>GDB</small> asks for confirmation if you try to do either of these
  142. things; you can control whether or not you need to confirm by using the
  143. <code>set confirm</code> command (see <a href="Messages_002fWarnings.html#Messages_002fWarnings">Optional Warnings and
  144. Messages</a>).
  145. </p>
  146. <hr>
  147. <div class="header">
  148. <p>
  149. 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>
  150. </div>
  151. </body>
  152. </html>