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.

180 lines
8.6KB

  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>dotdebug_gdb_scripts section (Debugging with GDB)</title>
  17. <meta name="description" content="dotdebug_gdb_scripts section (Debugging with GDB)">
  18. <meta name="keywords" content="dotdebug_gdb_scripts section (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="Auto_002dloading-extensions.html#Auto_002dloading-extensions" rel="up" title="Auto-loading extensions">
  26. <link href="Which-flavor-to-choose_003f.html#Which-flavor-to-choose_003f" rel="next" title="Which flavor to choose?">
  27. <link href="objfile_002dgdbdotext-file.html#objfile_002dgdbdotext-file" rel="prev" title="objfile-gdbdotext file">
  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="dotdebug_005fgdb_005fscripts-section"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Which-flavor-to-choose_003f.html#Which-flavor-to-choose_003f" accesskey="n" rel="next">Which flavor to choose?</a>, Previous: <a href="objfile_002dgdbdotext-file.html#objfile_002dgdbdotext-file" accesskey="p" rel="prev">objfile-gdbdotext file</a>, Up: <a href="Auto_002dloading-extensions.html#Auto_002dloading-extensions" accesskey="u" rel="up">Auto-loading extensions</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="The-_002edebug_005fgdb_005fscripts-section"></a>
  64. <h4 class="subsection">23.4.2 The <code>.debug_gdb_scripts</code> section</h4>
  65. <a name="index-_002edebug_005fgdb_005fscripts-section"></a>
  66. <p>For systems using file formats like ELF and COFF,
  67. when <small>GDB</small> loads a new object file
  68. it will look for a special section named <code>.debug_gdb_scripts</code>.
  69. If this section exists, its contents is a list of null-terminated entries
  70. specifying scripts to load. Each entry begins with a non-null prefix byte that
  71. specifies the kind of entry, typically the extension language and whether the
  72. script is in a file or inlined in <code>.debug_gdb_scripts</code>.
  73. </p>
  74. <p>The following entries are supported:
  75. </p>
  76. <dl compact="compact">
  77. <dt><code>SECTION_SCRIPT_ID_PYTHON_FILE = 1</code></dt>
  78. <dt><code>SECTION_SCRIPT_ID_SCHEME_FILE = 3</code></dt>
  79. <dt><code>SECTION_SCRIPT_ID_PYTHON_TEXT = 4</code></dt>
  80. <dt><code>SECTION_SCRIPT_ID_SCHEME_TEXT = 6</code></dt>
  81. </dl>
  82. <a name="Script-File-Entries"></a>
  83. <h4 class="subsubsection">23.4.2.1 Script File Entries</h4>
  84. <p>If the entry specifies a file, <small>GDB</small> will look for the file first
  85. in the current directory and then along the source search path
  86. (see <a href="Source-Path.html#Source-Path">Specifying Source Directories</a>),
  87. except that <samp>$cdir</samp> is not searched, since the compilation
  88. directory is not relevant to scripts.
  89. </p>
  90. <p>File entries can be placed in section <code>.debug_gdb_scripts</code> with,
  91. for example, this GCC macro for Python scripts.
  92. </p>
  93. <div class="example">
  94. <pre class="example">/* Note: The &quot;MS&quot; section flags are to remove duplicates. */
  95. #define DEFINE_GDB_PY_SCRIPT(script_name) \
  96. asm(&quot;\
  97. .pushsection \&quot;.debug_gdb_scripts\&quot;, \&quot;MS\&quot;,@progbits,1\n\
  98. .byte 1 /* Python */\n\
  99. .asciz \&quot;&quot; script_name &quot;\&quot;\n\
  100. .popsection \n\
  101. &quot;);
  102. </pre></div>
  103. <p>For Guile scripts, replace <code>.byte 1</code> with <code>.byte 3</code>.
  104. Then one can reference the macro in a header or source file like this:
  105. </p>
  106. <div class="example">
  107. <pre class="example">DEFINE_GDB_PY_SCRIPT (&quot;my-app-scripts.py&quot;)
  108. </pre></div>
  109. <p>The script name may include directories if desired.
  110. </p>
  111. <p>Note that loading of this script file also requires accordingly configured
  112. <code>auto-load safe-path</code> (see <a href="Auto_002dloading-safe-path.html#Auto_002dloading-safe-path">Auto-loading safe path</a>).
  113. </p>
  114. <p>If the macro invocation is put in a header, any application or library
  115. using this header will get a reference to the specified script,
  116. and with the use of <code>&quot;MS&quot;</code> attributes on the section, the linker
  117. will remove duplicates.
  118. </p>
  119. <a name="Script-Text-Entries"></a>
  120. <h4 class="subsubsection">23.4.2.2 Script Text Entries</h4>
  121. <p>Script text entries allow to put the executable script in the entry
  122. itself instead of loading it from a file.
  123. The first line of the entry, everything after the prefix byte and up to
  124. the first newline (<code>0xa</code>) character, is the script name, and must not
  125. contain any kind of space character, e.g., spaces or tabs.
  126. The rest of the entry, up to the trailing null byte, is the script to
  127. execute in the specified language. The name needs to be unique among
  128. all script names, as <small>GDB</small> executes each script only once based
  129. on its name.
  130. </p>
  131. <p>Here is an example from file <samp>py-section-script.c</samp> in the <small>GDB</small>
  132. testsuite.
  133. </p>
  134. <div class="example">
  135. <pre class="example">#include &quot;symcat.h&quot;
  136. #include &quot;gdb/section-scripts.h&quot;
  137. asm(
  138. &quot;.pushsection \&quot;.debug_gdb_scripts\&quot;, \&quot;MS\&quot;,@progbits,1\n&quot;
  139. &quot;.byte &quot; XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) &quot;\n&quot;
  140. &quot;.ascii \&quot;gdb.inlined-script\\n\&quot;\n&quot;
  141. &quot;.ascii \&quot;class test_cmd (gdb.Command):\\n\&quot;\n&quot;
  142. &quot;.ascii \&quot; def __init__ (self):\\n\&quot;\n&quot;
  143. &quot;.ascii \&quot; super (test_cmd, self).__init__ (&quot;
  144. &quot;\\\&quot;test-cmd\\\&quot;, gdb.COMMAND_OBSCURE)\\n\&quot;\n&quot;
  145. &quot;.ascii \&quot; def invoke (self, arg, from_tty):\\n\&quot;\n&quot;
  146. &quot;.ascii \&quot; print (\\\&quot;test-cmd output, arg = %s\\\&quot; % arg)\\n\&quot;\n&quot;
  147. &quot;.ascii \&quot;test_cmd ()\\n\&quot;\n&quot;
  148. &quot;.byte 0\n&quot;
  149. &quot;.popsection\n&quot;
  150. );
  151. </pre></div>
  152. <p>Loading of inlined scripts requires a properly configured
  153. <code>auto-load safe-path</code> (see <a href="Auto_002dloading-safe-path.html#Auto_002dloading-safe-path">Auto-loading safe path</a>).
  154. The path to specify in <code>auto-load safe-path</code> is the path of the file
  155. containing the <code>.debug_gdb_scripts</code> section.
  156. </p>
  157. <hr>
  158. <div class="header">
  159. <p>
  160. Next: <a href="Which-flavor-to-choose_003f.html#Which-flavor-to-choose_003f" accesskey="n" rel="next">Which flavor to choose?</a>, Previous: <a href="objfile_002dgdbdotext-file.html#objfile_002dgdbdotext-file" accesskey="p" rel="prev">objfile-gdbdotext file</a>, Up: <a href="Auto_002dloading-extensions.html#Auto_002dloading-extensions" accesskey="u" rel="up">Auto-loading extensions</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>
  161. </div>
  162. </body>
  163. </html>