Procedures.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1992-2019 Free Software Foundation, Inc.
  4. Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon,
  5. and David MacKenzie.
  6. Permission is granted to copy, distribute and/or modify this document
  7. under the terms of the GNU Free Documentation License, Version 1.3 or
  8. any later version published by the Free Software Foundation; with no
  9. Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  10. Texts. A copy of the license is included in the section entitled "GNU
  11. Free Documentation License". -->
  12. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>STABS: Procedures</title>
  15. <meta name="description" content="STABS: Procedures">
  16. <meta name="keywords" content="STABS: Procedures">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Program-Structure.html#Program-Structure" rel="up" title="Program Structure">
  25. <link href="Nested-Procedures.html#Nested-Procedures" rel="next" title="Nested Procedures">
  26. <link href="Line-Numbers.html#Line-Numbers" rel="prev" title="Line Numbers">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style:oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; 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" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="Procedures"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Nested-Procedures.html#Nested-Procedures" accesskey="n" rel="next">Nested Procedures</a>, Previous: <a href="Line-Numbers.html#Line-Numbers" accesskey="p" rel="prev">Line Numbers</a>, Up: <a href="Program-Structure.html#Program-Structure" accesskey="u" rel="up">Program Structure</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="Procedures-1"></a>
  64. <h3 class="section">2.5 Procedures</h3>
  65. <a name="index-N_005fFUN_002c-for-functions"></a>
  66. <a name="index-N_005fFNAME"></a>
  67. <a name="index-N_005fSTSYM_002c-for-functions-_0028Sun-acc_0029"></a>
  68. <a name="index-N_005fGSYM_002c-for-functions-_0028Sun-acc_0029"></a>
  69. <p>All of the following stabs normally use the <code>N_FUN</code> symbol type.
  70. However, Sun&rsquo;s <code>acc</code> compiler on SunOS4 uses <code>N_GSYM</code> and
  71. <code>N_STSYM</code>, which means that the value of the stab for the function
  72. is useless and the debugger must get the address of the function from
  73. the non-stab symbols instead. On systems where non-stab symbols have
  74. leading underscores, the stabs will lack underscores and the debugger
  75. needs to know about the leading underscore to match up the stab and the
  76. non-stab symbol. BSD Fortran is said to use <code>N_FNAME</code> with the
  77. same restriction; the value of the symbol is not useful (I&rsquo;m not sure it
  78. really does use this, because GDB doesn&rsquo;t handle this and no one has
  79. complained).
  80. </p>
  81. <a name="index-C_005fFUN"></a>
  82. <p>A function is represented by an &lsquo;<samp>F</samp>&rsquo; symbol descriptor for a global
  83. (extern) function, and &lsquo;<samp>f</samp>&rsquo; for a static (local) function. For
  84. a.out, the value of the symbol is the address of the start of the
  85. function; it is already relocated. For stabs in ELF, the SunPRO
  86. compiler version 2.0.1 and GCC put out an address which gets relocated
  87. by the linker. In a future release SunPRO is planning to put out zero,
  88. in which case the address can be found from the ELF (non-stab) symbol.
  89. Because looking things up in the ELF symbols would probably be slow, I&rsquo;m
  90. not sure how to find which symbol of that name is the right one, and
  91. this doesn&rsquo;t provide any way to deal with nested functions, it would
  92. probably be better to make the value of the stab an address relative to
  93. the start of the file, or just absolute. See <a href="ELF-Linker-Relocation.html#ELF-Linker-Relocation">ELF Linker Relocation</a> for more information on linker relocation of stabs in ELF
  94. files. For XCOFF, the stab uses the <code>C_FUN</code> storage class and the
  95. value of the stab is meaningless; the address of the function can be
  96. found from the csect symbol (XTY_LD/XMC_PR).
  97. </p>
  98. <p>The type information of the stab represents the return type of the
  99. function; thus &lsquo;<samp>foo:f5</samp>&rsquo; means that foo is a function returning type
  100. 5. There is no need to try to get the line number of the start of the
  101. function from the stab for the function; it is in the next
  102. <code>N_SLINE</code> symbol.
  103. </p>
  104. <p>Some compilers (such as Sun&rsquo;s Solaris compiler) support an extension for
  105. specifying the types of the arguments. I suspect this extension is not
  106. used for old (non-prototyped) function definitions in C. If the
  107. extension is in use, the type information of the stab for the function
  108. is followed by type information for each argument, with each argument
  109. preceded by &lsquo;<samp>;</samp>&rsquo;. An argument type of 0 means that additional
  110. arguments are being passed, whose types and number may vary (&lsquo;<samp>...</samp>&rsquo;
  111. in ANSI C). GDB has tolerated this extension (parsed the syntax, if not
  112. necessarily used the information) since at least version 4.8; I don&rsquo;t
  113. know whether all versions of dbx tolerate it. The argument types given
  114. here are not redundant with the symbols for the formal parameters
  115. (see <a href="Parameters.html#Parameters">Parameters</a>); they are the types of the arguments as they are
  116. passed, before any conversions might take place. For example, if a C
  117. function which is declared without a prototype takes a <code>float</code>
  118. argument, the value is passed as a <code>double</code> but then converted to a
  119. <code>float</code>. Debuggers need to use the types given in the arguments
  120. when printing values, but when calling the function they need to use the
  121. types given in the symbol defining the function.
  122. </p>
  123. <p>If the return type and types of arguments of a function which is defined
  124. in another source file are specified (i.e., a function prototype in ANSI
  125. C), traditionally compilers emit no stab; the only way for the debugger
  126. to find the information is if the source file where the function is
  127. defined was also compiled with debugging symbols. As an extension the
  128. Solaris compiler uses symbol descriptor &lsquo;<samp>P</samp>&rsquo; followed by the return
  129. type of the function, followed by the arguments, each preceded by
  130. &lsquo;<samp>;</samp>&rsquo;, as in a stab with symbol descriptor &lsquo;<samp>f</samp>&rsquo; or &lsquo;<samp>F</samp>&rsquo;.
  131. This use of symbol descriptor &lsquo;<samp>P</samp>&rsquo; can be distinguished from its use
  132. for register parameters (see <a href="Register-Parameters.html#Register-Parameters">Register Parameters</a>) by the fact that it has
  133. symbol type <code>N_FUN</code>.
  134. </p>
  135. <p>The AIX documentation also defines symbol descriptor &lsquo;<samp>J</samp>&rsquo; as an
  136. internal function. I assume this means a function nested within another
  137. function. It also says symbol descriptor &lsquo;<samp>m</samp>&rsquo; is a module in
  138. Modula-2 or extended Pascal.
  139. </p>
  140. <p>Procedures (functions which do not return values) are represented as
  141. functions returning the <code>void</code> type in C. I don&rsquo;t see why this couldn&rsquo;t
  142. be used for all languages (inventing a <code>void</code> type for this purpose if
  143. necessary), but the AIX documentation defines &lsquo;<samp>I</samp>&rsquo;, &lsquo;<samp>P</samp>&rsquo;, and
  144. &lsquo;<samp>Q</samp>&rsquo; for internal, global, and static procedures, respectively.
  145. These symbol descriptors are unusual in that they are not followed by
  146. type information.
  147. </p>
  148. <p>The following example shows a stab for a function <code>main</code> which
  149. returns type number <code>1</code>. The <code>_main</code> specified for the value
  150. is a reference to an assembler label which is used to fill in the start
  151. address of the function.
  152. </p>
  153. <div class="example">
  154. <pre class="example">.stabs &quot;main:F1&quot;,36,0,0,_main # <span class="roman">36 is N_FUN</span>
  155. </pre></div>
  156. <p>The stab representing a procedure is located immediately following the
  157. code of the procedure. This stab is in turn directly followed by a
  158. group of other stabs describing elements of the procedure. These other
  159. stabs describe the procedure&rsquo;s parameters, its block local variables, and
  160. its block structure.
  161. </p>
  162. <p>If functions can appear in different sections, then the debugger may not
  163. be able to find the end of a function. Recent versions of GCC will mark
  164. the end of a function with an <code>N_FUN</code> symbol with an empty string
  165. for the name. The value is the address of the end of the current
  166. function. Without such a symbol, there is no indication of the address
  167. of the end of a function, and you must assume that it ended at the
  168. starting address of the next function or at the end of the text section
  169. for the program.
  170. </p>
  171. <hr>
  172. <div class="header">
  173. <p>
  174. Next: <a href="Nested-Procedures.html#Nested-Procedures" accesskey="n" rel="next">Nested Procedures</a>, Previous: <a href="Line-Numbers.html#Line-Numbers" accesskey="p" rel="prev">Line Numbers</a>, Up: <a href="Program-Structure.html#Program-Structure" accesskey="u" rel="up">Program Structure</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  175. </div>
  176. </body>
  177. </html>