• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DfxStackInfoJsonFormatter {
35 public:
DfxStackInfoJsonFormatter(std::shared_ptr<DfxProcess> process,std::shared_ptr<ProcessDumpRequest> request)36     DfxStackInfoJsonFormatter(std::shared_ptr<DfxProcess> process, std::shared_ptr<ProcessDumpRequest> request)
37         : process_(process), request_(request) {};
~DfxStackInfoJsonFormatter()38     virtual ~DfxStackInfoJsonFormatter() {};
39     bool GetJsonFormatInfo(bool isDump, std::string& jsonStringInfo) const;
40 
41 private:
42     DfxStackInfoJsonFormatter() = delete;
43 #ifndef is_ohos_lite
44     void GetCrashJsonFormatInfo(Json::Value& jsonInfo) const;
45     void GetDumpJsonFormatInfo(Json::Value& jsonInfo) const;
46     bool FillFrames(const std::shared_ptr<DfxThread>& thread, Json::Value& jsonInfo) const;
47     void FillNativeFrame(const DfxFrame& frame, Json::Value& jsonInfo) const;
48     void AppendThreads(const std::vector<std::shared_ptr<DfxThread>>& threads, Json::Value& jsonInfo) const;
49 #endif
50 
51 private:
52     std::shared_ptr<DfxProcess> process_ = nullptr;
53     std::shared_ptr<ProcessDumpRequest> request_ = nullptr;
54 };
55 } // namespace HiviewDFX
56 } // namespace OHOS
57 #endif
58