1 /*
2  * Copyright (c) 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 DFX_UNWIND_ASYNC_THREAD_H
17 #define DFX_UNWIND_ASYNC_THREAD_H
18 
19 #include <cinttypes>
20 #include <csignal>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include "dfx_thread.h"
25 #include "unwinder.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 class DfxUnwindAsyncThread {
30 public:
DfxUnwindAsyncThread(std::shared_ptr<DfxThread> thread,std::shared_ptr<Unwinder> unwinder,uint64_t stackId)31     DfxUnwindAsyncThread(std::shared_ptr<DfxThread> thread, std::shared_ptr<Unwinder> unwinder, uint64_t stackId)
32         : thread_(thread), unwinder_(unwinder), stackId_(stackId) {}
33     bool UnwindStack(pid_t vmPid = 0);
34     std::string tip = "";
35 private:
36     void GetSubmitterStack(std::vector<DfxFrame> &submitterFrames);
37     void UnwindThreadFallback();
38     void UnwindThreadByParseStackIfNeed();
39     void MergeStack(std::vector<DfxFrame> &submitterFrames);
40     std::shared_ptr<DfxThread> thread_ = nullptr;
41     std::shared_ptr<Unwinder> unwinder_ = nullptr;
42     uint64_t stackId_ = 0;
43 };
44 }
45 }
46 #endif