• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 /* This files contains process dump hrader. */
17 
18 #ifndef DFX_PROCESSDUMP_H
19 #define DFX_PROCESSDUMP_H
20 
21 #include <cinttypes>
22 #include <condition_variable>
23 #include <memory>
24 #include <mutex>
25 #include <string>
26 #include <thread>
27 #include "cppcrash_reporter.h"
28 #include "dfx_dump_request.h"
29 #include "dfx_process.h"
30 #include "nocopyable.h"
31 
32 namespace OHOS {
33 namespace HiviewDFX {
34 class ProcessDumper final {
35 public:
36     static ProcessDumper &GetInstance();
37     ~ProcessDumper() = default;
38 
39     void Dump();
40     void WriteDumpRes(int32_t res);
41     int32_t GetTargetPid();
42     int32_t GetTargetNsPid();
43 private:
44     static int WriteDumpBuf(int fd, const char* buf, const int len);
45     int DumpProcessWithSignalContext(std::shared_ptr<ProcessDumpRequest> request);
46     int InitPrintThread(bool fromSignalHandler, std::shared_ptr<ProcessDumpRequest> request);
47     void PrintDumpProcessWithSignalContextHeader(std::shared_ptr<ProcessDumpRequest> request);
48     void CreateVmProcessIfNeed(std::shared_ptr<ProcessDumpRequest> request, bool enableNs);
49     bool InitProcessNsInfo(std::shared_ptr<ProcessDumpRequest> request, bool isCrash);
50     int InitProcessInfo(std::shared_ptr<ProcessDumpRequest> request, bool isCrash, bool enableNs);
51 
52     ProcessDumper() = default;
53     DISALLOW_COPY_AND_MOVE(ProcessDumper);
54 
55     std::shared_ptr<DfxProcess> vmProcess_ = nullptr;
56     std::shared_ptr<DfxProcess> targetProcess_ = nullptr;
57     std::shared_ptr<CppCrashReporter> reporter_ = nullptr;
58     int32_t resFd_ = -1;
59     int32_t resDump_ = 0;
60     int32_t targetPid_ = -1;
61     int32_t targetNsPid_ = -1;
62     int32_t targetVmPid_ = -1;
63     int32_t targetVmNsPid_ = -1;
64 };
65 } // namespace HiviewDFX
66 } // namespace OHOS
67 
68 #endif  // DFX_PROCESSDUMP_H
69