All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stackTrace.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef ARCH_STACKTRACE_H
25 #define ARCH_STACKTRACE_H
26 
30 
31 #include "pxr/pxr.h"
32 #include "pxr/base/arch/api.h"
33 #include "pxr/base/arch/defines.h"
34 
35 #include <inttypes.h>
36 #include <stdio.h>
37 #include <functional>
38 #include <vector>
39 #include <string>
40 #include <iosfwd>
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
46 
63 ARCH_API
65  const char* reason,
66  const char* message = nullptr,
67  const char* extraLogMsg = nullptr);
68 
87 ARCH_API
88 void ArchSetPostMortem(const char* command, const char *const argv[]);
89 
95 ARCH_API
96 void ArchLogSessionInfo(const char *crashStackTrace=NULL);
97 
119 ARCH_API
120 void ArchSetLogSession(const char* command,
121  const char* const argv[],
122  const char* const crashArgv[]);
123 
128 ARCH_API
130 
132 ARCH_API
133 void ArchPrintStackTrace(FILE *fout,
134  const std::string& programName,
135  const std::string& reason);
136 
140 ARCH_API
141 void ArchPrintStackTrace(FILE *fout, const std::string& reason);
142 
145 ARCH_API
146 void ArchPrintStackTrace(std::ostream& out,
147  const std::string& programName,
148  const std::string& reason);
149 
153 ARCH_API
154 void ArchPrintStackTrace(std::ostream& out, const std::string& reason);
155 
157 typedef std::function<std::string(uintptr_t address)> ArchStackTraceCallback;
158 
164 ARCH_API
166 
169 ARCH_API
171 
174 ARCH_API
175 time_t ArchGetAppLaunchTime();
176 
182 ARCH_API
183 void ArchSetFatalStackLogging(bool flag);
184 
188 ARCH_API
190 
194 ARCH_API
195 void ArchSetProgramNameForErrors(const char * progName);
196 
199 ARCH_API
200 const char * ArchGetProgramNameForErrors();
201 
204 ARCH_API
205 void ArchSetProgramInfoForErrors( const std::string& key, const std::string& value );
206 
209 ARCH_API
210 std::string ArchGetProgramInfoForErrors(const std::string& key);
211 
219 ARCH_API
220 void ArchSetExtraLogInfoForErrors(const std::string &key,
221  std::vector<std::string> const *lines);
222 
233 ARCH_API
234 void ArchLogStackTrace(const std::string& progName,
235  const std::string& reason,
236  bool fatal = false,
237  const std::string& sessionLog = "");
238 
249 ARCH_API
250 void ArchLogStackTrace(const std::string& reason,
251  bool fatal = false,
252  const std::string& sessionLog = "");
253 
258 ARCH_API
259 std::vector<std::string> ArchGetStackTrace(size_t maxDepth);
260 
261 
266 ARCH_API
267 void ArchGetStackFrames(size_t maxDepth, std::vector<uintptr_t> *frames);
268 
275 ARCH_API
276 void ArchGetStackFrames(size_t maxDepth, size_t numFramesToSkipAtTop,
277  std::vector<uintptr_t> *frames);
278 
280 ARCH_API
281 void ArchPrintStackFrames(std::ostream& out,
282  const std::vector<uintptr_t> &frames);
283 
286 typedef void (*ArchCrashHandlerSystemCB)(void* userData);
287 
301 ARCH_API
302 int ArchCrashHandlerSystemv(const char* pathname, char *const argv[],
303  int timeout, ArchCrashHandlerSystemCB callback,
304  void* userData);
305 
313 ARCH_API
314 void ArchTestCrash(bool spawnthread);
315 
316 #if defined(ARCH_OS_DARWIN)
317 // macOS has no ETIME. ECANCELED seems to have about the closest meaning to
318 // the actual error here. The operation is timing out, not being explicitly
319 // canceled, but it is canceled.
320 #ifndef ETIME
321 #define ETIME ECANCELED
322 #endif // end ETIME
323 #endif // end ARCH_OS_DARWIN
324 
326 
327 PXR_NAMESPACE_CLOSE_SCOPE
328 
329 #endif // ARCH_STACKTRACE_H
std::function< std::string(uintptr_t address)> ArchStackTraceCallback
A callback to get a symbolic representation of an address.
Definition: stackTrace.h:157
ARCH_API void ArchLogPostMortem(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 ArchGetStackFrames(size_t maxDepth, std::vector< uintptr_t > *frames)
Save frames of current stack.
ARCH_API int ArchCrashHandlerSystemv(const char *pathname, char *const argv[], int timeout, ArchCrashHandlerSystemCB callback, void *userData)
Replacement for &#39;system&#39; safe for a crash handler.
ARCH_API void ArchSetProgramNameForErrors(const char *progName)
Sets the program name to be used in diagnostic output.
ARCH_API void ArchLogSessionInfo(const char *crashStackTrace=NULL)
Log session info.
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 void ArchSetPostMortem(const char *command, const char *const argv[])
Sets the command line that gathers call-stack info.
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 ArchSetLogSession(const char *command, const char *const argv[], const char *const crashArgv[])
Sets the command line to log sessions.
ARCH_API void ArchGetStackTraceCallback(ArchStackTraceCallback *cb)
Returns the callback to get a symbolic representation of an address.
ARCH_API void ArchSetStackTraceCallback(const ArchStackTraceCallback &cb)
Sets a callback to get a symbolic representation of an address.
ARCH_API const char * ArchGetProgramNameForErrors()
Returns the currently set program name for reporting errors.
ARCH_API bool ArchGetFatalStackLogging()
Returns whether automatic logging of fatal crashes is enabled This is set to false by default...
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.
Define integral types.
void(* ArchCrashHandlerSystemCB)(void *userData)
Callback for handling crashes.
Definition: stackTrace.h:286
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 ArchPrintStackFrames(std::ostream &out, const std::vector< uintptr_t > &frames)
Print stack frames to the given ostream.
ARCH_API time_t ArchGetAppLaunchTime()
Returns the set value for the application&#39;s launch time.
ARCH_API void ArchEnableSessionLogging()
Register the callback to invoke logging at end of a successful session.
ARCH_API std::string ArchGetProgramInfoForErrors(const std::string &key)
Returns currently set program info.
ARCH_API void ArchSetFatalStackLogging(bool flag)
Enables or disables the automatic logging of crash information.