| <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- Copyright (C) 1988-2015 Free Software Foundation, Inc. |
| |
| Permission is granted to copy, distribute and/or modify this document |
| under the terms of the GNU Free Documentation License, Version 1.3 or |
| any later version published by the Free Software Foundation; with the |
| Invariant Sections being "Funding Free Software", the Front-Cover |
| Texts being (a) (see below), and with the Back-Cover Texts being (b) |
| (see below). A copy of the license is included in the section entitled |
| "GNU Free Documentation License". |
| |
| (a) The FSF's Front-Cover Text is: |
| |
| A GNU Manual |
| |
| (b) The FSF's Back-Cover Text is: |
| |
| You have freedom to copy and modify this GNU Manual, like GNU |
| software. Copies published by the Free Software Foundation raise |
| funds for GNU development. --> |
| <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> |
| <head> |
| <title>Using the GNU Compiler Collection (GCC): Return Address</title> |
| |
| <meta name="description" content="Using the GNU Compiler Collection (GCC): Return Address"> |
| <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Return Address"> |
| <meta name="resource-type" content="document"> |
| <meta name="distribution" content="global"> |
| <meta name="Generator" content="makeinfo"> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| <link href="index.html#Top" rel="start" title="Top"> |
| <link href="Option-Index.html#Option-Index" rel="index" title="Option Index"> |
| <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| <link href="C-Extensions.html#C-Extensions" rel="up" title="C Extensions"> |
| <link href="Vector-Extensions.html#Vector-Extensions" rel="next" title="Vector Extensions"> |
| <link href="Function-Names.html#Function-Names" rel="prev" title="Function Names"> |
| <style type="text/css"> |
| <!-- |
| a.summary-letter {text-decoration: none} |
| blockquote.smallquotation {font-size: smaller} |
| div.display {margin-left: 3.2em} |
| div.example {margin-left: 3.2em} |
| div.indentedblock {margin-left: 3.2em} |
| div.lisp {margin-left: 3.2em} |
| div.smalldisplay {margin-left: 3.2em} |
| div.smallexample {margin-left: 3.2em} |
| div.smallindentedblock {margin-left: 3.2em; font-size: smaller} |
| div.smalllisp {margin-left: 3.2em} |
| kbd {font-style:oblique} |
| pre.display {font-family: inherit} |
| pre.format {font-family: inherit} |
| pre.menu-comment {font-family: serif} |
| pre.menu-preformatted {font-family: serif} |
| pre.smalldisplay {font-family: inherit; font-size: smaller} |
| pre.smallexample {font-size: smaller} |
| pre.smallformat {font-family: inherit; font-size: smaller} |
| pre.smalllisp {font-size: smaller} |
| span.nocodebreak {white-space:nowrap} |
| span.nolinebreak {white-space:nowrap} |
| span.roman {font-family:serif; font-weight:normal} |
| span.sansserif {font-family:sans-serif; font-weight:normal} |
| ul.no-bullet {list-style: none} |
| --> |
| </style> |
| |
| |
| </head> |
| |
| <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> |
| <a name="Return-Address"></a> |
| <div class="header"> |
| <p> |
| Next: <a href="Vector-Extensions.html#Vector-Extensions" accesskey="n" rel="next">Vector Extensions</a>, Previous: <a href="Function-Names.html#Function-Names" accesskey="p" rel="prev">Function Names</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p> |
| </div> |
| <hr> |
| <a name="Getting-the-Return-or-Frame-Address-of-a-Function"></a> |
| <h3 class="section">6.48 Getting the Return or Frame Address of a Function</h3> |
| |
| <p>These functions may be used to get information about the callers of a |
| function. |
| </p> |
| <dl> |
| <dt><a name="index-_005f_005fbuiltin_005freturn_005faddress"></a>Built-in Function: <em>void *</em> <strong>__builtin_return_address</strong> <em>(unsigned int <var>level</var>)</em></dt> |
| <dd><p>This function returns the return address of the current function, or of |
| one of its callers. The <var>level</var> argument is number of frames to |
| scan up the call stack. A value of <code>0</code> yields the return address |
| of the current function, a value of <code>1</code> yields the return address |
| of the caller of the current function, and so forth. When inlining |
| the expected behavior is that the function returns the address of |
| the function that is returned to. To work around this behavior use |
| the <code>noinline</code> function attribute. |
| </p> |
| <p>The <var>level</var> argument must be a constant integer. |
| </p> |
| <p>On some machines it may be impossible to determine the return address of |
| any function other than the current one; in such cases, or when the top |
| of the stack has been reached, this function returns <code>0</code> or a |
| random value. In addition, <code>__builtin_frame_address</code> may be used |
| to determine if the top of the stack has been reached. |
| </p> |
| <p>Additional post-processing of the returned value may be needed, see |
| <code>__builtin_extract_return_addr</code>. |
| </p> |
| <p>This function should only be used with a nonzero argument for debugging |
| purposes. |
| </p></dd></dl> |
| |
| <dl> |
| <dt><a name="index-_005f_005fbuiltin_005fextract_005freturn_005faddr"></a>Built-in Function: <em>void *</em> <strong>__builtin_extract_return_addr</strong> <em>(void *<var>addr</var>)</em></dt> |
| <dd><p>The address as returned by <code>__builtin_return_address</code> may have to be fed |
| through this function to get the actual encoded address. For example, on the |
| 31-bit S/390 platform the highest bit has to be masked out, or on SPARC |
| platforms an offset has to be added for the true next instruction to be |
| executed. |
| </p> |
| <p>If no fixup is needed, this function simply passes through <var>addr</var>. |
| </p></dd></dl> |
| |
| <dl> |
| <dt><a name="index-_005f_005fbuiltin_005ffrob_005freturn_005faddress"></a>Built-in Function: <em>void *</em> <strong>__builtin_frob_return_address</strong> <em>(void *<var>addr</var>)</em></dt> |
| <dd><p>This function does the reverse of <code>__builtin_extract_return_addr</code>. |
| </p></dd></dl> |
| |
| <dl> |
| <dt><a name="index-_005f_005fbuiltin_005fframe_005faddress"></a>Built-in Function: <em>void *</em> <strong>__builtin_frame_address</strong> <em>(unsigned int <var>level</var>)</em></dt> |
| <dd><p>This function is similar to <code>__builtin_return_address</code>, but it |
| returns the address of the function frame rather than the return address |
| of the function. Calling <code>__builtin_frame_address</code> with a value of |
| <code>0</code> yields the frame address of the current function, a value of |
| <code>1</code> yields the frame address of the caller of the current function, |
| and so forth. |
| </p> |
| <p>The frame is the area on the stack that holds local variables and saved |
| registers. The frame address is normally the address of the first word |
| pushed on to the stack by the function. However, the exact definition |
| depends upon the processor and the calling convention. If the processor |
| has a dedicated frame pointer register, and the function has a frame, |
| then <code>__builtin_frame_address</code> returns the value of the frame |
| pointer register. |
| </p> |
| <p>On some machines it may be impossible to determine the frame address of |
| any function other than the current one; in such cases, or when the top |
| of the stack has been reached, this function returns <code>0</code> if |
| the first frame pointer is properly initialized by the startup code. |
| </p> |
| <p>This function should only be used with a nonzero argument for debugging |
| purposes. |
| </p></dd></dl> |
| |
| <hr> |
| <div class="header"> |
| <p> |
| Next: <a href="Vector-Extensions.html#Vector-Extensions" accesskey="n" rel="next">Vector Extensions</a>, Previous: <a href="Function-Names.html#Function-Names" accesskey="p" rel="prev">Function Names</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p> |
| </div> |
| |
| |
| |
| </body> |
| </html> |