2007-08-10 14:28:22 -07:00
|
|
|
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-08-10 14:28:22 -07:00
|
|
|
|
|
|
|
/* API for getting a stack trace of the C/C++ stack on the current thread */
|
|
|
|
|
|
|
|
#ifndef nsStackWalk_h_
|
|
|
|
#define nsStackWalk_h_
|
|
|
|
|
|
|
|
/* WARNING: This file is intended to be included from C or C++ files. */
|
|
|
|
|
|
|
|
#include "nscore.h"
|
2013-07-30 07:25:31 -07:00
|
|
|
#include <stdint.h>
|
2007-08-10 14:28:22 -07:00
|
|
|
|
2012-09-30 19:10:22 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2007-08-10 14:28:22 -07:00
|
|
|
|
2012-06-27 13:08:21 -07:00
|
|
|
// aSP will be the best approximation possible of what the stack pointer will be
|
|
|
|
// pointing to when the execution returns to executing that at that PC.
|
2013-10-10 13:41:00 -07:00
|
|
|
// If no approximation can be made it will be nullptr.
|
2007-08-10 14:28:22 -07:00
|
|
|
typedef void
|
2012-06-27 13:08:21 -07:00
|
|
|
(* NS_WalkStackCallback)(void *aPC, void *aSP, void *aClosure);
|
2007-08-10 14:28:22 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call aCallback for the C/C++ stack frames on the current thread, from
|
|
|
|
* the caller of NS_StackWalk to main (or above).
|
|
|
|
*
|
|
|
|
* @param aCallback Callback function, called once per frame.
|
|
|
|
* @param aSkipFrames Number of initial frames to skip. 0 means that
|
|
|
|
* the first callback will be for the caller of
|
|
|
|
* NS_StackWalk.
|
2012-12-20 21:31:57 -08:00
|
|
|
* @param aMaxFrames Maximum number of frames to trace. 0 means no limit.
|
2007-08-10 14:28:22 -07:00
|
|
|
* @param aClosure Caller-supplied data passed through to aCallback.
|
2011-12-23 15:14:09 -08:00
|
|
|
* @param aThread The thread for which the stack is to be retrieved.
|
|
|
|
* Passing null causes us to walk the stack of the
|
|
|
|
* current thread. On Windows, this is a thread HANDLE.
|
|
|
|
* It is currently not supported on any other platform.
|
2012-12-07 21:15:21 -08:00
|
|
|
* @param aPlatformData Platform specific data that can help in walking the
|
2013-10-10 13:41:00 -07:00
|
|
|
* stack, this should be nullptr unless you really know
|
2012-12-07 21:15:21 -08:00
|
|
|
* what you're doing! This needs to be a pointer to a
|
|
|
|
* CONTEXT on Windows and should not be passed on other
|
|
|
|
* platforms.
|
2007-08-10 14:28:22 -07:00
|
|
|
*
|
2012-12-20 21:31:57 -08:00
|
|
|
* Return values:
|
|
|
|
* - NS_ERROR_NOT_IMPLEMENTED. Occurs on platforms where it is unimplemented.
|
|
|
|
*
|
|
|
|
* - NS_ERROR_UNEXPECTED. Occurs when the stack indicates that the thread
|
|
|
|
* is in a very dangerous situation (e.g., holding sem_pool_lock in Mac OS X
|
|
|
|
* pthreads code). Callers should then bail out immediately.
|
|
|
|
*
|
|
|
|
* - NS_ERROR_FAILURE. Occurs when stack walking completely failed, i.e.
|
|
|
|
* aCallback was never called.
|
|
|
|
*
|
|
|
|
* - NS_OK. Occurs when stack walking succeeded, i.e. aCallback was called at
|
|
|
|
* least once (and there was no need to exit with NS_ERROR_UNEXPECTED).
|
2007-08-10 14:28:22 -07:00
|
|
|
*
|
|
|
|
* May skip some stack frames due to compiler optimizations or code
|
|
|
|
* generation.
|
|
|
|
*/
|
|
|
|
XPCOM_API(nsresult)
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_StackWalk(NS_WalkStackCallback aCallback, uint32_t aSkipFrames,
|
2012-12-20 21:31:57 -08:00
|
|
|
uint32_t aMaxFrames, void *aClosure, uintptr_t aThread,
|
|
|
|
void *aPlatformData);
|
2007-08-10 14:28:22 -07:00
|
|
|
|
2007-08-10 14:29:37 -07:00
|
|
|
typedef struct {
|
|
|
|
/*
|
|
|
|
* The name of the shared library or executable containing an
|
|
|
|
* address and the address's offset within that library, or empty
|
|
|
|
* string and zero if unknown.
|
|
|
|
*/
|
|
|
|
char library[256];
|
2012-09-14 13:09:52 -07:00
|
|
|
ptrdiff_t loffset;
|
2007-08-10 14:29:37 -07:00
|
|
|
/*
|
|
|
|
* The name of the file name and line number of the code
|
|
|
|
* corresponding to the address, or empty string and zero if
|
|
|
|
* unknown.
|
|
|
|
*/
|
|
|
|
char filename[256];
|
|
|
|
unsigned long lineno;
|
|
|
|
/*
|
|
|
|
* The name of the function containing an address and the address's
|
|
|
|
* offset within that function, or empty string and zero if unknown.
|
|
|
|
*/
|
|
|
|
char function[256];
|
2012-09-14 13:09:52 -07:00
|
|
|
ptrdiff_t foffset;
|
2007-08-10 14:29:37 -07:00
|
|
|
} nsCodeAddressDetails;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For a given pointer to code, fill in the pieces of information used
|
|
|
|
* when printing a stack trace.
|
|
|
|
*
|
|
|
|
* @param aPC The code address.
|
|
|
|
* @param aDetails A structure to be filled in with the result.
|
|
|
|
*/
|
|
|
|
XPCOM_API(nsresult)
|
|
|
|
NS_DescribeCodeAddress(void *aPC, nsCodeAddressDetails *aDetails);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format the information about a code address in a format suitable for
|
|
|
|
* stack traces on the current platform. When available, this string
|
|
|
|
* should contain the function name, source file, and line number. When
|
|
|
|
* these are not available, library and offset should be reported, if
|
|
|
|
* possible.
|
|
|
|
*
|
|
|
|
* @param aPC The code address.
|
|
|
|
* @param aDetails The value filled in by NS_DescribeCodeAddress(aPC).
|
|
|
|
* @param aBuffer A string to be filled in with the description.
|
|
|
|
* The string will always be null-terminated.
|
|
|
|
* @param aBufferSize The size, in bytes, of aBuffer, including
|
|
|
|
* room for the terminating null. If the information
|
|
|
|
* to be printed would be larger than aBuffer, it
|
|
|
|
* will be truncated so that aBuffer[aBufferSize-1]
|
|
|
|
* is the terminating null.
|
|
|
|
*/
|
|
|
|
XPCOM_API(nsresult)
|
|
|
|
NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
|
2012-08-22 08:56:38 -07:00
|
|
|
char *aBuffer, uint32_t aBufferSize);
|
2007-08-10 14:29:37 -07:00
|
|
|
|
2012-09-30 19:10:22 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-10 14:28:22 -07:00
|
|
|
|
|
|
|
#endif /* !defined(nsStackWalk_h_) */
|