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 sdk dump catcher module. */ 17 18 #ifndef DFX_DUMPCATCH_H 19 #define DFX_DUMPCATCH_H 20 21 #include <cinttypes> 22 #include <cstring> 23 #include <mutex> 24 #include <string> 25 #include <unistd.h> 26 #include <vector> 27 #include "dfx_define.h" 28 #include "dfx_frame.h" 29 30 namespace OHOS { 31 namespace HiviewDFX { 32 enum DfxDumpType : int32_t { 33 DUMP_TYPE_NATIVE = -1, 34 DUMP_TYPE_MIX = -2, 35 DUMP_TYPE_KERNEL = -3, 36 }; 37 38 class DfxDumpCatcher { 39 public: 40 DfxDumpCatcher(); 41 explicit DfxDumpCatcher(int32_t pid); 42 ~DfxDumpCatcher(); 43 44 bool DumpCatch(int pid, int tid, std::string& msg); 45 bool DumpCatchMix(int pid, int tid, std::string& msg); 46 bool DumpCatchFd(int pid, int tid, std::string& msg, int fd); 47 bool DumpCatchMultiPid(const std::vector<int> pidV, std::string& msg); 48 49 bool InitFrameCatcher(); 50 bool RequestCatchFrame(int tid); 51 bool CatchFrame(int tid, std::vector<std::shared_ptr<DfxFrame>>& frames); 52 void DestroyFrameCatcher(); 53 54 private: 55 bool DoDumpCurrTid(const size_t skipFramNum, std::string& msg); 56 bool DoDumpLocalTid(const int tid, std::string& msg); 57 bool DoDumpLocalPid(int pid, std::string& msg); 58 bool DoDumpLocalLocked(int pid, int tid, std::string& msg); 59 bool DoDumpRemoteLocked(int pid, int tid, std::string& msg); 60 bool DoDumpCatchRemote(const int type, int pid, int tid, std::string& msg); 61 int DoDumpRemotePid(const int type, int pid, std::string& msg); 62 int DoDumpRemotePoll(int bufFd, int resFd, int timeout, std::string& msg); 63 bool DoReadBuf(int fd, std::string& msg); 64 bool DoReadRes(int fd, bool &ret, std::string& msg); 65 66 private: 67 std::mutex dumpCatcherMutex_; 68 int32_t frameCatcherPid_; 69 struct ProcInfo procInfo_; 70 }; 71 } // namespace HiviewDFX 72 } // namespace OHOS 73 74 #endif 75