Added a DynamicLoaderStatic plug-in that will act as a static dynamic loader.

It will just load all files exactly where the files state they are (file
addresses == load addresses). This is used when the llvm::Triple::OSType is
set to llvm::Triple::UnknownOS or llvm::Triple::NoOS.

llvm-svn: 127053
This commit is contained in:
Greg Clayton 2011-03-05 01:04:56 +00:00
parent 11e6f0a6c3
commit fc7117ae93
4 changed files with 337 additions and 0 deletions

View File

@ -78,6 +78,8 @@
266A42D6128E3FFB0090CF7C /* ClangNamespaceDecl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 266A42D5128E3FFB0090CF7C /* ClangNamespaceDecl.cpp */; };
266A42D8128E40040090CF7C /* ClangNamespaceDecl.h in Headers */ = {isa = PBXBuildFile; fileRef = 266A42D7128E40040090CF7C /* ClangNamespaceDecl.h */; };
266F5CBC12FC846200DFCE33 /* Config.h in Headers */ = {isa = PBXBuildFile; fileRef = 266F5CBB12FC846200DFCE33 /* Config.h */; };
268A683F1321B53B000E3FB8 /* DynamicLoaderStatic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268A683D1321B53B000E3FB8 /* DynamicLoaderStatic.cpp */; };
268A68401321B53B000E3FB8 /* DynamicLoaderStatic.h in Headers */ = {isa = PBXBuildFile; fileRef = 268A683E1321B53B000E3FB8 /* DynamicLoaderStatic.h */; };
268DA872130095D000C9483A /* Terminal.h in Headers */ = {isa = PBXBuildFile; fileRef = 268DA871130095D000C9483A /* Terminal.h */; };
268DA874130095ED00C9483A /* Terminal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268DA873130095ED00C9483A /* Terminal.cpp */; };
268F9D53123AA15200B91E9B /* SBSymbolContextList.h in Headers */ = {isa = PBXBuildFile; fileRef = 268F9D52123AA15200B91E9B /* SBSymbolContextList.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -611,6 +613,8 @@
2682F286115EF3BD00CCFF99 /* SBError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBError.h; path = include/lldb/API/SBError.h; sourceTree = "<group>"; };
2689B0A4113EE3CD00A4AEDB /* Symbols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Symbols.h; path = include/lldb/Host/Symbols.h; sourceTree = "<group>"; };
2689B0B5113EE47E00A4AEDB /* Symbols.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Symbols.cpp; path = source/Host/macosx/Symbols.cpp; sourceTree = "<group>"; };
268A683D1321B53B000E3FB8 /* DynamicLoaderStatic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DynamicLoaderStatic.cpp; sourceTree = "<group>"; };
268A683E1321B53B000E3FB8 /* DynamicLoaderStatic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicLoaderStatic.h; sourceTree = "<group>"; };
268A813F115B19D000F645B0 /* UniqueCStringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UniqueCStringMap.h; path = include/lldb/Core/UniqueCStringMap.h; sourceTree = "<group>"; };
268DA871130095D000C9483A /* Terminal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Terminal.h; path = include/lldb/Host/Terminal.h; sourceTree = "<group>"; };
268DA873130095ED00C9483A /* Terminal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Terminal.cpp; sourceTree = "<group>"; };
@ -1249,6 +1253,7 @@
isa = PBXGroup;
children = (
260C897910F57C5600BB2B04 /* MacOSX-DYLD */,
268A683C1321B505000E3FB8 /* Static */,
);
path = DynamicLoader;
sourceTree = "<group>";
@ -1625,6 +1630,15 @@
name = Utility;
sourceTree = "<group>";
};
268A683C1321B505000E3FB8 /* Static */ = {
isa = PBXGroup;
children = (
268A683E1321B53B000E3FB8 /* DynamicLoaderStatic.h */,
268A683D1321B53B000E3FB8 /* DynamicLoaderStatic.cpp */,
);
path = Static;
sourceTree = "<group>";
};
26A3B4AB1181454800381BC2 /* BSD-Archive */ = {
isa = PBXGroup;
children = (
@ -2370,6 +2384,7 @@
2618EE6A1315B29C001D6D71 /* ProcessGDBRemote.h in Headers */,
2618EE6C1315B29C001D6D71 /* ProcessGDBRemoteLog.h in Headers */,
2618EE6E1315B29C001D6D71 /* ThreadGDBRemote.h in Headers */,
268A68401321B53B000E3FB8 /* DynamicLoaderStatic.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2876,6 +2891,7 @@
2618EE691315B29C001D6D71 /* ProcessGDBRemote.cpp in Sources */,
2618EE6B1315B29C001D6D71 /* ProcessGDBRemoteLog.cpp in Sources */,
2618EE6D1315B29C001D6D71 /* ThreadGDBRemote.cpp in Sources */,
268A683F1321B53B000E3FB8 /* DynamicLoaderStatic.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -0,0 +1,216 @@
//===-- 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;
}
void
DynamicLoaderStatic::GetPluginCommandHelp (const char *command, Stream *strm)
{
}
Error
DynamicLoaderStatic::ExecutePluginCommand (Args &command, Stream *strm)
{
Error error;
error.SetErrorString("No plug-in command are currently supported.");
return error;
}
Log *
DynamicLoaderStatic::EnablePluginLogging (Stream *strm, Args &command)
{
return NULL;
}

View File

@ -0,0 +1,100 @@
//===-- DynamicLoaderStatic.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_DynamicLoaderStatic_h_
#define liblldb_DynamicLoaderStatic_h_
// C Includes
// C++ Includes
#include <map>
#include <vector>
#include <string>
// Other libraries and framework includes
#include "llvm/Support/MachO.h"
#include "lldb/Target/DynamicLoader.h"
#include "lldb/Host/FileSpec.h"
#include "lldb/Core/UUID.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Target/Process.h"
class DynamicLoaderStatic : public lldb_private::DynamicLoader
{
public:
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void
Initialize();
static void
Terminate();
static const char *
GetPluginNameStatic();
static const char *
GetPluginDescriptionStatic();
static lldb_private::DynamicLoader *
CreateInstance (lldb_private::Process *process, bool force);
DynamicLoaderStatic (lldb_private::Process *process);
virtual
~DynamicLoaderStatic ();
//------------------------------------------------------------------
/// Called after attaching a process.
///
/// Allow DynamicLoader plug-ins to execute some code after
/// attaching to a process.
//------------------------------------------------------------------
virtual void
DidAttach ();
virtual void
DidLaunch ();
virtual lldb::ThreadPlanSP
GetStepThroughTrampolinePlan (lldb_private::Thread &thread,
bool stop_others);
virtual lldb_private::Error
CanLoadImage ();
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
virtual const char *
GetPluginName();
virtual const char *
GetShortPluginName();
virtual uint32_t
GetPluginVersion();
virtual void
GetPluginCommandHelp (const char *command, lldb_private::Stream *strm);
virtual lldb_private::Error
ExecutePluginCommand (lldb_private::Args &command, lldb_private::Stream *strm);
virtual lldb_private::Log *
EnablePluginLogging (lldb_private::Stream *strm, lldb_private::Args &command);
private:
void
LoadAllImagesAtFileAddresses ();
DISALLOW_COPY_AND_ASSIGN (DynamicLoaderStatic);
};
#endif // liblldb_DynamicLoaderStatic_h_

View File

@ -48,6 +48,8 @@
#include "Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.h"
#endif
#include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h"
using namespace lldb;
using namespace lldb_private;
@ -99,6 +101,7 @@ lldb_private::Initialize ()
ProcessLinux::Initialize();
DynamicLoaderLinuxDYLD::Initialize();
#endif
DynamicLoaderStatic::Initialize();
// Scan for any system or user LLDB plug-ins
PluginManager::Initialize();
@ -154,6 +157,8 @@ lldb_private::Terminate ()
ProcessLinux::Terminate();
DynamicLoaderLinuxDYLD::Terminate();
#endif
DynamicLoaderStatic::Terminate();
Log::Terminate();
}