1 /*
2  * Copyright (c) 2021-2023 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 DFX_UNWIND_REMOTE_H
16 #define DFX_UNWIND_REMOTE_H
17 
18 #ifdef __clang__
19 #pragma clang diagnostic push
20 #pragma clang diagnostic ignored "-Wextern-c-compat"
21 #endif
22 
23 #include <map>
24 #include <memory>
25 
26 #include "dfx_define.h"
27 #include "dfx_dump_request.h"
28 #include "dfx_process.h"
29 #include "nocopyable.h"
30 #include "unwinder.h"
31 
32 namespace OHOS {
33 namespace HiviewDFX {
34 class DfxUnwindRemote final {
35 public:
36     static DfxUnwindRemote &GetInstance();
37     ~DfxUnwindRemote() = default;
38 
39     bool UnwindProcess(std::shared_ptr<ProcessDumpRequest> request, std::shared_ptr<DfxProcess> process,
40                        std::shared_ptr<Unwinder> unwinder, pid_t vmPid = 0);
41     bool InitProcessAllThreadRegs(std::shared_ptr<ProcessDumpRequest> request, std::shared_ptr<DfxProcess> process);
42 
43 private:
44     DfxUnwindRemote() = default;
45     bool UnwindKeyThread(std::shared_ptr<ProcessDumpRequest> request, std::shared_ptr<DfxProcess> process,
46                                       std::shared_ptr<Unwinder> unwinder, pid_t vmPid = 0);
47     int UnwindOtherThread(std::shared_ptr<DfxProcess> process, std::shared_ptr<Unwinder> unwinder,
48         pid_t vmPid = 0);
49 
50     DISALLOW_COPY_AND_MOVE(DfxUnwindRemote);
51     bool InitTargetKeyThreadRegs(std::shared_ptr<ProcessDumpRequest> request, std::shared_ptr<DfxProcess> process);
52     void InitOtherThreadRegs(std::shared_ptr<DfxProcess> process);
53     bool isVmProcAttach = false;
54 };
55 }   // namespace HiviewDFX
56 }   // namespace OHOS
57 
58 #endif  // DFX_UNWIND_REMOTE_H
59