2007-08-11 01:28:22 +04:00
|
|
|
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 15:12:37 +04: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-11 01:28:22 +04: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 07:56:43 +04:00
|
|
|
#include <mozilla/StandardInteger.h>
|
2012-09-07 01:54:59 +04:00
|
|
|
#include "prtypes.h"
|
2007-08-11 01:28:22 +04:00
|
|
|
|
|
|
|
PR_BEGIN_EXTERN_C
|
|
|
|
|
2012-06-28 00:08:21 +04: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-11 01:28:22 +04:00
|
|
|
typedef void
|
2012-06-28 00:08:21 +04:00
|
|
|
(* NS_WalkStackCallback)(void *aPC, void *aSP, void *aClosure);
|
2007-08-11 01:28:22 +04: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-24 03:14:09 +04: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-11 01:28:22 +04:00
|
|
|
*
|
|
|
|
* Returns NS_ERROR_NOT_IMPLEMENTED on platforms where it is
|
|
|
|
* unimplemented.
|
2009-02-18 08:11:29 +03: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-11 01:28:22 +04:00
|
|
|
*
|
|
|
|
* May skip some stack frames due to compiler optimizations or code
|
|
|
|
* generation.
|
|
|
|
*/
|
|
|
|
XPCOM_API(nsresult)
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_StackWalk(NS_WalkStackCallback aCallback, uint32_t aSkipFrames,
|
2011-12-24 03:14:09 +04:00
|
|
|
void *aClosure, uintptr_t aThread);
|
2007-08-11 01:28:22 +04:00
|
|
|
|
2007-08-11 01:29:37 +04: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];
|
2009-03-22 06:53:47 +03:00
|
|
|
PRUptrdiff loffset;
|
2007-08-11 01:29:37 +04: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];
|
2009-03-22 06:53:47 +03:00
|
|
|
PRUptrdiff foffset;
|
2007-08-11 01:29:37 +04: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 19:56:38 +04:00
|
|
|
char *aBuffer, uint32_t aBufferSize);
|
2007-08-11 01:29:37 +04:00
|
|
|
|
2007-08-11 01:28:22 +04:00
|
|
|
PR_END_EXTERN_C
|
|
|
|
|
|
|
|
#endif /* !defined(nsStackWalk_h_) */
|