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_PROCESS_H 17 #define DFX_PROCESS_H 18 19 #include <cinttypes> 20 #include <map> 21 #include <memory> 22 #include <string> 23 24 #if defined(__x86_64__) 25 #include "dfx_maps.h" 26 #endif 27 #include "dfx_thread.h" 28 29 namespace OHOS { 30 namespace HiviewDFX { 31 struct DfxProcessInfo { 32 pid_t pid = 0; 33 pid_t nsPid = 0; 34 uid_t uid = 0; 35 std::string processName = ""; 36 }; 37 38 class DfxProcess { 39 public: 40 static std::shared_ptr<DfxProcess> Create(pid_t pid, pid_t nsPid); 41 DfxProcess(pid_t pid, pid_t nsPid); 42 virtual ~DfxProcess() = default; 43 void Attach(bool hasKey = false); 44 void Detach(); 45 46 bool InitOtherThreads(bool attach = false); 47 std::vector<std::shared_ptr<DfxThread>> GetOtherThreads() const; 48 void ClearOtherThreads(); 49 pid_t ChangeTid(pid_t tid, bool ns); 50 51 void SetFatalMessage(const std::string &msg); 52 std::string GetFatalMessage() const; 53 #if defined(__x86_64__) 54 void InitProcessMaps(); 55 void SetMaps(std::shared_ptr<DfxElfMaps> maps); 56 std::shared_ptr<DfxElfMaps> GetMaps() const; 57 #endif 58 59 DfxProcessInfo processInfo_; 60 pid_t recycleTid_ = 0; 61 std::shared_ptr<DfxThread> keyThread_ = nullptr; // comment: crash thread or dump target thread 62 std::shared_ptr<DfxThread> vmThread_ = nullptr; // comment: vm thread object in crash secnario 63 std::string reason = ""; 64 private: 65 DfxProcess() = default; 66 void InitProcessInfo(pid_t pid, pid_t nsPid); 67 68 std::string fatalMsg_ = ""; 69 #if defined(__x86_64__) 70 std::shared_ptr<DfxElfMaps> maps_; 71 #endif 72 std::vector<std::shared_ptr<DfxThread>> otherThreads_; 73 std::map<int, int> kvThreads_; 74 }; 75 } // namespace HiviewDFX 76 } // namespace OHOS 77 #endif 78