From 672e6f59c5e487b83b81c8b13ce162dfda7fdddf Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Mon, 7 Mar 2011 23:44:08 +0000 Subject: Add a method "GetEntryPoint" to the ObjectFile class, and implement it on MachO & ELF - though the ELF implementation is probably a little weak. Then use this method in place of directly looking for "start" in the ThreadPlanCallFunction constructor to find the stopping point for our function evaluation. llvm-svn: 127194 --- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 135 ++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) (limited to 'lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp') diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index deac894..fa88b18 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -7,6 +7,8 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/MachO.h" + #include "ObjectFileMachO.h" #include "lldb/Core/ArchSpec.h" @@ -105,7 +107,8 @@ ObjectFileMachO::ObjectFileMachO(Module* module, DataBufferSP& dataSP, const Fil m_mutex (Mutex::eMutexTypeRecursive), m_header(), m_sections_ap(), - m_symtab_ap() + m_symtab_ap(), + m_entry_point_address () { ::memset (&m_header, 0, sizeof(m_header)); ::memset (&m_dysymtab, 0, sizeof(m_dysymtab)); @@ -1435,6 +1438,136 @@ ObjectFileMachO::GetDependentModules (FileSpecList& files) return count; } +lldb_private::Address +ObjectFileMachO::GetEntryPointAddress () +{ + // If the object file is not an executable it can't hold the entry point. m_entry_point_address + // is initialized to an invalid address, so we can just return that. + // If m_entry_point_address is valid it means we've found it already, so return the cached value. + + if (!IsExecutable() || m_entry_point_address.IsValid()) + return m_entry_point_address; + + // Otherwise, look for the UnixThread or Thread command. The data for the Thread command is given in + // /usr/include/mach-o.h, but it is basically: + // + // uint32_t flavor - this is the flavor argument you would pass to thread_get_state + // uint32_t count - this is the count of longs in the thread state data + // struct XXX_thread_state state - this is the structure from corresponding to the flavor. + // + // + // So we just keep reading the various register flavors till we find the GPR one, then read the PC out of there. + // FIXME: We will need to have a "RegisterContext data provider" class at some point that can get all the registers + // out of data in this form & attach them to a given thread. That should underlie the MacOS X User process plugin, + // and we'll also need it for the MacOS X Core File process plugin. When we have that we can also use it here. + // + // For now we hard-code the offsets and flavors we need: + // + // + + lldb_private::Mutex::Locker locker(m_mutex); + struct load_command load_cmd; + uint32_t offset = MachHeaderSizeFromMagic(m_header.magic); + uint32_t i; + lldb::addr_t start_address = LLDB_INVALID_ADDRESS; + bool done = false; + + for (i=0; iFindSymbolsWithNameAndType(ConstString ("start"), lldb::eSymbolTypeCode, contexts)) + return m_entry_point_address; + + contexts.GetContextAtIndex(0, context); + + m_entry_point_address = context.symbol->GetValue(); + } + + return m_entry_point_address; + +} + bool ObjectFileMachO::GetArchitecture (ArchSpec &arch) { -- cgit v1.1