Skip to content

Kernel fileset live debugging support #5272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lldb/include/lldb/Core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,20 @@ class PluginManager {
llvm::StringRef plugin_name);

// ObjectContainer
static bool
RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
ObjectContainerCreateInstance create_callback,
ObjectFileGetModuleSpecifications get_module_specifications);
static bool RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
ObjectContainerCreateInstance create_callback,
ObjectFileGetModuleSpecifications get_module_specifications,
ObjectContainerCreateMemoryInstance create_memory_callback = nullptr);

static bool UnregisterPlugin(ObjectContainerCreateInstance create_callback);

static ObjectContainerCreateInstance
GetObjectContainerCreateCallbackAtIndex(uint32_t idx);

static ObjectContainerCreateMemoryInstance
GetObjectContainerCreateMemoryCallbackAtIndex(uint32_t idx);

static ObjectFileGetModuleSpecifications
GetObjectContainerGetModuleSpecificationsCallbackAtIndex(uint32_t idx);

Expand Down
52 changes: 14 additions & 38 deletions lldb/include/lldb/Symbol/ObjectContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,14 @@ class ObjectContainer : public PluginInterface, public ModuleChild {
/// more than one architecture or object.
ObjectContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
lldb::offset_t file_offset, lldb::offset_t length,
lldb::DataBufferSP &data_sp, lldb::offset_t data_offset)
: ModuleChild(module_sp),
m_file(), // This file can be different than the module's file spec
m_offset(file_offset), m_length(length) {
if (file)
m_file = *file;
if (data_sp)
m_data.SetData(data_sp, data_offset, length);
}
lldb::DataBufferSP data_sp, lldb::offset_t data_offset);

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

/// Dump a description of this object to a Stream.
///
/// Dump a description of the current contents of this object to the
/// supplied stream \a s. The dumping should include the section list if it
/// has been parsed, and the symbol table if it has been parsed.
///
/// \param[in] s
/// The stream to which to dump the object description.
virtual void Dump(Stream *s) const = 0;

/// Gets the architecture given an index.
///
/// Copies the architecture specification for index \a idx.
Expand Down Expand Up @@ -142,29 +124,23 @@ class ObjectContainer : public PluginInterface, public ModuleChild {
/// file exists in the container.
virtual lldb::ObjectFileSP GetObjectFile(const FileSpec *file) = 0;

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

virtual ObjectFile *GetObjectFileAtIndex(uint32_t object_idx) {
return nullptr;
}
protected:
/// The file that represents this container objects (which can be different
/// from the module's file).
FileSpec m_file;

virtual ObjectContainer *GetObjectContainerAtIndex(uint32_t object_idx) {
return nullptr;
}
/// The offset in bytes into the file, or the address in memory
lldb::addr_t m_offset;

virtual const char *GetObjectNameAtIndex(uint32_t object_idx) const {
return nullptr;
}
/// The size in bytes if known (can be zero).
lldb::addr_t m_length;

protected:
// Member variables.
FileSpec m_file; ///< The file that represents this container objects (which
///can be different from the module's file).
lldb::addr_t
m_offset; ///< The offset in bytes into the file, or the address in memory
lldb::addr_t m_length; ///< The size in bytes if known (can be zero).
DataExtractor
m_data; ///< The data for this object file so things can be parsed lazily.
/// The data for this object file so things can be parsed lazily.
DataExtractor m_data;

private:
ObjectContainer(const ObjectContainer &) = delete;
Expand Down
5 changes: 2 additions & 3 deletions lldb/include/lldb/Symbol/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
/// file when storing cached data.
uint32_t GetCacheHash();

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

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

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

private:
ObjectFile(const ObjectFile &) = delete;
const ObjectFile &operator=(const ObjectFile &) = delete;
Expand Down
54 changes: 54 additions & 0 deletions lldb/include/lldb/Target/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,34 @@ class Platform : public PluginInterface {
return nullptr;
}

/// Detect a binary in memory that will determine which Platform and
/// DynamicLoader should be used in this target/process, and update
/// the Platform/DynamicLoader.
/// The binary will be loaded into the Target, or will be registered with
/// the DynamicLoader so that it will be loaded at a later stage. Returns
/// true to indicate that this is a platform binary and has been
/// loaded/registered, no further action should be taken by the caller.
///
/// \param[in] process
/// Process read memory from, a Process must be provided.
///
/// \param[in] addr
/// Address of a binary in memory.
///
/// \param[in] notify
/// Whether ModulesDidLoad should be called, if a binary is loaded.
/// Caller may prefer to call ModulesDidLoad for multiple binaries
/// that were loaded at the same time.
///
/// \return
/// Returns true if the binary was loaded in the target (or will be
/// via a DynamicLoader). Returns false if the binary was not
/// loaded/registered, and the caller must load it into the target.
virtual bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr,
bool notify) {
return false;
}

virtual CompilerType GetSiginfoType(const llvm::Triple &triple);

virtual Args GetExtraStartupCommands();
Expand Down Expand Up @@ -1026,6 +1054,32 @@ class PlatformList {

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

/// Detect a binary in memory that will determine which Platform and
/// DynamicLoader should be used in this target/process, and update
/// the Platform/DynamicLoader.
/// The binary will be loaded into the Target, or will be registered with
/// the DynamicLoader so that it will be loaded at a later stage. Returns
/// true to indicate that this is a platform binary and has been
/// loaded/registered, no further action should be taken by the caller.
///
/// \param[in] process
/// Process read memory from, a Process must be provided.
///
/// \param[in] addr
/// Address of a binary in memory.
///
/// \param[in] notify
/// Whether ModulesDidLoad should be called, if a binary is loaded.
/// Caller may prefer to call ModulesDidLoad for multiple binaries
/// that were loaded at the same time.
///
/// \return
/// Returns true if the binary was loaded in the target (or will be
/// via a DynamicLoader). Returns false if the binary was not
/// loaded/registered, and the caller must load it into the target.
bool LoadPlatformBinaryAndSetup(Process *process, lldb::addr_t addr,
bool notify);

protected:
typedef std::vector<lldb::PlatformSP> collection;
mutable std::recursive_mutex m_mutex;
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ class Process : public std::enable_shared_from_this<Process>,
/// plug-in.
virtual DynamicLoader *GetDynamicLoader();

void SetDynamicLoader(lldb::DynamicLoaderUP dyld);

// Returns AUXV structure found in many ELF-based environments.
//
// The default action is to return an empty data buffer.
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/lldb-forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ typedef std::shared_ptr<lldb_private::MemoryRegionInfo> MemoryRegionInfoSP;
typedef std::shared_ptr<lldb_private::Module> ModuleSP;
typedef std::weak_ptr<lldb_private::Module> ModuleWP;
typedef std::shared_ptr<lldb_private::ObjectFile> ObjectFileSP;
typedef std::shared_ptr<lldb_private::ObjectContainer> ObjectContainerSP;
typedef std::shared_ptr<lldb_private::ObjectFileJITDelegate>
ObjectFileJITDelegateSP;
typedef std::weak_ptr<lldb_private::ObjectFileJITDelegate>
Expand Down
3 changes: 3 additions & 0 deletions lldb/include/lldb/lldb-private-interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ typedef ObjectContainer *(*ObjectContainerCreateInstance)(
const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t offset,
lldb::offset_t length);
typedef ObjectContainer *(*ObjectContainerCreateMemoryInstance)(
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t offset);
typedef size_t (*ObjectFileGetModuleSpecifications)(
const FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
Expand Down
4 changes: 4 additions & 0 deletions lldb/source/Core/DynamicLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ ModuleSP DynamicLoader::LoadBinaryWithUUIDAndAddress(Process *process,

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

bool changed = false;
Expand Down
17 changes: 15 additions & 2 deletions lldb/source/Core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,14 @@ struct ObjectContainerInstance
ObjectContainerInstance(
llvm::StringRef name, llvm::StringRef description,
CallbackType create_callback,
ObjectContainerCreateMemoryInstance create_memory_callback,
ObjectFileGetModuleSpecifications get_module_specifications)
: PluginInstance<ObjectContainerCreateInstance>(name, description,
create_callback),
create_memory_callback(create_memory_callback),
get_module_specifications(get_module_specifications) {}

ObjectContainerCreateMemoryInstance create_memory_callback;
ObjectFileGetModuleSpecifications get_module_specifications;
};
typedef PluginInstances<ObjectContainerInstance> ObjectContainerInstances;
Expand All @@ -739,9 +742,11 @@ static ObjectContainerInstances &GetObjectContainerInstances() {
bool PluginManager::RegisterPlugin(
llvm::StringRef name, llvm::StringRef description,
ObjectContainerCreateInstance create_callback,
ObjectFileGetModuleSpecifications get_module_specifications) {
ObjectFileGetModuleSpecifications get_module_specifications,
ObjectContainerCreateMemoryInstance create_memory_callback) {
return GetObjectContainerInstances().RegisterPlugin(
name, description, create_callback, get_module_specifications);
name, description, create_callback, create_memory_callback,
get_module_specifications);
}

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

ObjectContainerCreateMemoryInstance
PluginManager::GetObjectContainerCreateMemoryCallbackAtIndex(uint32_t idx) {
const auto &instances = GetObjectContainerInstances().GetInstances();
if (idx < instances.size())
return instances[idx].create_memory_callback;
return nullptr;
}

ObjectFileGetModuleSpecifications
PluginManager::GetObjectContainerGetModuleSpecificationsCallbackAtIndex(
uint32_t idx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ add_lldb_library(lldbPluginDynamicLoaderDarwinKernel PLUGIN
lldbSymbol
lldbTarget
lldbUtility
lldbPluginPlatformMacOSX
)

add_dependencies(lldbPluginDynamicLoaderDarwinKernel
Expand Down
Loading