Pixar Arch
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 "./api.h"
15#include "./defines.h"
16
17#include <inttypes.h>
18#include <stdio.h>
19#include <functional>
20#include <vector>
21#include <string>
22#include <iosfwd>
23#include <ctime>
24
25namespace pxr {
26
46ARCH_API
47void ArchLogFatalProcessState(const char* reason,
48 const char* message = nullptr,
49 const char* extraLogMsg = nullptr);
50
67ARCH_API
68void ArchLogCurrentProcessState(const char* reason,
69 const char* message = nullptr,
70 const char* extraLogMsg = nullptr);
71
93ARCH_API
94void ArchSetProcessStateLogCommand(const char* command,
95 const char *const argv[],
96 const char* const fatalArgv[]);
97
100ARCH_API
102
108ARCH_API
109void ArchLogSessionInfo(const char *crashStackTrace=NULL);
110
132ARCH_API
133void ArchSetLogSession(const char* command,
134 const char* const argv[],
135 const char* const crashArgv[]);
136
141ARCH_API
143
145ARCH_API
146void ArchPrintStackTrace(FILE *fout,
147 const std::string& programName,
148 const std::string& reason);
149
153ARCH_API
154void ArchPrintStackTrace(FILE *fout, const std::string& reason);
155
158ARCH_API
159void ArchPrintStackTrace(std::ostream& out,
160 const std::string& programName,
161 const std::string& reason);
162
166ARCH_API
167void ArchPrintStackTrace(std::ostream& out, const std::string& reason);
168
170typedef std::function<std::string(uintptr_t address)> ArchStackTraceCallback;
171
177ARCH_API
179
182ARCH_API
184
187ARCH_API
189
195ARCH_API
197
201ARCH_API
203
207ARCH_API
208void ArchSetProgramNameForErrors(const char * progName);
209
212ARCH_API
214
217ARCH_API
218void ArchSetProgramInfoForErrors( const std::string& key, const std::string& value );
219
222ARCH_API
223std::string ArchGetProgramInfoForErrors(const std::string& key);
224
232ARCH_API
233void ArchSetExtraLogInfoForErrors(const std::string &key,
234 std::vector<std::string> const *lines);
235
246ARCH_API
247void ArchLogStackTrace(const std::string& progName,
248 const std::string& reason,
249 bool fatal = false,
250 const std::string& sessionLog = "");
251
262ARCH_API
263void ArchLogStackTrace(const std::string& reason,
264 bool fatal = false,
265 const std::string& sessionLog = "");
266
271ARCH_API
272std::vector<std::string> ArchGetStackTrace(size_t maxDepth);
273
274
279ARCH_API
280void ArchGetStackFrames(size_t maxDepth, std::vector<uintptr_t> *frames);
281
284ARCH_API
285size_t ArchGetStackFrames(size_t maxDepth, uintptr_t *frames);
286
293ARCH_API
294void ArchGetStackFrames(size_t maxDepth, size_t numFramesToSkipAtTop,
295 std::vector<uintptr_t> *frames);
296
300ARCH_API
301size_t ArchGetStackFrames(size_t maxDepth, size_t numFramesToSkipAtTop,
302 uintptr_t *frames);
303
304
306ARCH_API
307void ArchPrintStackFrames(std::ostream& out,
308 const std::vector<uintptr_t> &frames,
309 bool skipUnknownFrames = false);
310
313typedef void (*ArchCrashHandlerSystemCB)(void* userData);
314
328ARCH_API
329int ArchCrashHandlerSystemv(const char* pathname, char *const argv[],
330 int timeout, ArchCrashHandlerSystemCB callback,
331 void* userData);
332
333#if defined(ARCH_OS_DARWIN)
334// macOS has no ETIME. ECANCELED seems to have about the closest meaning to
335// the actual error here. The operation is timing out, not being explicitly
336// canceled, but it is canceled.
337#ifndef ETIME
338#define ETIME ECANCELED
339#endif // end ETIME
340#endif // end ARCH_OS_DARWIN
341
342} // namespace pxr
343
344#endif // PXR_ARCH_STACK_TRACE_H
Define integral types.
ARCH_API void ArchPrintStackTrace(FILE *fout, const std::string &programName, const std::string &reason)
Print a stack trace to the given FILE pointer.
ARCH_API bool ArchGetFatalStackLogging()
Returns whether automatic logging of fatal crashes is enabled This is set to false by default.
ARCH_API void ArchGetStackTraceCallback(ArchStackTraceCallback *cb)
Returns the callback to get a symbolic representation of an address.
ARCH_API std::string ArchGetProgramInfoForErrors(const std::string &key)
Returns currently set program info.
ARCH_API 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.
ARCH_API 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.
ARCH_API void ArchSetFatalStackLogging(bool flag)
Enables or disables the automatic logging of crash information.
ARCH_API const char * ArchGetProgramNameForErrors()
Returns the currently set program name for reporting errors.
ARCH_API void ArchSetStackTraceCallback(const ArchStackTraceCallback &cb)
Sets a callback to get a symbolic representation of an address.
ARCH_API 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.
ARCH_API 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(* ArchCrashHandlerSystemCB)(void *userData)
Callback for handling crashes.
Definition stackTrace.h:313
ARCH_API void ArchSetLogSession(const char *command, const char *const argv[], const char *const crashArgv[])
Sets the command line to log sessions.
std::function< std::string(uintptr_t address)> ArchStackTraceCallback
A callback to get a symbolic representation of an address.
Definition stackTrace.h:170
ARCH_API void ArchSetProgramNameForErrors(const char *progName)
Sets the program name to be used in diagnostic output.
ARCH_API bool ArchIsAppCrashing()
Returns true if the fatal signal handler ArchLogFatalProcessState has been invoked.
ARCH_API void ArchPrintStackFrames(std::ostream &out, const std::vector< uintptr_t > &frames, bool skipUnknownFrames=false)
Print stack frames to the given ostream.
ARCH_API time_t ArchGetAppLaunchTime()
Returns the set value for the application's launch time.
ARCH_API 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.
ARCH_API 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...
ARCH_API std::vector< std::string > ArchGetStackTrace(size_t maxDepth)
Return stack trace.
ARCH_API void ArchGetStackFrames(size_t maxDepth, std::vector< uintptr_t > *frames)
Save frames of current stack.
ARCH_API void ArchEnableSessionLogging()
Register the callback to invoke logging at end of a successful session.
ARCH_API void ArchLogSessionInfo(const char *crashStackTrace=NULL)
Log session info.
ARCH_API int ArchCrashHandlerSystemv(const char *pathname, char *const argv[], int timeout, ArchCrashHandlerSystemCB callback, void *userData)
Replacement for 'system' safe for a crash handler.