[lldb-dev] [RFC] Extend ObjectFile interface.

Stephen Wilson wilsons at start.ca
Tue Jan 11 20:17:51 PST 2011


*,

I have been prototyping a DynamicLoader plugin for the Linux platform.
Current state of the effort is available here:

   https://github.com/eightcien/lldb/tree/lldb-linux


On ELF platforms there is a "rendezvous" structure in a processes
address space populated by the runtime linker for use by debuggers.
This structure provides the address of a function which is called by the
linker each time a shared object is loaded and unloaded (thus a
breakpoint at that address will let a debugger intercept such events), a
list of entries describing the currently loaded shared objects, plus a
few other things.

In order to locate this structure one must interrogate the object file
for the process.  The location of this rendezvous is provided by a
DT_DEBUG entry in the processes .dynamic section.  The actual address
must be reaped by looking at the loaded .dynamic section contents of the
process.

The first proposal is to add the following method to ObjectFile, which
allows us to locate the needed information:

    //------------------------------------------------------------------
    /// Similar to Process::GetImageInfoAddress().
    ///
    /// Some platforms embed auxiliary structures useful to debuggers in the
    /// address space of the inferior process.  This method returns the address
    /// of such a structure if the information can be resolved via entries in
    /// the object file.  ELF, for example, provides a means to hook into the
    /// runtime linker so that a debugger may monitor the loading and unloading
    /// of shared libraries.
    ///
    /// @return 
    ///     The address of any auxiliary tables, or an invalid address if this
    ///     object file format does not support or contain such information.
    virtual lldb_private::Address
    GetImageInfoAddress () { return Address(); }

In my prototype the above method is implemented by ObjectFileELF, and
Process::GetImageInfoAddress in turn uses this information.

I use an Address object instead of an lldb::addr_t as it is slightly
more generic, and perhaps more useful, to represent the info as a
"section load address + offset".


The second bit is to provide the DynamicLoader plugin with a method to
synchronize with the runtime linker.  A simple strategy is to set a
breakpoint on the entry address for the executable and to parse the
rendezvous structure after the linker has had a chance to populate it.
Hence the following addition:

    //------------------------------------------------------------------
    /// Returns the virtual address of the entry point for this object 
    /// file.
    ///
    /// @return
    ///     The virtual address of the entry point or 
    ///     LLDB_INVALID_ADDRESS if an entry point is not defined.
    //------------------------------------------------------------------
    virtual lldb::addr_t
    GetEntryPoint () const { return LLDB_INVALID_ADDRESS; }


The above two methods are enough to get a minimal DynamicLoader plugin
functioning on Linux.  I would very much appreciate any
feedback/comments on the above.


Take care,

--
steve



More information about the lldb-dev mailing list