1 /* 2 * Copyright (c) 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_STACK_INFO_FORMATTER_H 17 #define DFX_STACK_INFO_FORMATTER_H 18 19 #include <cinttypes> 20 #include <csignal> 21 #include <map> 22 #include <memory> 23 #include <string> 24 25 #include "dfx_dump_request.h" 26 #include "dfx_process.h" 27 #ifndef is_ohos_lite 28 #include "json/json.h" 29 #endif 30 31 namespace OHOS { 32 namespace HiviewDFX { 33 34 class DfxStackInfoFormatter { 35 public: DfxStackInfoFormatter(std::shared_ptr<DfxProcess> process,std::shared_ptr<ProcessDumpRequest> request)36 DfxStackInfoFormatter(std::shared_ptr<DfxProcess> process, std::shared_ptr<ProcessDumpRequest> request) 37 : process_(process), request_(request) {}; ~DfxStackInfoFormatter()38 virtual ~DfxStackInfoFormatter() {}; 39 bool GetStackInfo(bool isJsonDump, std::string& jsonStringInfo) const; 40 41 private: 42 DfxStackInfoFormatter() = delete; 43 #ifndef is_ohos_lite 44 bool GetStackInfo(bool isJsonDump, Json::Value& jsonInfo) const; 45 void GetNativeCrashInfo(Json::Value& jsonInfo) const; 46 void GetDumpInfo(Json::Value& jsonInfo) const; 47 bool FillFrames(const std::shared_ptr<DfxThread>& thread, Json::Value& jsonInfo) const; 48 void FillNativeFrame(const DfxFrame& frame, Json::Value& jsonInfo) const; 49 void AppendThreads(const std::vector<std::shared_ptr<DfxThread>>& threads, Json::Value& jsonInfo) const; 50 #endif 51 52 private: 53 std::shared_ptr<DfxProcess> process_ = nullptr; 54 std::shared_ptr<ProcessDumpRequest> request_ = nullptr; 55 }; 56 } // namespace HiviewDFX 57 } // namespace OHOS 58 #endif 59