Skip to content

Commit 6ad20b8

Browse files
authored
Merge pull request #5272 from jasonmolenda/kernel-fileset-live-debugging-support
Kernel fileset live debugging support
2 parents 5991caa + 41527c1 commit 6ad20b8

37 files changed

+1028
-217
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,20 @@ class PluginManager {
196196
llvm::StringRef plugin_name);
197197

198198
// ObjectContainer
199-
static bool
200-
RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
201-
ObjectContainerCreateInstance create_callback,
202-
ObjectFileGetModuleSpecifications get_module_specifications);
199+
static bool RegisterPlugin(
200+
llvm::StringRef name, llvm::StringRef description,
201+
ObjectContainerCreateInstance create_callback,
202+
ObjectFileGetModuleSpecifications get_module_specifications,
203+
ObjectContainerCreateMemoryInstance create_memory_callback = nullptr);
203204

204205
static bool UnregisterPlugin(ObjectContainerCreateInstance create_callback);
205206

206207
static ObjectContainerCreateInstance
207208
GetObjectContainerCreateCallbackAtIndex(uint32_t idx);
208209

210+
static ObjectContainerCreateMemoryInstance
211+
GetObjectContainerCreateMemoryCallbackAtIndex(uint32_t idx);
212+
209213
static ObjectFileGetModuleSpecifications
210214
GetObjectContainerGetModuleSpecificationsCallbackAtIndex(uint32_t idx);
211215

lldb/include/lldb/Symbol/ObjectContainer.h

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,14 @@ class ObjectContainer : public PluginInterface, public ModuleChild {
3636
/// more than one architecture or object.
3737
ObjectContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
3838
lldb::offset_t file_offset, lldb::offset_t length,
39-
lldb::DataBufferSP &data_sp, lldb::offset_t data_offset)
40-
: ModuleChild(module_sp),
41-
m_file(), // This file can be different than the module's file spec
42-
m_offset(file_offset), m_length(length) {
43-
if (file)
44-
m_file = *file;
45-
if (data_sp)
46-
m_data.SetData(data_sp, data_offset, length);
47-
}
39+
lldb::DataBufferSP data_sp, lldb::offset_t data_offset);
4840

4941
/// Destructor.
5042
///
5143
/// The destructor is virtual since this class is designed to be inherited
5244
/// from by the plug-in instance.
5345
~ObjectContainer() override = default;
5446

55-
/// Dump a description of this object to a Stream.
56-
///
57-
/// Dump a description of the current contents of this object to the
58-
/// supplied stream \a s. The dumping should include the section list if it
59-
/// has been parsed, and the symbol table if it has been parsed.
60-
///
61-
/// \param[in] s
62-
/// The stream to which to dump the object description.
63-
virtual void Dump(Stream *s) const = 0;
64-
6547
/// Gets the architecture given an index.
6648
///
6749
/// Copies the architecture specification for index \a idx.
@@ -142,29 +124,23 @@ class ObjectContainer : public PluginInterface, public ModuleChild {
142124
/// file exists in the container.
143125
virtual lldb::ObjectFileSP GetObjectFile(const FileSpec *file) = 0;
144126

145-
virtual bool ObjectAtIndexIsContainer(uint32_t object_idx) { return false; }
127+
static lldb::ObjectContainerSP
128+
FindPlugin(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp,
129+
lldb::addr_t header_addr, lldb::WritableDataBufferSP file_data_sp);
146130

147-
virtual ObjectFile *GetObjectFileAtIndex(uint32_t object_idx) {
148-
return nullptr;
149-
}
131+
protected:
132+
/// The file that represents this container objects (which can be different
133+
/// from the module's file).
134+
FileSpec m_file;
150135

151-
virtual ObjectContainer *GetObjectContainerAtIndex(uint32_t object_idx) {
152-
return nullptr;
153-
}
136+
/// The offset in bytes into the file, or the address in memory
137+
lldb::addr_t m_offset;
154138

155-
virtual const char *GetObjectNameAtIndex(uint32_t object_idx) const {
156-
return nullptr;
157-
}
139+
/// The size in bytes if known (can be zero).
140+
lldb::addr_t m_length;
158141

159-
protected:
160-
// Member variables.
161-
FileSpec m_file; ///< The file that represents this container objects (which
162-
///can be different from the module's file).
163-
lldb::addr_t
164-
m_offset; ///< The offset in bytes into the file, or the address in memory
165-
lldb::addr_t m_length; ///< The size in bytes if known (can be zero).
166-
DataExtractor
167-
m_data; ///< The data for this object file so things can be parsed lazily.
142+
/// The data for this object file so things can be parsed lazily.
143+
DataExtractor m_data;
168144

169145
private:
170146
ObjectContainer(const ObjectContainer &) = delete;

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
738738
/// file when storing cached data.
739739
uint32_t GetCacheHash();
740740

741+
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
742+
uint64_t Offset);
741743

742744
protected:
743745
// Member variables.
@@ -778,9 +780,6 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
778780
/// The number of bytes to read when going through the plugins.
779781
static size_t g_initial_bytes_to_read;
780782

781-
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size,
782-
uint64_t Offset);
783-
784783
private:
785784
ObjectFile(const ObjectFile &) = delete;
786785
const ObjectFile &operator=(const ObjectFile &) = delete;

lldb/include/lldb/Target/Platform.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,34 @@ class Platform : public PluginInterface {
846846
return nullptr;
847847
}
848848

849+
/// Detect a binary in memory that will determine which Platform and
850+
/// DynamicLoader should be used in this target/process, and update
851+
/// the Platform/DynamicLoader.
852+
/// The binary will be loaded into the Target, or will be registered with
853+
/// the DynamicLoader so that it will be loaded at a later stage. Returns
854+
/// true to indicate that this is a platform binary and has been
855+
/// loaded/registered, no further action should be taken by the caller.
856+
///
857+
/// \param[in] process
858+
/// Process read memory from, a Process must be provided.
859+
///
860+
/// \param[in] addr
861+
/// Address of a binary in memory.
862+
///
863+
/// \param[in] notify
864+
/// Whether ModulesDidLoad should be called, if a binary is loaded.
865+
/// Caller may prefer to call ModulesDidLoad for multiple binaries
866+
/// that were loaded at the same time.
867+
///
868+
/// \return
869+
/// Returns true if the binary was loaded in the target (or will be
870+
/// via a DynamicLoader). Returns false if the binary was not
871+
/// loaded/registered, and the caller must load it into the target.
872+
virtual bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr,
873+
bool notify) {
874+
return false;
875+
}
876+
849877
virtual CompilerType GetSiginfoType(const llvm::Triple &triple);
850878

851879
virtual Args GetExtraStartupCommands();
@@ -1026,6 +1054,32 @@ class PlatformList {
10261054

10271055
lldb::PlatformSP Create(llvm::StringRef name);
10281056

1057+
/// Detect a binary in memory that will determine which Platform and
1058+
/// DynamicLoader should be used in this target/process, and update
1059+
/// the Platform/DynamicLoader.
1060+
/// The binary will be loaded into the Target, or will be registered with
1061+
/// the DynamicLoader so that it will be loaded at a later stage. Returns
1062+
/// true to indicate that this is a platform binary and has been
1063+
/// loaded/registered, no further action should be taken by the caller.
1064+
///
1065+
/// \param[in] process
1066+
/// Process read memory from, a Process must be provided.
1067+
///
1068+
/// \param[in] addr
1069+
/// Address of a binary in memory.
1070+
///
1071+
/// \param[in] notify
1072+
/// Whether ModulesDidLoad should be called, if a binary is loaded.
1073+
/// Caller may prefer to call ModulesDidLoad for multiple binaries
1074+
/// that were loaded at the same time.
1075+
///
1076+
/// \return
1077+
/// Returns true if the binary was loaded in the target (or will be
1078+
/// via a DynamicLoader). Returns false if the binary was not
1079+
/// loaded/registered, and the caller must load it into the target.
1080+
bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr,
1081+
bool notify);
1082+
10291083
protected:
10301084
typedef std::vector<lldb::PlatformSP> collection;
10311085
mutable std::recursive_mutex m_mutex;

lldb/include/lldb/Target/Process.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ class Process : public std::enable_shared_from_this<Process>,
653653
/// plug-in.
654654
virtual DynamicLoader *GetDynamicLoader();
655655

656+
void SetDynamicLoader(lldb::DynamicLoaderUP dyld);
657+
656658
// Returns AUXV structure found in many ELF-based environments.
657659
//
658660
// The default action is to return an empty data buffer.

lldb/include/lldb/lldb-forward.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ typedef std::shared_ptr<lldb_private::MemoryRegionInfo> MemoryRegionInfoSP;
348348
typedef std::shared_ptr<lldb_private::Module> ModuleSP;
349349
typedef std::weak_ptr<lldb_private::Module> ModuleWP;
350350
typedef std::shared_ptr<lldb_private::ObjectFile> ObjectFileSP;
351+
typedef std::shared_ptr<lldb_private::ObjectContainer> ObjectContainerSP;
351352
typedef std::shared_ptr<lldb_private::ObjectFileJITDelegate>
352353
ObjectFileJITDelegateSP;
353354
typedef std::weak_ptr<lldb_private::ObjectFileJITDelegate>

lldb/include/lldb/lldb-private-interfaces.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ typedef ObjectContainer *(*ObjectContainerCreateInstance)(
4040
const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
4141
lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t offset,
4242
lldb::offset_t length);
43+
typedef ObjectContainer *(*ObjectContainerCreateMemoryInstance)(
44+
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
45+
const lldb::ProcessSP &process_sp, lldb::addr_t offset);
4346
typedef size_t (*ObjectFileGetModuleSpecifications)(
4447
const FileSpec &file, lldb::DataBufferSP &data_sp,
4548
lldb::offset_t data_offset, lldb::offset_t file_offset,

lldb/source/Core/DynamicLoader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(Process *process,
230230

231231
Log *log = GetLog(LLDBLog::DynamicLoader);
232232
if (module_sp.get()) {
233+
// Ensure the Target has an architecture set in case
234+
// we need it while processing this binary/eh_frame/debug info.
235+
if (!target.GetArchitecture().IsValid())
236+
target.SetArchitecture(module_sp->GetArchitecture());
233237
target.GetImages().AppendIfNeeded(module_sp, false);
234238

235239
bool changed = false;

lldb/source/Core/PluginManager.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,14 @@ struct ObjectContainerInstance
722722
ObjectContainerInstance(
723723
llvm::StringRef name, llvm::StringRef description,
724724
CallbackType create_callback,
725+
ObjectContainerCreateMemoryInstance create_memory_callback,
725726
ObjectFileGetModuleSpecifications get_module_specifications)
726727
: PluginInstance<ObjectContainerCreateInstance>(name, description,
727728
create_callback),
729+
create_memory_callback(create_memory_callback),
728730
get_module_specifications(get_module_specifications) {}
729731

732+
ObjectContainerCreateMemoryInstance create_memory_callback;
730733
ObjectFileGetModuleSpecifications get_module_specifications;
731734
};
732735
typedef PluginInstances<ObjectContainerInstance> ObjectContainerInstances;
@@ -739,9 +742,11 @@ static ObjectContainerInstances &GetObjectContainerInstances() {
739742
bool PluginManager::RegisterPlugin(
740743
llvm::StringRef name, llvm::StringRef description,
741744
ObjectContainerCreateInstance create_callback,
742-
ObjectFileGetModuleSpecifications get_module_specifications) {
745+
ObjectFileGetModuleSpecifications get_module_specifications,
746+
ObjectContainerCreateMemoryInstance create_memory_callback) {
743747
return GetObjectContainerInstances().RegisterPlugin(
744-
name, description, create_callback, get_module_specifications);
748+
name, description, create_callback, create_memory_callback,
749+
get_module_specifications);
745750
}
746751

747752
bool PluginManager::UnregisterPlugin(
@@ -754,6 +759,14 @@ PluginManager::GetObjectContainerCreateCallbackAtIndex(uint32_t idx) {
754759
return GetObjectContainerInstances().GetCallbackAtIndex(idx);
755760
}
756761

762+
ObjectContainerCreateMemoryInstance
763+
PluginManager::GetObjectContainerCreateMemoryCallbackAtIndex(uint32_t idx) {
764+
const auto &instances = GetObjectContainerInstances().GetInstances();
765+
if (idx < instances.size())
766+
return instances[idx].create_memory_callback;
767+
return nullptr;
768+
}
769+
757770
ObjectFileGetModuleSpecifications
758771
PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(
759772
uint32_t idx) {

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ add_lldb_library(lldbPluginDynamicLoaderDarwinKernel PLUGIN
1717
lldbSymbol
1818
lldbTarget
1919
lldbUtility
20-
lldbPluginPlatformMacOSX
2120
)
2221

2322
add_dependencies(lldbPluginDynamicLoaderDarwinKernel

0 commit comments

Comments
 (0)