Pixar Arch 0.25.8
Loading...
Searching...
No Matches
stackTrace.h
Go to the documentation of this file.
1// Copyright 2016 Pixar
2//
3// Licensed under the terms set forth in the LICENSE.txt file available at
4// https://openusd.org/license.
5//
6// Modified by Jeremy Retailleau.
7
8#ifndef PXR_ARCH_STACK_TRACE_H
9#define PXR_ARCH_STACK_TRACE_H
10
13
14#include "pxr/arch/pxr.h"
15#include "pxr/arch/api.h"
16#include "pxr/arch/defines.h"
17
18#include <inttypes.h>
19#include <stdio.h>
20#include <functional>
21#include <vector>
22#include <string>
23#include <iosfwd>
24#include <ctime>
25
26ARCH_NAMESPACE_OPEN_SCOPE
27
47ARCH_API
48void ArchLogFatalProcessState(const char* reason,
49 const char* message = nullptr,
50 const char* extraLogMsg = nullptr);
51
68ARCH_API
69void ArchLogCurrentProcessState(const char* reason,
70 const char* message = nullptr,
71 const char* extraLogMsg = nullptr);
72
94ARCH_API
95void ArchSetProcessStateLogCommand(const char* command,
96 const char *const argv[],
97 const char* const fatalArgv[]);
98
101ARCH_API
103
109ARCH_API
110void ArchLogSessionInfo(const char *crashStackTrace=NULL);
111
133ARCH_API
134void ArchSetLogSession(const char* command,
135 const char* const argv[],
136 const char* const crashArgv[]);
137
142ARCH_API
144
146ARCH_API
147void ArchPrintStackTrace(FILE *fout,
148 const std::string& programName,
149 const std::string& reason);
150
154ARCH_API
155void ArchPrintStackTrace(FILE *fout, const std::string& reason);
156
159ARCH_API
160void ArchPrintStackTrace(std::ostream& out,
161 const std::string& programName,
162 const std::string& reason);
163
167ARCH_API
168void ArchPrintStackTrace(std::ostream& out, const std::string& reason);
169
171typedef std::function<std::string(uintptr_t address)> ArchStackTraceCallback;
172
178ARCH_API
180
183ARCH_API
185
188ARCH_API
190
196ARCH_API
198
202ARCH_API
204
208ARCH_API
209void ArchSetProgramNameForErrors(const char * progName);
210
213ARCH_API
215
218ARCH_API
219void ArchSetProgramInfoForErrors( const std::string& key, const std::string& value );
220
223ARCH_API
224std::string ArchGetProgramInfoForErrors(const std::string& key);
225
233ARCH_API
234void ArchSetExtraLogInfoForErrors(const std::string &key,
235 std::vector<std::string> const *lines);
236
247ARCH_API
248void ArchLogStackTrace(const std::string& progName,
249 const std::string& reason,
250 bool fatal = false,
251 const std::string& sessionLog = "");
252
263ARCH_API
264void ArchLogStackTrace(const std::string& reason,
265 bool fatal = false,
266 const std::string& sessionLog = "");
267
272ARCH_API
273std::vector<std::string> ArchGetStackTrace(size_t maxDepth);
274
275
280ARCH_API
281void ArchGetStackFrames(size_t maxDepth, std::vector<uintptr_t> *frames);
282
285ARCH_API
286size_t ArchGetStackFrames(size_t maxDepth, uintptr_t *frames);
287
294ARCH_API
295void ArchGetStackFrames(size_t maxDepth, size_t numFramesToSkipAtTop,
296 std::vector<uintptr_t> *frames);
297
301ARCH_API
302size_t ArchGetStackFrames(size_t maxDepth, size_t numFramesToSkipAtTop,
303 uintptr_t *frames);
304
305
307ARCH_API
308void ArchPrintStackFrames(std::ostream& out,
309 const std::vector<uintptr_t> &frames,
310 bool skipUnknownFrames = false);
311
314typedef void (*ArchCrashHandlerSystemCB)(void* userData);
315
329ARCH_API
330int ArchCrashHandlerSystemv(const char* pathname, char *const argv[],
331 int timeout, ArchCrashHandlerSystemCB callback,
332 void* userData);
333
334#if defined(ARCH_OS_DARWIN)
335// macOS has no ETIME. ECANCELED seems to have about the closest meaning to
336// the actual error here. The operation is timing out, not being explicitly
337// canceled, but it is canceled.
338#ifndef ETIME
339#define ETIME ECANCELED
340#endif // end ETIME
341#endif // end ARCH_OS_DARWIN
342
343ARCH_NAMESPACE_CLOSE_SCOPE
344
345#endif // PXR_ARCH_STACK_TRACE_H
Define integral types.
void ArchSetExtraLogInfoForErrors(const std::string &key, std::vector< std::string > const *lines)
Stores (or removes if lines is nullptr) a pointer to additional log data that will be output in the s...
int ArchCrashHandlerSystemv(const char *pathname, char *const argv[], int timeout, ArchCrashHandlerSystemCB callback, void *userData)
Replacement for 'system' safe for a crash handler.
bool ArchIsAppCrashing()
Returns true if the fatal signal handler ArchLogFatalProcessState has been invoked.
void ArchPrintStackTrace(FILE *fout, const std::string &programName, const std::string &reason)
Print a stack trace to the given FILE pointer.
void ArchGetStackTraceCallback(ArchStackTraceCallback *cb)
Returns the callback to get a symbolic representation of an address.
void ArchLogFatalProcessState(const char *reason, const char *message=nullptr, const char *extraLogMsg=nullptr)
Dumps call-stack info to a file, prints a message to the terminal, and invokes crash handling script.
void ArchSetStackTraceCallback(const ArchStackTraceCallback &cb)
Sets a callback to get a symbolic representation of an address.
void ArchLogSessionInfo(const char *crashStackTrace=NULL)
Log session info.
void(* ArchCrashHandlerSystemCB)(void *userData)
Callback for handling crashes.
Definition stackTrace.h:314
void ArchLogCurrentProcessState(const char *reason, const char *message=nullptr, const char *extraLogMsg=nullptr)
Dumps call-stack info to a file, and prints an informative message.
std::function< std::string(uintptr_t address)> ArchStackTraceCallback
A callback to get a symbolic representation of an address.
Definition stackTrace.h:171
void ArchSetFatalStackLogging(bool flag)
Enables or disables the automatic logging of crash information.
time_t ArchGetAppLaunchTime()
Returns the set value for the application's launch time.
const char * ArchGetProgramNameForErrors()
Returns the currently set program name for reporting errors.
std::string ArchGetProgramInfoForErrors(const std::string &key)
Returns currently set program info.
void ArchGetStackFrames(size_t maxDepth, std::vector< uintptr_t > *frames)
Save frames of current stack.
void ArchPrintStackFrames(std::ostream &out, const std::vector< uintptr_t > &frames, bool skipUnknownFrames=false)
Print stack frames to the given ostream.
void ArchSetProgramInfoForErrors(const std::string &key, const std::string &value)
Sets additional program info to be reported to the terminal in case of a fatal error.
void ArchLogStackTrace(const std::string &progName, const std::string &reason, bool fatal=false, const std::string &sessionLog="")
Logs a stack trace to a file in /var/tmp.
void ArchEnableSessionLogging()
Register the callback to invoke logging at end of a successful session.
bool ArchGetFatalStackLogging()
Returns whether automatic logging of fatal crashes is enabled This is set to false by default.
void ArchSetLogSession(const char *command, const char *const argv[], const char *const crashArgv[])
Sets the command line to log sessions.
std::vector< std::string > ArchGetStackTrace(size_t maxDepth)
Return stack trace.
void ArchSetProgramNameForErrors(const char *progName)
Sets the program name to be used in diagnostic output.
void ArchSetProcessStateLogCommand(const char *command, const char *const argv[], const char *const fatalArgv[])
Sets command line that gets call-stack info and triggers crash handling script.