1 /* 2 * Copyright (c) 2022-2024 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 16 #ifndef UNWIND_LOCAL_THREAD_H 17 #define UNWIND_LOCAL_THREAD_H 18 19 #include <cinttypes> 20 #include <memory> 21 #include <vector> 22 23 #include "dfx_frame.h" 24 #include "unwinder.h" 25 #include "proc_util.h" 26 27 namespace OHOS { 28 namespace HiviewDFX { 29 constexpr int32_t BACKTRACE_CURRENT_THREAD = -1; 30 31 std::string GetThreadHead(int32_t tid); 32 33 class BacktraceLocalThread { 34 public: 35 explicit BacktraceLocalThread(int32_t tid, bool includeThreadInfo = false) tid_(tid)36 : tid_(tid), includeThreadInfo_(includeThreadInfo) {} 37 bool Unwind(Unwinder& unwinder, bool fast = false, 38 size_t maxFrameNum = DEFAULT_MAX_FRAME_NUM, size_t skipFrameNum = 0); 39 bool UnwindOtherThreadMix(Unwinder& unwinder, bool fast, 40 size_t maxFrameNum = DEFAULT_MAX_FRAME_NUM, size_t skipFrameNum = 0); 41 42 const std::vector<DfxFrame>& GetFrames() const; 43 void SetFrames(const std::vector<DfxFrame>& frames); 44 std::string GetFormattedStr(bool withThreadName = false); 45 46 private: 47 int32_t tid_; 48 std::vector<DfxFrame> frames_{}; 49 bool includeThreadInfo_; 50 }; 51 } // namespace HiviewDFX 52 } // namespace OHOS 53 #endif // UNWIND_LOCAL_THREAD_H 54