1*9356374aSAndroid Build Coastguard Worker // 2*9356374aSAndroid Build Coastguard Worker // Copyright 2018 The Abseil Authors. 3*9356374aSAndroid Build Coastguard Worker // 4*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); 5*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License. 6*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at 7*9356374aSAndroid Build Coastguard Worker // 8*9356374aSAndroid Build Coastguard Worker // https://www.apache.org/licenses/LICENSE-2.0 9*9356374aSAndroid Build Coastguard Worker // 10*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software 11*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, 12*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and 14*9356374aSAndroid Build Coastguard Worker // limitations under the License. 15*9356374aSAndroid Build Coastguard Worker // 16*9356374aSAndroid Build Coastguard Worker 17*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_DEBUGGING_INTERNAL_EXAMINE_STACK_H_ 18*9356374aSAndroid Build Coastguard Worker #define ABSL_DEBUGGING_INTERNAL_EXAMINE_STACK_H_ 19*9356374aSAndroid Build Coastguard Worker 20*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h" 21*9356374aSAndroid Build Coastguard Worker 22*9356374aSAndroid Build Coastguard Worker namespace absl { 23*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN 24*9356374aSAndroid Build Coastguard Worker namespace debugging_internal { 25*9356374aSAndroid Build Coastguard Worker 26*9356374aSAndroid Build Coastguard Worker // Type of function used for printing in stack trace dumping, etc. 27*9356374aSAndroid Build Coastguard Worker // We avoid closures to keep things simple. 28*9356374aSAndroid Build Coastguard Worker typedef void OutputWriter(const char*, void*); 29*9356374aSAndroid Build Coastguard Worker 30*9356374aSAndroid Build Coastguard Worker // RegisterDebugStackTraceHook() allows to register a single routine 31*9356374aSAndroid Build Coastguard Worker // `hook` that is called each time DumpStackTrace() is called. 32*9356374aSAndroid Build Coastguard Worker // `hook` may be called from a signal handler. 33*9356374aSAndroid Build Coastguard Worker typedef void (*SymbolizeUrlEmitter)(void* const stack[], int depth, 34*9356374aSAndroid Build Coastguard Worker OutputWriter* writer, void* writer_arg); 35*9356374aSAndroid Build Coastguard Worker 36*9356374aSAndroid Build Coastguard Worker // Registration of SymbolizeUrlEmitter for use inside of a signal handler. 37*9356374aSAndroid Build Coastguard Worker // This is inherently unsafe and must be signal safe code. 38*9356374aSAndroid Build Coastguard Worker void RegisterDebugStackTraceHook(SymbolizeUrlEmitter hook); 39*9356374aSAndroid Build Coastguard Worker SymbolizeUrlEmitter GetDebugStackTraceHook(); 40*9356374aSAndroid Build Coastguard Worker 41*9356374aSAndroid Build Coastguard Worker // Returns the program counter from signal context, or nullptr if 42*9356374aSAndroid Build Coastguard Worker // unknown. `vuc` is a ucontext_t*. We use void* to avoid the use of 43*9356374aSAndroid Build Coastguard Worker // ucontext_t on non-POSIX systems. 44*9356374aSAndroid Build Coastguard Worker void* GetProgramCounter(void* const vuc); 45*9356374aSAndroid Build Coastguard Worker 46*9356374aSAndroid Build Coastguard Worker // Uses `writer` to dump the program counter, stack trace, and stack 47*9356374aSAndroid Build Coastguard Worker // frame sizes. 48*9356374aSAndroid Build Coastguard Worker void DumpPCAndFrameSizesAndStackTrace(void* const pc, void* const stack[], 49*9356374aSAndroid Build Coastguard Worker int frame_sizes[], int depth, 50*9356374aSAndroid Build Coastguard Worker int min_dropped_frames, 51*9356374aSAndroid Build Coastguard Worker bool symbolize_stacktrace, 52*9356374aSAndroid Build Coastguard Worker OutputWriter* writer, void* writer_arg); 53*9356374aSAndroid Build Coastguard Worker 54*9356374aSAndroid Build Coastguard Worker // Dump current stack trace omitting the topmost `min_dropped_frames` stack 55*9356374aSAndroid Build Coastguard Worker // frames. 56*9356374aSAndroid Build Coastguard Worker void DumpStackTrace(int min_dropped_frames, int max_num_frames, 57*9356374aSAndroid Build Coastguard Worker bool symbolize_stacktrace, OutputWriter* writer, 58*9356374aSAndroid Build Coastguard Worker void* writer_arg); 59*9356374aSAndroid Build Coastguard Worker 60*9356374aSAndroid Build Coastguard Worker } // namespace debugging_internal 61*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END 62*9356374aSAndroid Build Coastguard Worker } // namespace absl 63*9356374aSAndroid Build Coastguard Worker 64*9356374aSAndroid Build Coastguard Worker #endif // ABSL_DEBUGGING_INTERNAL_EXAMINE_STACK_H_ 65