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 26namespace OHOS { 27namespace HiviewDFX { 28constexpr int32_t BACKTRACE_CURRENT_THREAD = -1; 29 30class BacktraceLocalThread { 31public: 32 explicit BacktraceLocalThread(int32_t tid, std::shared_ptr<Unwinder> unwinder); 33 ~BacktraceLocalThread(); 34 35 bool Unwind(bool fast = false, size_t maxFrameNum = DEFAULT_MAX_FRAME_NUM, size_t skipFrameNum = 0); 36 37 const std::vector<DfxFrame>& GetFrames() const; 38 void SetFrames(const std::vector<DfxFrame>& frames); 39 std::string GetFormattedStr(bool withThreadName = false); 40 41private: 42 int32_t tid_; 43 std::vector<DfxFrame> frames_; 44 std::shared_ptr<Unwinder> unwinder_; 45}; 46} // namespace HiviewDFX 47} // namespace OHOS 48#endif // UNWIND_LOCAL_THREAD_H 49