1 //===-- ProcessMinidump.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_PROCESSMINIDUMP_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_PROCESSMINIDUMP_H
11 
12 #include "MinidumpParser.h"
13 #include "MinidumpTypes.h"
14 
15 #include "lldb/Target/PostMortemProcess.h"
16 #include "lldb/Target/StopInfo.h"
17 #include "lldb/Target/Target.h"
18 #include "lldb/Utility/ConstString.h"
19 #include "lldb/Utility/Status.h"
20 
21 #include "llvm/Support/Format.h"
22 #include "llvm/Support/raw_ostream.h"
23 
24 
25 namespace lldb_private {
26 
27 namespace minidump {
28 
29 class ProcessMinidump : public PostMortemProcess {
30 public:
31   static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
32                                         lldb::ListenerSP listener_sp,
33                                         const FileSpec *crash_file_path,
34                                         bool can_connect);
35 
36   static void Initialize();
37 
38   static void Terminate();
39 
40   static ConstString GetPluginNameStatic();
41 
42   static const char *GetPluginDescriptionStatic();
43 
44   ProcessMinidump(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
45                   const FileSpec &core_file, lldb::DataBufferSP code_data);
46 
47   ~ProcessMinidump() override;
48 
49   bool CanDebug(lldb::TargetSP target_sp,
50                 bool plugin_specified_by_name) override;
51 
52   CommandObject *GetPluginCommandObject() override;
53 
54   Status DoLoadCore() override;
55 
56   DynamicLoader *GetDynamicLoader() override { return nullptr; }
57 
58   ConstString GetPluginName() override;
59 
60   uint32_t GetPluginVersion() override;
61 
62   SystemRuntime *GetSystemRuntime() override { return nullptr; }
63 
64   Status DoDestroy() override;
65 
66   void RefreshStateAfterStop() override;
67 
68   bool IsAlive() override;
69 
70   bool WarnBeforeDetach() const override;
71 
72   size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
73                     Status &error) override;
74 
75   size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
76                       Status &error) override;
77 
78   ArchSpec GetArchitecture();
79 
80   Status GetMemoryRegionInfo(lldb::addr_t load_addr,
81                              MemoryRegionInfo &range_info) override;
82 
83   Status GetMemoryRegions(
84       lldb_private::MemoryRegionInfos &region_list) override;
85 
86   bool GetProcessInfo(ProcessInstanceInfo &info) override;
87 
88   Status WillResume() override {
89     Status error;
90     error.SetErrorStringWithFormat(
91         "error: %s does not support resuming processes",
92         GetPluginName().GetCString());
93     return error;
94   }
95 
96   llvm::Optional<MinidumpParser> m_minidump_parser;
97 
98 protected:
99   void Clear();
100 
101   bool DoUpdateThreadList(ThreadList &old_thread_list,
102                           ThreadList &new_thread_list) override;
103 
104   void ReadModuleList();
105 
106   lldb::ModuleSP GetOrCreateModule(lldb_private::UUID minidump_uuid,
107                                    llvm::StringRef name,
108                                    lldb_private::ModuleSpec module_spec);
109 
110   JITLoaderList &GetJITLoaders() override;
111 
112 private:
113   FileSpec m_core_file;
114   lldb::DataBufferSP m_core_data;
115   llvm::ArrayRef<minidump::Thread> m_thread_list;
116   const minidump::ExceptionStream *m_active_exception;
117   lldb::CommandObjectSP m_command_sp;
118   bool m_is_wow64;
119   llvm::Optional<MemoryRegionInfos> m_memory_regions;
120 
121   void BuildMemoryRegions();
122 };
123 
124 } // namespace minidump
125 } // namespace lldb_private
126 
127 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MINIDUMP_PROCESSMINIDUMP_H
128