2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBInstruction.cpp ---------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBInstruction.h"
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
#include "lldb/API/SBAddress.h"
|
2011-04-06 07:22:54 +08:00
|
|
|
#include "lldb/API/SBFrame.h"
|
2010-10-06 11:09:58 +08:00
|
|
|
#include "lldb/API/SBInstruction.h"
|
|
|
|
#include "lldb/API/SBStream.h"
|
2011-04-06 07:22:54 +08:00
|
|
|
#include "lldb/API/SBTarget.h"
|
2010-10-06 11:09:58 +08:00
|
|
|
|
2011-04-06 07:22:54 +08:00
|
|
|
#include "lldb/Core/ArchSpec.h"
|
2011-09-26 15:11:27 +08:00
|
|
|
#include "lldb/Core/DataBufferHeap.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/Core/DataExtractor.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Disassembler.h"
|
2011-04-06 07:22:54 +08:00
|
|
|
#include "lldb/Core/EmulateInstruction.h"
|
2010-10-06 11:09:58 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
2011-04-06 07:22:54 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
|
|
|
#include "lldb/Target/StackFrame.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
SBInstruction::SBInstruction ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
SBInstruction::SBInstruction (const lldb::InstructionSP& inst_sp) :
|
|
|
|
m_opaque_sp (inst_sp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-06 07:17:00 +08:00
|
|
|
SBInstruction::SBInstruction(const SBInstruction &rhs) :
|
|
|
|
m_opaque_sp (rhs.m_opaque_sp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SBInstruction &
|
|
|
|
SBInstruction::operator = (const SBInstruction &rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs)
|
|
|
|
m_opaque_sp = rhs.m_opaque_sp;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SBInstruction::~SBInstruction ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
bool
|
|
|
|
SBInstruction::IsValid()
|
|
|
|
{
|
|
|
|
return (m_opaque_sp.get() != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress
|
|
|
|
SBInstruction::GetAddress()
|
|
|
|
{
|
|
|
|
SBAddress sb_addr;
|
|
|
|
if (m_opaque_sp && m_opaque_sp->GetAddress().IsValid())
|
|
|
|
sb_addr.SetAddress(&m_opaque_sp->GetAddress());
|
|
|
|
return sb_addr;
|
|
|
|
}
|
|
|
|
|
2011-09-26 15:11:27 +08:00
|
|
|
const char *
|
2011-09-27 08:58:45 +08:00
|
|
|
SBInstruction::GetMnemonic(SBTarget target)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
{
|
|
|
|
Mutex::Locker api_locker;
|
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
|
|
|
if (target_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2012-05-05 07:02:50 +08:00
|
|
|
api_locker.Lock (target_sp->GetAPIMutex());
|
2012-01-30 15:41:31 +08:00
|
|
|
target_sp->CalculateExecutionContext (exe_ctx);
|
|
|
|
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
2012-05-10 10:52:23 +08:00
|
|
|
return m_opaque_sp->GetMnemonic(&exe_ctx);
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2011-09-27 08:58:45 +08:00
|
|
|
SBInstruction::GetOperands(SBTarget target)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
{
|
|
|
|
Mutex::Locker api_locker;
|
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
|
|
|
if (target_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2012-05-05 07:02:50 +08:00
|
|
|
api_locker.Lock (target_sp->GetAPIMutex());
|
2012-01-30 15:41:31 +08:00
|
|
|
target_sp->CalculateExecutionContext (exe_ctx);
|
|
|
|
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
2012-05-10 10:52:23 +08:00
|
|
|
return m_opaque_sp->GetOperands(&exe_ctx);
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBInstruction::GetComment(SBTarget target)
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
{
|
|
|
|
Mutex::Locker api_locker;
|
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
|
|
|
if (target_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2012-05-05 07:02:50 +08:00
|
|
|
api_locker.Lock (target_sp->GetAPIMutex());
|
2012-01-30 15:41:31 +08:00
|
|
|
target_sp->CalculateExecutionContext (exe_ctx);
|
|
|
|
exe_ctx.SetProcessSP(target_sp->GetProcessSP());
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
2012-05-10 10:52:23 +08:00
|
|
|
return m_opaque_sp->GetComment(&exe_ctx);
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
size_t
|
|
|
|
SBInstruction::GetByteSize ()
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
2011-03-26 02:03:16 +08:00
|
|
|
return m_opaque_sp->GetOpcode().GetByteSize();
|
2010-10-06 11:09:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-09-26 15:11:27 +08:00
|
|
|
SBData
|
|
|
|
SBInstruction::GetData (SBTarget target)
|
|
|
|
{
|
|
|
|
lldb::SBData sb_data;
|
|
|
|
if (m_opaque_sp)
|
|
|
|
{
|
2012-04-12 05:13:31 +08:00
|
|
|
DataExtractorSP data_extractor_sp (new DataExtractor());
|
2012-05-10 10:52:23 +08:00
|
|
|
if (m_opaque_sp->GetData (*data_extractor_sp))
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
|
|
|
sb_data.SetOpaque (data_extractor_sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sb_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
bool
|
|
|
|
SBInstruction::DoesBranch ()
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->DoesBranch ();
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
void
|
|
|
|
SBInstruction::SetOpaque (const lldb::InstructionSP &inst_sp)
|
|
|
|
{
|
|
|
|
m_opaque_sp = inst_sp;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
bool
|
|
|
|
SBInstruction::GetDescription (lldb::SBStream &s)
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
{
|
|
|
|
// Use the "ref()" instead of the "get()" accessor in case the SBStream
|
|
|
|
// didn't have a stream already created, one will get created...
|
2012-05-10 10:52:23 +08:00
|
|
|
m_opaque_sp->Dump (&s.ref(), 0, true, false, NULL);
|
2010-10-06 11:09:58 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
SBInstruction::Print (FILE *out)
|
|
|
|
{
|
|
|
|
if (out == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
if (m_opaque_sp)
|
|
|
|
{
|
2011-02-09 09:08:52 +08:00
|
|
|
StreamFile out_stream (out, false);
|
2012-05-10 10:52:23 +08:00
|
|
|
m_opaque_sp->Dump (&out_stream, 0, true, false, NULL);
|
2010-10-06 11:09:58 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2011-04-06 07:22:54 +08:00
|
|
|
|
|
|
|
bool
|
2011-04-26 12:39:08 +08:00
|
|
|
SBInstruction::EmulateWithFrame (lldb::SBFrame &frame, uint32_t evaluate_options)
|
2011-04-06 07:22:54 +08:00
|
|
|
{
|
2012-01-30 15:41:31 +08:00
|
|
|
if (m_opaque_sp)
|
2011-04-06 07:22:54 +08:00
|
|
|
{
|
2012-01-30 15:41:31 +08:00
|
|
|
lldb::StackFrameSP frame_sp (frame.GetFrameSP());
|
|
|
|
|
|
|
|
if (frame_sp)
|
|
|
|
{
|
|
|
|
lldb_private::ExecutionContext exe_ctx;
|
|
|
|
frame_sp->CalculateExecutionContext (exe_ctx);
|
|
|
|
lldb_private::Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
lldb_private::ArchSpec arch = target->GetArchitecture();
|
|
|
|
|
|
|
|
return m_opaque_sp->Emulate (arch,
|
|
|
|
evaluate_options,
|
|
|
|
(void *) frame_sp.get(),
|
|
|
|
&lldb_private::EmulateInstruction::ReadMemoryFrame,
|
|
|
|
&lldb_private::EmulateInstruction::WriteMemoryFrame,
|
|
|
|
&lldb_private::EmulateInstruction::ReadRegisterFrame,
|
|
|
|
&lldb_private::EmulateInstruction::WriteRegisterFrame);
|
|
|
|
}
|
2011-04-06 07:22:54 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBInstruction::DumpEmulation (const char *triple)
|
|
|
|
{
|
|
|
|
if (m_opaque_sp && triple)
|
|
|
|
{
|
2011-04-08 06:46:35 +08:00
|
|
|
lldb_private::ArchSpec arch (triple, NULL);
|
2011-04-06 07:22:54 +08:00
|
|
|
|
2011-04-09 07:33:06 +08:00
|
|
|
return m_opaque_sp->DumpEmulation (arch);
|
|
|
|
|
2011-04-06 07:22:54 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-20 07:30:03 +08:00
|
|
|
bool
|
|
|
|
SBInstruction::TestEmulation (lldb::SBStream &output_stream, const char *test_file)
|
|
|
|
{
|
|
|
|
if (!m_opaque_sp.get())
|
|
|
|
m_opaque_sp.reset (new PseudoInstruction());
|
|
|
|
|
2011-04-22 04:27:45 +08:00
|
|
|
return m_opaque_sp->TestEmulation (output_stream.get(), test_file);
|
|
|
|
}
|
2012-04-13 08:07:34 +08:00
|
|
|
|
|
|
|
lldb::AddressClass
|
|
|
|
SBInstruction::GetAddressClass ()
|
|
|
|
{
|
|
|
|
if (m_opaque_sp.get())
|
|
|
|
return m_opaque_sp->GetAddressClass();
|
|
|
|
return eAddressClassInvalid;
|
|
|
|
}
|