1 /** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef PANDA_STACKTRACE_H_ 16 #define PANDA_STACKTRACE_H_ 17 18 #include <vector> 19 #include <iostream> 20 21 namespace panda { 22 23 class StackPrinterImpl; 24 25 /* 26 * Return stack trace as a vector of PCs 27 * 28 * Use std::vector instead of PandaVector due to have ability 29 * to print stack traces in internal allocator. 30 * Since PandaVector uses internal allocator it leads to 31 * infinite recursion. 32 */ 33 std::vector<uintptr_t> GetStacktrace(); 34 35 /* 36 * Print stack trace provided into 'Print' function. 37 * The class caches information. So it is aimed to be used 38 * to print multiple stack traces. 39 */ 40 std::ostream &PrintStack(const std::vector<uintptr_t> &stacktrace, std::ostream &out); 41 42 /* 43 * Print stack trace 44 */ 45 // NOLINTNEXTLINE(misc-definitions-in-headers) PrintStack(std::ostream & out)46inline std::ostream &PrintStack(std::ostream &out) 47 { 48 return PrintStack(GetStacktrace(), out); 49 } 50 51 } // namespace panda 52 #endif // PANDA_STACKTRACE_H_ 53