[lldb-dev] [PATCH] factor methods in DynamicLoaderPOSIXDYLD into base class
gclayton at apple.com
Mon Jan 27 15:05:24 PST 2014
Looks ok except for:
This is ELF specific with the file address of zero, and it probably should more be done via flags and asking the section if it is loadable:
+DynamicLoader::UpdateLoadedSectionsCommon(ModuleSP module, addr_t link_map_addr, addr_t base_addr)
+ Target &target = m_process->GetTarget();
+ const SectionList *sections = GetSectionListFromModule(module);
+ assert(sections && "SectionList missing from loaded module.");
+ const size_t num_sections = sections->GetSize();
+ for (unsigned i = 0; i < num_sections; ++i)
+ SectionSP section_sp (sections->GetSectionAtIndex(i));
+ lldb::addr_t new_load_addr = section_sp->GetFileAddress() + base_addr;
+ // If the file address of the section is zero then this is not an
+ // allocatable/loadable section (property of ELF sh_addr). Skip it.
+ if (new_load_addr == base_addr)
+ target.SetSectionLoadAddress(section_sp, new_load_addr);
There is also a module function that does something similar to this, without the looking for the zero address:
Module::SetLoadAddress (Target &target, lldb::addr_t offset, bool &changed);
So I would propose the following:
Update DynamicLoader::UpdateLoadedSectionsCommon() to call into a new function that is a virtual function in ObjectFile:
virtual bool SetLoadAddress (addr_t base_addr)
Then each object file (ObjectFileELF in your case) can choose to do the loading correctly given a single "base_addr":
ObjectFileELF::SetLoadAddress (addr_t base_addr)
Then in ObjectFileELF::SetLoadAddress() you can use the section flags that were saved in the lldb_private::Section to properly determine which sections are loadable and which aren't. This function is for a rigid slide of all loadable sections.
Does that make sense?
On Jan 27, 2014, at 2:32 PM, Steve Pucci <spucci at google.com> wrote:
> I'd like to have access to a number of methods in DynamicLoaderPOSIXDYLD from the new class I'm working on, DynamicLoaderGDBServer. These methods have no dependency on DynamicLoaderPOSIXDYLD, with two exceptions noted below, so I'm proposing to move them into the base class DynamicLoader.
> The two exceptions are the methods UpdateLoadedSections and UnloadSections; in each case there is one line of code that is special to the derived class, and the rest of the code in the method is generic to the base class. In each case I created a XXXCommon() method on the base class with the common code, and created a virtual method XXX() on the base class, which in DynamicLoaderPOSIXDYLD will call the common code and then execute its one line of specialized code.
> This patch is intended to have no functional difference whatsoever. All 276 tests that are enabled for Ubuntu pass successfully.
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
More information about the lldb-dev