2007-08-10 21:28:22 +00:00
|
|
|
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 11:12:37 +00: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 21:28:22 +00: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"
|
2012-03-01 03:56:43 +00:00
|
|
|
#include <mozilla/StandardInteger.h>
|
2007-08-10 21:28:22 +00:00
|
|
|
|
2012-10-01 02:10:22 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2007-08-10 21:28:22 +00:00
|
|
|
|
2012-06-27 20:08:21 +00: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.
|
|
|
|
// If no approximation can be made it will be NULL.
|
2007-08-10 21:28:22 +00:00
|
|
|
typedef void
|
2012-06-27 20:08:21 +00:00
|
|
|
(* NS_WalkStackCallback)(void *aPC, void *aSP, void *aClosure);
|
2007-08-10 21:28:22 +00: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.
|
|
|
|
* @param aClosure Caller-supplied data passed through to aCallback.
|
2011-12-23 23:14:09 +00: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.
|
2007-08-10 21:28:22 +00:00
|
|
|
*
|
|
|
|
* Returns NS_ERROR_NOT_IMPLEMENTED on platforms where it is
|
|
|
|
* unimplemented.
|
2009-02-18 05:11:29 +00:00
|
|
|
* Returns NS_ERROR_UNEXPECTED 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.
|
2007-08-10 21:28:22 +00:00
|
|
|
*
|
|
|
|
* May skip some stack frames due to compiler optimizations or code
|
|
|
|
* generation.
|
|
|
|
*/
|
|
|
|
XPCOM_API(nsresult)
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_StackWalk(NS_WalkStackCallback aCallback, uint32_t aSkipFrames,
|
2011-12-23 23:14:09 +00:00
|
|
|
void *aClosure, uintptr_t aThread);
|
2007-08-10 21:28:22 +00:00
|
|
|
|
2007-08-10 21:29:37 +00: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 20:09:52 +00:00
|
|
|
ptrdiff_t loffset;
|
2007-08-10 21:29:37 +00: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 20:09:52 +00:00
|
|
|
ptrdiff_t foffset;
|
2007-08-10 21:29:37 +00: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 15:56:38 +00:00
|
|
|
char *aBuffer, uint32_t aBufferSize);
|
2007-08-10 21:29:37 +00:00
|
|
|
|
2012-10-01 02:10:22 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-10 21:28:22 +00:00
|
|
|
|
|
|
|
#endif /* !defined(nsStackWalk_h_) */
|