1 //===-- ProcessMachCore.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_ProcessMachCore_h_
11 #define liblldb_ProcessMachCore_h_
12 
13 // C Includes
14 
15 // C++ Includes
16 #include <list>
17 #include <vector>
18 
19 // Other libraries and framework includes
20 #include "lldb/Core/ConstString.h"
21 #include "lldb/Core/Error.h"
22 #include "lldb/Target/Process.h"
23 
24 class ThreadKDP;
25 
26 class ProcessMachCore : public lldb_private::Process
27 {
28 public:
29     //------------------------------------------------------------------
30     // Constructors and Destructors
31     //------------------------------------------------------------------
32     static lldb::ProcessSP
33     CreateInstance (lldb_private::Target& target,
34                     lldb_private::Listener &listener,
35                     const lldb_private::FileSpec *crash_file_path);
36 
37     static void
38     Initialize();
39 
40     static void
41     Terminate();
42 
43     static lldb_private::ConstString
44     GetPluginNameStatic();
45 
46     static const char *
47     GetPluginDescriptionStatic();
48 
49     //------------------------------------------------------------------
50     // Constructors and Destructors
51     //------------------------------------------------------------------
52     ProcessMachCore(lldb_private::Target& target,
53                     lldb_private::Listener &listener,
54                     const lldb_private::FileSpec &core_file);
55 
56     virtual
57     ~ProcessMachCore();
58 
59     //------------------------------------------------------------------
60     // Check if a given Process
61     //------------------------------------------------------------------
62     virtual bool
63     CanDebug (lldb_private::Target &target,
64               bool plugin_specified_by_name);
65 
66     //------------------------------------------------------------------
67     // Creating a new process, or attaching to an existing one
68     //------------------------------------------------------------------
69     virtual lldb_private::Error
70     DoLoadCore ();
71 
72     virtual lldb_private::DynamicLoader *
73     GetDynamicLoader ();
74 
75     //------------------------------------------------------------------
76     // PluginInterface protocol
77     //------------------------------------------------------------------
78     virtual lldb_private::ConstString
79     GetPluginName();
80 
81     virtual uint32_t
82     GetPluginVersion();
83 
84     //------------------------------------------------------------------
85     // Process Control
86     //------------------------------------------------------------------
87     virtual lldb_private::Error
88     DoDestroy ();
89 
90     virtual void
91     RefreshStateAfterStop();
92 
93     //------------------------------------------------------------------
94     // Process Queries
95     //------------------------------------------------------------------
96     virtual bool
97     IsAlive ();
98 
99     virtual bool
100     WarnBeforeDetach () const;
101 
102     //------------------------------------------------------------------
103     // Process Memory
104     //------------------------------------------------------------------
105     virtual size_t
106     ReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
107 
108     virtual size_t
109     DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
110 
111     virtual lldb::addr_t
112     GetImageInfoAddress ();
113 
114 protected:
115     friend class ThreadMachCore;
116 
117     void
118     Clear ( );
119 
120     virtual bool
121     UpdateThreadList (lldb_private::ThreadList &old_thread_list,
122                       lldb_private::ThreadList &new_thread_list);
123 
124     lldb_private::ObjectFile *
125     GetCoreObjectFile ();
126 private:
127     bool
128     GetDynamicLoaderAddress (lldb::addr_t addr);
129 
130     typedef enum CorefilePreference { eUserProcessCorefile, eKernelCorefile } CorefilePreferences;
131 
132     //------------------------------------------------------------------
133     /// If a core file can be interpreted multiple ways, this establishes
134     /// which style wins.
135     ///
136     /// If a core file contains both a kernel binary and a user-process
137     /// dynamic loader, lldb needs to pick one over the other.  This could
138     /// be a kernel corefile that happens to have a coyp of dyld in its
139     /// memory.  Or it could be a user process coredump of lldb while doing
140     /// kernel debugging - so a copy of the kernel is in its heap.  This
141     /// should become a setting so it can be over-ridden when necessary.
142     //------------------------------------------------------------------
143     CorefilePreference
144     GetCorefilePreference ()
145     {
146         // For now, if both user process and kernel binaries a present,
147         // assume this is a kernel coredump which has a copy of a user
148         // process dyld in one of its pages.
149         return eKernelCorefile;
150     }
151 
152     //------------------------------------------------------------------
153     // For ProcessMachCore only
154     //------------------------------------------------------------------
155     typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange;
156     typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, FileRange> VMRangeToFileOffset;
157 
158     VMRangeToFileOffset m_core_aranges;
159     lldb::ModuleSP m_core_module_sp;
160     lldb_private::FileSpec m_core_file;
161     lldb::addr_t m_dyld_addr;
162     lldb::addr_t m_mach_kernel_addr;
163     lldb_private::ConstString m_dyld_plugin_name;
164     DISALLOW_COPY_AND_ASSIGN (ProcessMachCore);
165 
166 };
167 
168 #endif  // liblldb_ProcessMachCore_h_
169