2014-05-05 21:30:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
|
2017-08-11 22:15:31 +03:00
|
|
|
/* APIs for getting a stack trace of the current thread */
|
2007-08-11 01:28:22 +04:00
|
|
|
|
2015-06-10 23:32:45 +03:00
|
|
|
#ifndef mozilla_StackWalk_h
|
|
|
|
#define mozilla_StackWalk_h
|
2007-08-11 01:28:22 +04:00
|
|
|
|
2015-06-10 23:32:45 +03:00
|
|
|
#include "mozilla/Types.h"
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2007-08-11 01:28:22 +04:00
|
|
|
|
2014-09-11 08:47:01 +04:00
|
|
|
/**
|
2017-07-27 05:46:47 +03:00
|
|
|
* The callback for MozStackWalk and MozStackWalkThread.
|
2014-09-11 08:47:01 +04:00
|
|
|
*
|
|
|
|
* @param aFrameNumber The frame number (starts at 1, not 0).
|
|
|
|
* @param aPC The program counter value.
|
|
|
|
* @param aSP The best approximation possible of what the stack
|
|
|
|
* pointer will be pointing to when the execution returns
|
|
|
|
* to executing that at aPC. If no approximation can
|
|
|
|
* be made it will be nullptr.
|
2017-07-27 05:46:47 +03:00
|
|
|
* @param aClosure Extra data passed in from MozStackWalk() or
|
|
|
|
* MozStackWalkThread().
|
2014-09-11 08:47:01 +04:00
|
|
|
*/
|
2015-06-10 23:32:45 +03:00
|
|
|
typedef void (*MozWalkStackCallback)(uint32_t aFrameNumber, void* aPC,
|
2014-09-11 08:47:01 +04:00
|
|
|
void* aSP, void* aClosure);
|
2007-08-11 01:28:22 +04:00
|
|
|
|
|
|
|
/**
|
2017-08-11 22:15:31 +03:00
|
|
|
* Call aCallback for each stack frame on the current thread, from
|
2015-06-10 23:32:45 +03:00
|
|
|
* the caller of MozStackWalk to main (or above).
|
2007-08-11 01:28:22 +04:00
|
|
|
*
|
|
|
|
* @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
|
2015-06-10 23:32:45 +03:00
|
|
|
* MozStackWalk.
|
2012-12-21 09:31:57 +04:00
|
|
|
* @param aMaxFrames Maximum number of frames to trace. 0 means no limit.
|
2007-08-11 01:28:22 +04:00
|
|
|
* @param aClosure Caller-supplied data passed through to aCallback.
|
|
|
|
*
|
|
|
|
* May skip some stack frames due to compiler optimizations or code
|
|
|
|
* generation.
|
|
|
|
*/
|
2015-06-10 23:32:45 +03:00
|
|
|
MFBT_API void MozStackWalk(MozWalkStackCallback aCallback, uint32_t aSkipFrames,
|
2017-07-27 05:46:47 +03:00
|
|
|
uint32_t aMaxFrames, void* aClosure);
|
|
|
|
|
2018-08-23 23:48:53 +03:00
|
|
|
#if defined(_WIN32) && (defined(_M_IX86) || defined(_M_AMD64) || \
|
|
|
|
defined(_M_IA64) || defined(_M_ARM64))
|
2017-07-27 05:46:47 +03:00
|
|
|
|
|
|
|
# include <windows.h>
|
|
|
|
|
|
|
|
# define MOZ_STACKWALK_SUPPORTS_WINDOWS 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like MozStackWalk, but walks the stack for another thread.
|
2017-08-11 22:15:31 +03:00
|
|
|
* Call aCallback for each stack frame on the current thread, from
|
2017-07-27 05:46:47 +03:00
|
|
|
* the caller of MozStackWalk to main (or above).
|
|
|
|
*
|
|
|
|
* @param aCallback Same as for MozStackWalk().
|
|
|
|
* @param aSkipFrames Same as for MozStackWalk().
|
|
|
|
* @param aMaxFrames Same as for MozStackWalk().
|
|
|
|
* @param aClosure Same as for MozStackWalk().
|
|
|
|
* @param aThread The handle of the thread whose stack is to be walked.
|
|
|
|
* If 0, walks the current thread.
|
|
|
|
* @param aContext A CONTEXT, presumably obtained with GetThreadContext()
|
|
|
|
* after suspending the thread with SuspendThread(). If
|
|
|
|
* null, the CONTEXT will be re-obtained.
|
|
|
|
*/
|
|
|
|
MFBT_API void MozStackWalkThread(MozWalkStackCallback aCallback,
|
|
|
|
uint32_t aSkipFrames, uint32_t aMaxFrames,
|
|
|
|
void* aClosure, HANDLE aThread,
|
|
|
|
CONTEXT* aContext);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
# define MOZ_STACKWALK_SUPPORTS_WINDOWS 0
|
|
|
|
|
|
|
|
#endif
|
2007-08-11 01:28:22 +04:00
|
|
|
|
2014-05-13 21:41:38 +04:00
|
|
|
typedef struct {
|
2014-05-05 21:30:39 +04:00
|
|
|
/*
|
|
|
|
* 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];
|
|
|
|
ptrdiff_t loffset;
|
|
|
|
/*
|
|
|
|
* 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];
|
|
|
|
ptrdiff_t foffset;
|
2015-06-10 23:32:45 +03:00
|
|
|
} MozCodeAddressDetails;
|
2007-08-11 01:29:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-06-10 23:32:45 +03:00
|
|
|
MFBT_API bool MozDescribeCodeAddress(void* aPC,
|
|
|
|
MozCodeAddressDetails* aDetails);
|
2007-08-11 01:29:37 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2014-09-02 09:56:05 +04:00
|
|
|
* Note that this output is parsed by several scripts including the fix*.py and
|
|
|
|
* make-tree.pl scripts in tools/rb/. It should only be change with care, and
|
|
|
|
* in conjunction with those scripts.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
* @param aFrameNumber The frame number.
|
2014-09-11 08:47:01 +04:00
|
|
|
* @param aPC The code address.
|
2014-09-02 09:56:05 +04:00
|
|
|
* @param aFunction The function name. Possibly null or the empty string.
|
|
|
|
* @param aLibrary The library name. Possibly null or the empty string.
|
|
|
|
* @param aLOffset The library offset.
|
|
|
|
* @param aFileName The filename. Possibly null or the empty string.
|
|
|
|
* @param aLineNo The line number. Possibly zero.
|
|
|
|
*/
|
2015-06-10 23:32:45 +03:00
|
|
|
MFBT_API void MozFormatCodeAddress(char* aBuffer, uint32_t aBufferSize,
|
|
|
|
uint32_t aFrameNumber, const void* aPC,
|
2014-09-02 09:56:05 +04:00
|
|
|
const char* aFunction, const char* aLibrary,
|
|
|
|
ptrdiff_t aLOffset, const char* aFileName,
|
|
|
|
uint32_t aLineNo);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format the information about a code address in the same fashion as
|
2015-06-10 23:32:45 +03:00
|
|
|
* MozFormatCodeAddress.
|
2014-09-02 09:56:05 +04:00
|
|
|
*
|
2014-09-11 08:47:01 +04:00
|
|
|
* @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.
|
2014-09-02 09:56:05 +04:00
|
|
|
* @param aFrameNumber The frame number.
|
|
|
|
* @param aPC The code address.
|
2015-06-10 23:32:45 +03:00
|
|
|
* @param aDetails The value filled in by MozDescribeCodeAddress(aPC).
|
2007-08-11 01:29:37 +04:00
|
|
|
*/
|
2015-06-10 23:32:45 +03:00
|
|
|
MFBT_API void MozFormatCodeAddressDetails(
|
|
|
|
char* aBuffer, uint32_t aBufferSize, uint32_t aFrameNumber, void* aPC,
|
|
|
|
const MozCodeAddressDetails* aDetails);
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
MFBT_API void FramePointerStackWalk(MozWalkStackCallback aCallback,
|
|
|
|
uint32_t aSkipFrames, uint32_t aMaxFrames,
|
|
|
|
void* aClosure, void** aBp,
|
|
|
|
void* aStackEnd);
|
2007-08-11 01:29:37 +04:00
|
|
|
|
2019-08-23 08:45:16 +03:00
|
|
|
#ifdef XP_LINUX
|
|
|
|
MFBT_API void DemangleSymbol(const char* aSymbol, char* aBuffer, int aBufLen);
|
|
|
|
#endif
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2007-08-11 01:28:22 +04:00
|
|
|
|
2015-06-10 23:32:45 +03:00
|
|
|
#endif
|