2010-06-09 00:52:24 +08:00
|
|
|
//===-- UnwindMacOSXFrameBackchain.cpp --------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Core/ArchSpec.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
|
|
|
#include "lldb/Symbol/ObjectFile.h"
|
2012-02-21 08:09:25 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2012-02-21 08:09:25 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
#include "RegisterContextMacOSXFrameBackchain.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
UnwindMacOSXFrameBackchain::UnwindMacOSXFrameBackchain (Thread &thread) :
|
|
|
|
Unwind (thread),
|
|
|
|
m_cursors()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2011-10-21 09:49:48 +08:00
|
|
|
UnwindMacOSXFrameBackchain::DoGetFrameCount()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
if (m_cursors.empty())
|
|
|
|
{
|
2012-02-21 08:09:25 +08:00
|
|
|
ExecutionContext exe_ctx (m_thread.shared_from_this());
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
const ArchSpec& target_arch = target->GetArchitecture ();
|
|
|
|
// Frame zero should always be supplied by the thread...
|
|
|
|
exe_ctx.SetFrameSP (m_thread.GetStackFrameAtIndex (0));
|
|
|
|
|
|
|
|
if (target_arch.GetAddressByteSize() == 8)
|
|
|
|
GetStackFrameData_x86_64 (exe_ctx);
|
|
|
|
else
|
|
|
|
GetStackFrameData_i386 (exe_ctx);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return m_cursors.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-10-21 09:49:48 +08:00
|
|
|
UnwindMacOSXFrameBackchain::DoGetFrameInfoAtIndex (uint32_t idx, addr_t& cfa, addr_t& pc)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
const uint32_t frame_count = GetFrameCount();
|
|
|
|
if (idx < frame_count)
|
|
|
|
{
|
|
|
|
if (m_cursors[idx].pc == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
if (m_cursors[idx].fp == LLDB_INVALID_ADDRESS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pc = m_cursors[idx].pc;
|
|
|
|
cfa = m_cursors[idx].fp;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-07 06:15:06 +08:00
|
|
|
lldb::RegisterContextSP
|
2013-11-04 17:33:30 +08:00
|
|
|
UnwindMacOSXFrameBackchain::DoCreateRegisterContextForFrame (StackFrame *frame)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2011-01-07 06:15:06 +08:00
|
|
|
lldb::RegisterContextSP reg_ctx_sp;
|
|
|
|
uint32_t concrete_idx = frame->GetConcreteFrameIndex ();
|
2010-06-09 00:52:24 +08:00
|
|
|
const uint32_t frame_count = GetFrameCount();
|
2011-01-07 06:15:06 +08:00
|
|
|
if (concrete_idx < frame_count)
|
|
|
|
reg_ctx_sp.reset (new RegisterContextMacOSXFrameBackchain (m_thread, concrete_idx, m_cursors[concrete_idx]));
|
|
|
|
return reg_ctx_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2012-02-21 08:09:25 +08:00
|
|
|
UnwindMacOSXFrameBackchain::GetStackFrameData_i386 (const ExecutionContext &exe_ctx)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_cursors.clear();
|
2012-02-21 08:09:25 +08:00
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrame *first_frame = exe_ctx.GetFramePtr();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-02-21 08:09:25 +08:00
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
if (process == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
std::pair<lldb::addr_t, lldb::addr_t> fp_pc_pair;
|
|
|
|
|
2010-07-08 01:07:17 +08:00
|
|
|
struct Frame_i386
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
uint32_t fp;
|
|
|
|
uint32_t pc;
|
|
|
|
};
|
|
|
|
|
2011-01-07 06:15:06 +08:00
|
|
|
RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
assert (reg_ctx);
|
|
|
|
|
|
|
|
Cursor cursor;
|
|
|
|
cursor.pc = reg_ctx->GetPC (LLDB_INVALID_ADDRESS);
|
|
|
|
cursor.fp = reg_ctx->GetFP (0);
|
|
|
|
|
2012-02-22 02:37:14 +08:00
|
|
|
Frame_i386 frame = { static_cast<uint32_t>(cursor.fp), static_cast<uint32_t>(cursor.pc) };
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
m_cursors.push_back(cursor);
|
|
|
|
|
|
|
|
const size_t k_frame_size = sizeof(frame);
|
|
|
|
Error error;
|
|
|
|
while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0))
|
|
|
|
{
|
|
|
|
// Read both the FP and PC (8 bytes)
|
2012-02-21 08:09:25 +08:00
|
|
|
if (process->ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size)
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
if (frame.pc >= 0x1000)
|
|
|
|
{
|
|
|
|
cursor.pc = frame.pc;
|
|
|
|
cursor.fp = frame.fp;
|
|
|
|
m_cursors.push_back (cursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!m_cursors.empty())
|
|
|
|
{
|
|
|
|
lldb::addr_t first_frame_pc = m_cursors.front().pc;
|
|
|
|
if (first_frame_pc != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
const uint32_t resolve_scope = eSymbolContextModule |
|
|
|
|
eSymbolContextCompUnit |
|
|
|
|
eSymbolContextFunction |
|
|
|
|
eSymbolContextSymbol;
|
|
|
|
|
|
|
|
SymbolContext first_frame_sc (first_frame->GetSymbolContext(resolve_scope));
|
|
|
|
const AddressRange *addr_range_ptr = NULL;
|
2012-03-08 05:03:09 +08:00
|
|
|
AddressRange range;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (first_frame_sc.function)
|
|
|
|
addr_range_ptr = &first_frame_sc.function->GetAddressRange();
|
|
|
|
else if (first_frame_sc.symbol)
|
2012-03-08 05:03:09 +08:00
|
|
|
{
|
|
|
|
range.GetBaseAddress() = first_frame_sc.symbol->GetAddress();
|
|
|
|
range.SetByteSize (first_frame_sc.symbol->GetByteSize());
|
|
|
|
addr_range_ptr = ⦥
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (addr_range_ptr)
|
|
|
|
{
|
2010-08-25 05:05:24 +08:00
|
|
|
if (first_frame->GetFrameCodeAddress() == addr_range_ptr->GetBaseAddress())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// We are at the first instruction, so we can recover the
|
|
|
|
// previous PC by dereferencing the SP
|
|
|
|
lldb::addr_t first_frame_sp = reg_ctx->GetSP (0);
|
|
|
|
// Read the real second frame return address into frame.pc
|
2012-02-21 08:09:25 +08:00
|
|
|
if (first_frame_sp && process->ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
cursor.fp = m_cursors.front().fp;
|
|
|
|
cursor.pc = frame.pc; // Set the new second frame PC
|
|
|
|
|
|
|
|
// Insert the second frame
|
|
|
|
m_cursors.insert(m_cursors.begin()+1, cursor);
|
|
|
|
|
|
|
|
m_cursors.front().fp = first_frame_sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// uint32_t i=0;
|
|
|
|
// printf(" PC FP\n");
|
|
|
|
// printf(" ------------------ ------------------ \n");
|
|
|
|
// for (i=0; i<m_cursors.size(); ++i)
|
|
|
|
// {
|
2012-11-30 05:49:15 +08:00
|
|
|
// printf("[%3u] 0x%16.16" PRIx64 " 0x%16.16" PRIx64 "\n", i, m_cursors[i].pc, m_cursors[i].fp);
|
2010-06-09 00:52:24 +08:00
|
|
|
// }
|
|
|
|
return m_cursors.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
2012-02-21 08:09:25 +08:00
|
|
|
UnwindMacOSXFrameBackchain::GetStackFrameData_x86_64 (const ExecutionContext &exe_ctx)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
m_cursors.clear();
|
|
|
|
|
2012-02-21 08:09:25 +08:00
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
if (process == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrame *first_frame = exe_ctx.GetFramePtr();
|
2012-02-21 08:09:25 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
std::pair<lldb::addr_t, lldb::addr_t> fp_pc_pair;
|
|
|
|
|
2010-07-08 01:07:17 +08:00
|
|
|
struct Frame_x86_64
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
uint64_t fp;
|
|
|
|
uint64_t pc;
|
|
|
|
};
|
|
|
|
|
2011-01-07 06:15:06 +08:00
|
|
|
RegisterContext *reg_ctx = m_thread.GetRegisterContext().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
assert (reg_ctx);
|
|
|
|
|
|
|
|
Cursor cursor;
|
|
|
|
cursor.pc = reg_ctx->GetPC (LLDB_INVALID_ADDRESS);
|
|
|
|
cursor.fp = reg_ctx->GetFP (0);
|
|
|
|
|
|
|
|
Frame_x86_64 frame = { cursor.fp, cursor.pc };
|
|
|
|
|
|
|
|
m_cursors.push_back(cursor);
|
|
|
|
Error error;
|
|
|
|
const size_t k_frame_size = sizeof(frame);
|
|
|
|
while (frame.fp != 0 && frame.pc != 0 && ((frame.fp & 7) == 0))
|
|
|
|
{
|
|
|
|
// Read both the FP and PC (16 bytes)
|
2012-02-21 08:09:25 +08:00
|
|
|
if (process->ReadMemory (frame.fp, &frame.fp, k_frame_size, error) != k_frame_size)
|
2010-06-09 00:52:24 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (frame.pc >= 0x1000)
|
|
|
|
{
|
|
|
|
cursor.pc = frame.pc;
|
|
|
|
cursor.fp = frame.fp;
|
|
|
|
m_cursors.push_back (cursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!m_cursors.empty())
|
|
|
|
{
|
|
|
|
lldb::addr_t first_frame_pc = m_cursors.front().pc;
|
|
|
|
if (first_frame_pc != LLDB_INVALID_ADDRESS)
|
|
|
|
{
|
|
|
|
const uint32_t resolve_scope = eSymbolContextModule |
|
|
|
|
eSymbolContextCompUnit |
|
|
|
|
eSymbolContextFunction |
|
|
|
|
eSymbolContextSymbol;
|
|
|
|
|
|
|
|
SymbolContext first_frame_sc(first_frame->GetSymbolContext(resolve_scope));
|
|
|
|
const AddressRange *addr_range_ptr = NULL;
|
2012-03-08 05:03:09 +08:00
|
|
|
AddressRange range;
|
2010-06-09 00:52:24 +08:00
|
|
|
if (first_frame_sc.function)
|
|
|
|
addr_range_ptr = &first_frame_sc.function->GetAddressRange();
|
|
|
|
else if (first_frame_sc.symbol)
|
2012-03-08 05:03:09 +08:00
|
|
|
{
|
|
|
|
range.GetBaseAddress() = first_frame_sc.symbol->GetAddress();
|
|
|
|
range.SetByteSize (first_frame_sc.symbol->GetByteSize());
|
|
|
|
addr_range_ptr = ⦥
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (addr_range_ptr)
|
|
|
|
{
|
2010-08-25 05:05:24 +08:00
|
|
|
if (first_frame->GetFrameCodeAddress() == addr_range_ptr->GetBaseAddress())
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
// We are at the first instruction, so we can recover the
|
|
|
|
// previous PC by dereferencing the SP
|
|
|
|
lldb::addr_t first_frame_sp = reg_ctx->GetSP (0);
|
|
|
|
// Read the real second frame return address into frame.pc
|
2012-02-21 08:09:25 +08:00
|
|
|
if (process->ReadMemory (first_frame_sp, &frame.pc, sizeof(frame.pc), error) == sizeof(frame.pc))
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
cursor.fp = m_cursors.front().fp;
|
|
|
|
cursor.pc = frame.pc; // Set the new second frame PC
|
|
|
|
|
|
|
|
// Insert the second frame
|
|
|
|
m_cursors.insert(m_cursors.begin()+1, cursor);
|
|
|
|
|
|
|
|
m_cursors.front().fp = first_frame_sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_cursors.size();
|
|
|
|
}
|
|
|
|
|