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 16 #ifndef DFX_PROCESSDUMP_H 17 #define DFX_PROCESSDUMP_H 18 19 #include <cinttypes> 20 #include <condition_variable> 21 #include <memory> 22 #include <mutex> 23 #include <string> 24 #include <thread> 25 26 #include "cppcrash_reporter.h" 27 #include "dfx_dump_request.h" 28 #include "dfx_process.h" 29 #include "nocopyable.h" 30 #if !defined(__x86_64__) 31 #include "unwinder.h" 32 #endif 33 34 namespace OHOS { 35 namespace HiviewDFX { 36 class ProcessDumper final { 37 public: 38 static ProcessDumper &GetInstance(); 39 ~ProcessDumper() = default; 40 41 void Dump(); 42 void WriteDumpRes(int32_t res); 43 bool IsCrash() const; 44 45 private: 46 ProcessDumper() = default; 47 DISALLOW_COPY_AND_MOVE(ProcessDumper); 48 static int WriteDumpBuf(int fd, const char* buf, const int len); 49 int DumpProcess(std::shared_ptr<ProcessDumpRequest> request); 50 int InitPrintThread(std::shared_ptr<ProcessDumpRequest> request); 51 int InitProcessInfo(std::shared_ptr<ProcessDumpRequest> request); 52 static int GetLogTypeBySignal(int sig); 53 54 private: 55 std::shared_ptr<DfxProcess> process_ = nullptr; 56 std::shared_ptr<CppCrashReporter> reporter_ = nullptr; 57 #if !defined(__x86_64__) 58 std::shared_ptr<Unwinder> unwinder_ = nullptr; 59 #endif 60 bool isCrash_ = false; 61 bool isJsonDump_ = false; 62 int32_t resFd_ = -1; 63 int32_t jsonFd_ = -1; 64 int32_t resDump_ = 0; 65 }; 66 } // namespace HiviewDFX 67 } // namespace OHOS 68 69 #endif // DFX_PROCESSDUMP_H 70