• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 HIVIEW_PLUGINS_CRASH_VALIDATOR_H
17 #define HIVIEW_PLUGINS_CRASH_VALIDATOR_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 
23 #include "event.h"
24 #include "plugin.h"
25 #include "sys_event.h"
26 
27 namespace OHOS {
28 namespace HiviewDFX {
29 class CrashValidator : public Plugin {
30 public:
31     CrashValidator();
32     ~CrashValidator();
33     void OnLoad() override;
34     void OnUnload() override;
35     bool OnEvent(std::shared_ptr<Event>& event) override;
36     bool IsInterestedPipelineEvent(std::shared_ptr<Event> event) override;
37 private:
38     void InitWorkLoop();
39     bool MatchEvent(int32_t pid);
40     bool MatchKernelSnapshotEvent(int32_t pid);
41     void RemoveMatchEvent(int32_t pid);
42     void AddEventToMap(int32_t pid, std::shared_ptr<SysEvent> sysEvent);
43     void ReportMatchEvent(std::string eventName, std::shared_ptr<SysEvent> sysEvent);
44     void ReportDisMatchEvent(std::shared_ptr<SysEvent> sysEvent);
45 
46     std::shared_ptr<SysEvent> Convert2SysEvent(std::shared_ptr<Event>& event);
47     std::atomic<bool> hasLoaded_;
48     std::mutex mutex_;
49     std::map<int32_t, std::shared_ptr<SysEvent>> processExitEvents_;
50     std::map<int32_t, std::shared_ptr<SysEvent>> cppCrashEvents_;
51     std::map<int32_t, std::shared_ptr<SysEvent>> cppCrashExceptionEvents_;
52 };
53 } // namespace HiviewDFX
54 } // namespace OHOS
55 
56 #endif