Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / Process / mach-core / ProcessMachCore.h
blobc8820209e3f38306387f0c626be392d7b05ca5de
1 //===-- ProcessMachCore.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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_MACH_CORE_PROCESSMACHCORE_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_MACH_CORE_PROCESSMACHCORE_H
12 #include <list>
13 #include <vector>
15 #include "lldb/Target/PostMortemProcess.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/Utility/Status.h"
19 class ThreadKDP;
21 class ProcessMachCore : public lldb_private::PostMortemProcess {
22 public:
23 // Constructors and Destructors
24 ProcessMachCore(lldb::TargetSP target_sp, lldb::ListenerSP listener,
25 const lldb_private::FileSpec &core_file);
27 ~ProcessMachCore() override;
29 static lldb::ProcessSP
30 CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener,
31 const lldb_private::FileSpec *crash_file_path,
32 bool can_connect);
34 static void Initialize();
36 static void Terminate();
38 static llvm::StringRef GetPluginNameStatic() { return "mach-o-core"; }
40 static llvm::StringRef GetPluginDescriptionStatic();
42 // Check if a given Process
43 bool CanDebug(lldb::TargetSP target_sp,
44 bool plugin_specified_by_name) override;
46 // Creating a new process, or attaching to an existing one
47 lldb_private::Status DoLoadCore() override;
49 lldb_private::DynamicLoader *GetDynamicLoader() override;
51 // PluginInterface protocol
52 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
54 // Process Control
55 lldb_private::Status DoDestroy() override;
57 void RefreshStateAfterStop() override;
59 // Process Queries
60 bool IsAlive() override;
62 bool WarnBeforeDetach() const override;
64 // Process Memory
65 size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size,
66 lldb_private::Status &error) override;
68 size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
69 lldb_private::Status &error) override;
71 lldb::addr_t GetImageInfoAddress() override;
73 protected:
74 friend class ThreadMachCore;
76 void Clear();
78 bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list,
79 lldb_private::ThreadList &new_thread_list) override;
81 lldb_private::ObjectFile *GetCoreObjectFile();
83 lldb_private::Status
84 DoGetMemoryRegionInfo(lldb::addr_t load_addr,
85 lldb_private::MemoryRegionInfo &region_info) override;
87 private:
88 void CreateMemoryRegions();
90 bool LoadBinaryViaLowmemUUID();
92 /// \return
93 /// True if any metadata were found indicating the binary that should
94 /// be loaded, regardless of whether the specified binary could be found.
95 /// False if no metadata were present.
96 bool LoadBinariesViaMetadata();
98 void LoadBinariesViaExhaustiveSearch();
99 void LoadBinariesAndSetDYLD();
100 void CleanupMemoryRegionPermissions();
102 bool CheckAddressForDyldOrKernel(lldb::addr_t addr, lldb::addr_t &dyld,
103 lldb::addr_t &kernel);
105 enum CorefilePreference { eUserProcessCorefile, eKernelCorefile };
107 /// If a core file can be interpreted multiple ways, this establishes
108 /// which style wins.
110 /// If a core file contains both a kernel binary and a user-process
111 /// dynamic loader, lldb needs to pick one over the other. This could
112 /// be a kernel corefile that happens to have a copy of dyld in its
113 /// memory. Or it could be a user process coredump of lldb while doing
114 /// kernel debugging - so a copy of the kernel is in its heap. This
115 /// should become a setting so it can be over-ridden when necessary.
116 CorefilePreference GetCorefilePreference() {
117 // For now, if both user process and kernel binaries a present,
118 // assume this is a kernel coredump which has a copy of a user
119 // process dyld in one of its pages.
120 return eKernelCorefile;
123 // For ProcessMachCore only
124 typedef lldb_private::Range<lldb::addr_t, lldb::addr_t> FileRange;
125 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, FileRange>
126 VMRangeToFileOffset;
127 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, uint32_t>
128 VMRangeToPermissions;
130 VMRangeToFileOffset m_core_aranges;
131 VMRangeToPermissions m_core_range_infos;
132 lldb::ModuleSP m_core_module_sp;
133 lldb_private::FileSpec m_core_file;
134 lldb::addr_t m_dyld_addr;
135 lldb::addr_t m_mach_kernel_addr;
136 llvm::StringRef m_dyld_plugin_name;
139 #endif // LLDB_SOURCE_PLUGINS_PROCESS_MACH_CORE_PROCESSMACHCORE_H