1 //===-- DynamicLoaderStatic.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/Module.h"
11 #include "lldb/Core/PluginManager.h"
12 #include "lldb/Core/Section.h"
13 #include "lldb/Symbol/ObjectFile.h"
14 #include "lldb/Target/Target.h"
16 #include "DynamicLoaderStatic.h"
19 using namespace lldb_private;
21 //----------------------------------------------------------------------
22 // Create an instance of this class. This function is filled into
23 // the plugin info class that gets handed out by the plugin factory and
24 // allows the lldb to instantiate an instance of this class.
25 //----------------------------------------------------------------------
27 DynamicLoaderStatic::CreateInstance (Process* process, bool force)
32 const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
33 const llvm::Triple::OSType os_type = triple_ref.getOS();
34 if ((os_type == llvm::Triple::UnknownOS))
40 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
43 ObjectFile *object_file = exe_module->GetObjectFile();
46 create = (object_file->GetStrata() == ObjectFile::eStrataRawImage);
52 return new DynamicLoaderStatic (process);
56 //----------------------------------------------------------------------
58 //----------------------------------------------------------------------
59 DynamicLoaderStatic::DynamicLoaderStatic (Process* process) :
60 DynamicLoader(process)
64 //----------------------------------------------------------------------
66 //----------------------------------------------------------------------
67 DynamicLoaderStatic::~DynamicLoaderStatic()
71 //------------------------------------------------------------------
72 /// Called after attaching a process.
74 /// Allow DynamicLoader plug-ins to execute some code after
75 /// attaching to a process.
76 //------------------------------------------------------------------
78 DynamicLoaderStatic::DidAttach ()
80 LoadAllImagesAtFileAddresses();
83 //------------------------------------------------------------------
84 /// Called after attaching a process.
86 /// Allow DynamicLoader plug-ins to execute some code after
87 /// attaching to a process.
88 //------------------------------------------------------------------
90 DynamicLoaderStatic::DidLaunch ()
92 LoadAllImagesAtFileAddresses();
96 DynamicLoaderStatic::LoadAllImagesAtFileAddresses ()
98 const ModuleList &module_list = m_process->GetTarget().GetImages();
100 ModuleList loaded_module_list;
102 // Disable JIT for static dynamic loader targets
103 m_process->SetCanJIT(false);
105 Mutex::Locker mutex_locker(module_list.GetMutex());
107 const size_t num_modules = module_list.GetSize();
108 for (uint32_t idx = 0; idx < num_modules; ++idx)
110 ModuleSP module_sp (module_list.GetModuleAtIndexUnlocked (idx));
113 bool changed = false;
114 ObjectFile *image_object_file = module_sp->GetObjectFile();
115 if (image_object_file)
117 SectionList *section_list = image_object_file->GetSectionList ();
120 // All sections listed in the dyld image info structure will all
121 // either be fixed up already, or they will all be off by a single
122 // slide amount that is determined by finding the first segment
123 // that is at file offset zero which also has bytes (a file size
124 // that is greater than zero) in the object file.
126 // Determine the slide amount (if any)
127 const size_t num_sections = section_list->GetSize();
129 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
131 // Iterate through the object file sections to find the
132 // first section that starts of file offset zero and that
133 // has bytes in the file...
134 SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
137 if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress()))
145 loaded_module_list.AppendIfNeeded (module_sp);
149 m_process->GetTarget().ModulesDidLoad (loaded_module_list);
153 DynamicLoaderStatic::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
155 return ThreadPlanSP();
159 DynamicLoaderStatic::CanLoadImage ()
162 error.SetErrorString ("can't load images on with a static debug session");
167 DynamicLoaderStatic::Initialize()
169 PluginManager::RegisterPlugin (GetPluginNameStatic(),
170 GetPluginDescriptionStatic(),
175 DynamicLoaderStatic::Terminate()
177 PluginManager::UnregisterPlugin (CreateInstance);
181 lldb_private::ConstString
182 DynamicLoaderStatic::GetPluginNameStatic()
184 static ConstString g_name("static");
189 DynamicLoaderStatic::GetPluginDescriptionStatic()
191 return "Dynamic loader plug-in that will load any images at the static addresses contained in each image.";
195 //------------------------------------------------------------------
196 // PluginInterface protocol
197 //------------------------------------------------------------------
198 lldb_private::ConstString
199 DynamicLoaderStatic::GetPluginName()
201 return GetPluginNameStatic();
205 DynamicLoaderStatic::GetPluginVersion()