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