• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef FAULTLOG_DUMP_H
16 #define FAULTLOG_DUMP_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "faultlog_manager.h"
22 
23 namespace OHOS {
24 namespace HiviewDFX {
25 struct DumpRequest {
26     bool requestDetail {false};
27     bool requestList {false};
28     bool compatFlag {false};
29     std::string fileName;
30     std::string moduleName;
31     time_t time {-1};
32 };
33 
34 enum class ParseCmdResult {
35     SUCCESS,
36     UNKNOWN,
37     MAX
38 };
39 
40 class FaultLogDump {
41 public:
FaultLogDump(int fd,const std::shared_ptr<FaultLogManager> & faultLogManager)42     FaultLogDump(int fd, const std::shared_ptr<FaultLogManager>& faultLogManager)
43         : fd_(fd), faultLogManager_(faultLogManager) {}
44     void DumpByCommands(const std::vector<std::string>& cmds) const;
45 private:
46     bool VerifiedDumpPermission() const;
47     void DumpByRequest(const DumpRequest& request) const;
48     ParseCmdResult HandleCommandOption(const std::string& cmd, int32_t &status, DumpRequest& request) const;
49     bool ParseDumpCommands(const std::vector<std::string>& cmds, DumpRequest& request, int32_t& status) const;
50     bool DumpByFileName(const DumpRequest& request) const;
51     void DumpByModule(const DumpRequest& request) const;
52     void PrintFileMaps(const DumpRequest& request, std::map<std::string, std::string> fileNameMap) const;
53     std::map<std::string, std::string> FindByModule(const DumpRequest& request) const;
54 private:
55     int fd_{-1};
56     std::shared_ptr<FaultLogManager> faultLogManager_;
57 };
58 }  // namespace HiviewDFX
59 }  // namespace OHOS
60 #endif
61