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