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.

Shell-Commands.html 7.0KB

3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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>Shell Commands (Debugging with GDB)</title>
  17. <meta name="description" content="Shell Commands (Debugging with GDB)">
  18. <meta name="keywords" content="Shell Commands (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="Invocation.html#Invocation" rel="up" title="Invocation">
  26. <link href="Logging-Output.html#Logging-Output" rel="next" title="Logging Output">
  27. <link href="Quitting-GDB.html#Quitting-GDB" rel="prev" title="Quitting GDB">
  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="Shell-Commands"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Logging-Output.html#Logging-Output" accesskey="n" rel="next">Logging Output</a>, Previous: <a href="Quitting-GDB.html#Quitting-GDB" accesskey="p" rel="prev">Quitting GDB</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</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="Shell-Commands-1"></a>
  64. <h3 class="section">2.3 Shell Commands</h3>
  65. <p>If you need to execute occasional shell commands during your
  66. debugging session, there is no need to leave or suspend <small>GDB</small>; you can
  67. just use the <code>shell</code> command.
  68. </p>
  69. <dl compact="compact">
  70. <dd><a name="index-shell"></a>
  71. <a name="index-_0021"></a>
  72. <a name="index-shell-escape"></a>
  73. </dd>
  74. <dt><code>shell <var>command-string</var></code></dt>
  75. <dt><code>!<var>command-string</var></code></dt>
  76. <dd><p>Invoke a standard shell to execute <var>command-string</var>.
  77. Note that no space is needed between <code>!</code> and <var>command-string</var>.
  78. On GNU and Unix systems, the environment variable <code>SHELL</code>, if it
  79. exists, determines which shell to run. Otherwise <small>GDB</small> uses
  80. the default shell (<samp>/bin/sh</samp> on GNU and Unix systems,
  81. <samp>cmd.exe</samp> on MS-Windows, <samp>COMMAND.COM</samp> on MS-DOS, etc.).
  82. </p></dd>
  83. </dl>
  84. <p>The utility <code>make</code> is often needed in development environments.
  85. You do not have to use the <code>shell</code> command for this purpose in
  86. <small>GDB</small>:
  87. </p>
  88. <dl compact="compact">
  89. <dd><a name="index-make"></a>
  90. <a name="index-calling-make"></a>
  91. </dd>
  92. <dt><code>make <var>make-args</var></code></dt>
  93. <dd><p>Execute the <code>make</code> program with the specified
  94. arguments. This is equivalent to &lsquo;<samp>shell make <var>make-args</var></samp>&rsquo;.
  95. </p></dd>
  96. </dl>
  97. <dl compact="compact">
  98. <dd><a name="index-pipe"></a>
  99. <a name="index-_007c"></a>
  100. <a name="index-send-the-output-of-a-gdb-command-to-a-shell-command"></a>
  101. <a name="pipe"></a></dd>
  102. <dt><code>pipe [<var>command</var>] | <var>shell_command</var></code></dt>
  103. <dt><code>| [<var>command</var>] | <var>shell_command</var></code></dt>
  104. <dt><code>pipe -d <var>delim</var> <var>command</var> <var>delim</var> <var>shell_command</var></code></dt>
  105. <dt><code>| -d <var>delim</var> <var>command</var> <var>delim</var> <var>shell_command</var></code></dt>
  106. <dd><p>Executes <var>command</var> and sends its output to <var>shell_command</var>.
  107. Note that no space is needed around <code>|</code>.
  108. If no <var>command</var> is provided, the last command executed is repeated.
  109. </p>
  110. <p>In case the <var>command</var> contains a <code>|</code>, the option <code>-d <var>delim</var></code>
  111. can be used to specify an alternate delimiter string <var>delim</var> that separates
  112. the <var>command</var> from the <var>shell_command</var>.
  113. </p>
  114. <p>Example:
  115. </p><div class="smallexample">
  116. <pre class="smallexample">(gdb) p var
  117. $1 = {
  118. black = 144,
  119. red = 233,
  120. green = 377,
  121. blue = 610,
  122. white = 987
  123. }
  124. </pre><pre class="smallexample">(gdb) pipe p var|wc
  125. 7 19 80
  126. (gdb) |p var|wc -l
  127. 7
  128. </pre><pre class="smallexample">(gdb) p /x var
  129. $4 = {
  130. black = 0x90,
  131. red = 0xe9,
  132. green = 0x179,
  133. blue = 0x262,
  134. white = 0x3db
  135. }
  136. (gdb) ||grep red
  137. red =&gt; 0xe9,
  138. </pre><pre class="smallexample">(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
  139. this contains a PIPE char
  140. (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
  141. this contains a PIPE char!
  142. (gdb)
  143. </pre></div>
  144. </dd>
  145. </dl>
  146. <p>The convenience variables <code>$_shell_exitcode</code> and <code>$_shell_exitsignal</code>
  147. can be used to examine the exit status of the last shell command launched
  148. by <code>shell</code>, <code>make</code>, <code>pipe</code> and <code>|</code>.
  149. See <a href="Convenience-Vars.html#Convenience-Vars">Convenience Variables</a>.
  150. </p>
  151. <hr>
  152. <div class="header">
  153. <p>
  154. Next: <a href="Logging-Output.html#Logging-Output" accesskey="n" rel="next">Logging Output</a>, Previous: <a href="Quitting-GDB.html#Quitting-GDB" accesskey="p" rel="prev">Quitting GDB</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</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>
  155. </div>
  156. </body>
  157. </html>