an interface to a local or remote debugging platform. By default each host OS that supports LLDB should be registering a "default" platform that will be used unless a new platform is selected. Platforms are responsible for things such as: - getting process information by name or by processs ID - finding platform files. This is useful for remote debugging where there is an SDK with files that might already or need to be cached for debug access. - getting a list of platform supported architectures in the exact order they should be selected. This helps the native x86 platform on MacOSX select the correct x86_64/i386 slice from universal binaries. - Connect to remote platforms for remote debugging - Resolving an executable including finding an executable inside platform specific bundles (macosx uses .app bundles that contain files) and also selecting the appropriate slice of universal files for a given platform. So by default there is always a local platform, but remote platforms can be connected to. I will soon be adding a new "platform" command that will support the following commands: (lldb) platform connect --name machine1 macosx connect://host:port Connected to "machine1" platform. (lldb) platform disconnect macosx This allows LLDB to be well setup to do remote debugging and also once connected process listing and finding for things like: (lldb) process attach --name x<TAB> The currently selected platform plug-in can now auto complete any available processes that start with "x". The responsibilities for the platform plug-in will soon grow and expand. llvm-svn: 127286
197 lines
5.9 KiB
C++
197 lines
5.9 KiB
C++
//===-- DynamicLoaderStatic.cpp ---------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Core/Module.h"
|
|
#include "lldb/Core/PluginManager.h"
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "DynamicLoaderStatic.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
//----------------------------------------------------------------------
|
|
// Create an instance of this class. This function is filled into
|
|
// the plugin info class that gets handed out by the plugin factory and
|
|
// allows the lldb to instantiate an instance of this class.
|
|
//----------------------------------------------------------------------
|
|
DynamicLoader *
|
|
DynamicLoaderStatic::CreateInstance (Process* process, bool force)
|
|
{
|
|
bool create = force;
|
|
if (!create)
|
|
{
|
|
const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
|
|
const llvm::Triple::OSType os_type = triple_ref.getOS();
|
|
if ((os_type == llvm::Triple::UnknownOS) ||
|
|
(os_type == llvm::Triple::NoOS))
|
|
create = true;
|
|
}
|
|
|
|
if (create)
|
|
return new DynamicLoaderStatic (process);
|
|
return NULL;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
// Constructor
|
|
//----------------------------------------------------------------------
|
|
DynamicLoaderStatic::DynamicLoaderStatic (Process* process) :
|
|
DynamicLoader(process)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
// Destructor
|
|
//----------------------------------------------------------------------
|
|
DynamicLoaderStatic::~DynamicLoaderStatic()
|
|
{
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
/// Called after attaching a process.
|
|
///
|
|
/// Allow DynamicLoader plug-ins to execute some code after
|
|
/// attaching to a process.
|
|
//------------------------------------------------------------------
|
|
void
|
|
DynamicLoaderStatic::DidAttach ()
|
|
{
|
|
LoadAllImagesAtFileAddresses();
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
/// Called after attaching a process.
|
|
///
|
|
/// Allow DynamicLoader plug-ins to execute some code after
|
|
/// attaching to a process.
|
|
//------------------------------------------------------------------
|
|
void
|
|
DynamicLoaderStatic::DidLaunch ()
|
|
{
|
|
LoadAllImagesAtFileAddresses();
|
|
}
|
|
|
|
void
|
|
DynamicLoaderStatic::LoadAllImagesAtFileAddresses ()
|
|
{
|
|
ModuleList &module_list = m_process->GetTarget().GetImages();
|
|
|
|
ModuleList loaded_module_list;
|
|
|
|
const size_t num_modules = module_list.GetSize();
|
|
for (uint32_t idx = 0; idx < num_modules; ++idx)
|
|
{
|
|
ModuleSP module_sp (module_list.GetModuleAtIndex (idx));
|
|
if (module_sp)
|
|
{
|
|
bool changed = false;
|
|
ObjectFile *image_object_file = module_sp->GetObjectFile();
|
|
if (image_object_file)
|
|
{
|
|
SectionList *section_list = image_object_file->GetSectionList ();
|
|
if (section_list)
|
|
{
|
|
// All sections listed in the dyld image info structure will all
|
|
// either be fixed up already, or they will all be off by a single
|
|
// slide amount that is determined by finding the first segment
|
|
// that is at file offset zero which also has bytes (a file size
|
|
// that is greater than zero) in the object file.
|
|
|
|
// Determine the slide amount (if any)
|
|
const size_t num_sections = section_list->GetSize();
|
|
size_t sect_idx = 0;
|
|
for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
|
|
{
|
|
// Iterate through the object file sections to find the
|
|
// first section that starts of file offset zero and that
|
|
// has bytes in the file...
|
|
Section *section = section_list->GetSectionAtIndex (sect_idx).get();
|
|
if (section)
|
|
{
|
|
if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section, section->GetFileAddress()))
|
|
changed = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (changed)
|
|
loaded_module_list.AppendIfNeeded (module_sp);
|
|
}
|
|
}
|
|
|
|
if (loaded_module_list.GetSize())
|
|
m_process->GetTarget().ModulesDidLoad (loaded_module_list);
|
|
}
|
|
|
|
ThreadPlanSP
|
|
DynamicLoaderStatic::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
|
|
{
|
|
return ThreadPlanSP();
|
|
}
|
|
|
|
Error
|
|
DynamicLoaderStatic::CanLoadImage ()
|
|
{
|
|
Error error;
|
|
error.SetErrorString ("can't load images on with a static debug session");
|
|
return error;
|
|
}
|
|
|
|
void
|
|
DynamicLoaderStatic::Initialize()
|
|
{
|
|
PluginManager::RegisterPlugin (GetPluginNameStatic(),
|
|
GetPluginDescriptionStatic(),
|
|
CreateInstance);
|
|
}
|
|
|
|
void
|
|
DynamicLoaderStatic::Terminate()
|
|
{
|
|
PluginManager::UnregisterPlugin (CreateInstance);
|
|
}
|
|
|
|
|
|
const char *
|
|
DynamicLoaderStatic::GetPluginNameStatic()
|
|
{
|
|
return "dynamic-loader.static";
|
|
}
|
|
|
|
const char *
|
|
DynamicLoaderStatic::GetPluginDescriptionStatic()
|
|
{
|
|
return "Dynamic loader plug-in that will load any images at the static addresses contained in each image.";
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
// PluginInterface protocol
|
|
//------------------------------------------------------------------
|
|
const char *
|
|
DynamicLoaderStatic::GetPluginName()
|
|
{
|
|
return "DynamicLoaderStatic";
|
|
}
|
|
|
|
const char *
|
|
DynamicLoaderStatic::GetShortPluginName()
|
|
{
|
|
return GetPluginNameStatic();
|
|
}
|
|
|
|
uint32_t
|
|
DynamicLoaderStatic::GetPluginVersion()
|
|
{
|
|
return 1;
|
|
}
|
|
|