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"
|
2014-10-11 07:07:36 +08:00
|
|
|
#include "lldb/Core/Module.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"
|
2013-11-04 17:33:30 +08:00
|
|
|
#include "lldb/Target/StackFrame.h"
|
2011-04-06 07:22:54 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-06-08 06:56:40 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// We recently fixed a leak in one of the Instruction subclasses where
|
|
|
|
// the instruction will only hold a weak reference to the disassembler
|
|
|
|
// to avoid a cycle that was keeping both objects alive (leak) and we
|
|
|
|
// need the InstructionImpl class to make sure our public API behaves
|
|
|
|
// as users would expect. Calls in our public API allow clients to do
|
|
|
|
// things like:
|
|
|
|
//
|
|
|
|
// 1 lldb::SBInstruction inst;
|
|
|
|
// 2 inst = target.ReadInstructions(pc, 1).GetInstructionAtIndex(0)
|
|
|
|
// 3 if (inst.DoesBranch())
|
|
|
|
// 4 ...
|
|
|
|
//
|
|
|
|
// There was a temporary lldb::DisassemblerSP object created in the
|
|
|
|
// SBInstructionList that was returned by lldb.target.ReadInstructions()
|
|
|
|
// that will go away after line 2 but the "inst" object should be able
|
|
|
|
// to still answer questions about itself. So we make sure that any
|
|
|
|
// SBInstruction objects that are given out have a strong reference to
|
|
|
|
// the disassembler and the instruction so that the object can live and
|
|
|
|
// successfully respond to all queries.
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
class InstructionImpl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InstructionImpl (const lldb::DisassemblerSP &disasm_sp, const lldb::InstructionSP& inst_sp) :
|
|
|
|
m_disasm_sp(disasm_sp),
|
|
|
|
m_inst_sp(inst_sp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::InstructionSP
|
|
|
|
GetSP() const
|
|
|
|
{
|
|
|
|
return m_inst_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsValid() const
|
|
|
|
{
|
|
|
|
return (bool)m_inst_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
lldb::DisassemblerSP m_disasm_sp; // Can be empty/invalid
|
|
|
|
lldb::InstructionSP m_inst_sp;
|
|
|
|
};
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-06-08 06:56:40 +08:00
|
|
|
SBInstruction::SBInstruction() :
|
|
|
|
m_opaque_sp()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-08 06:56:40 +08:00
|
|
|
SBInstruction::SBInstruction(const lldb::DisassemblerSP &disasm_sp, const lldb::InstructionSP& inst_sp) :
|
|
|
|
m_opaque_sp(new InstructionImpl(disasm_sp, inst_sp))
|
2010-10-06 11:09:58 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
return m_opaque_sp && m_opaque_sp->IsValid();
|
2010-10-06 11:09:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBAddress
|
|
|
|
SBInstruction::GetAddress()
|
|
|
|
{
|
|
|
|
SBAddress sb_addr;
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp && inst_sp->GetAddress().IsValid())
|
|
|
|
sb_addr.SetAddress(&inst_sp->GetAddress());
|
2010-10-06 11:09:58 +08:00
|
|
|
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
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
2016-05-19 13:13:57 +08:00
|
|
|
std::unique_lock<std::recursive_mutex> lock;
|
2012-01-30 15:41:31 +08:00
|
|
|
if (target_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
lock = std::unique_lock<std::recursive_mutex>(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
|
|
|
}
|
2016-06-08 06:56:40 +08:00
|
|
|
return inst_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
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
2016-05-19 13:13:57 +08:00
|
|
|
std::unique_lock<std::recursive_mutex> lock;
|
2012-01-30 15:41:31 +08:00
|
|
|
if (target_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
lock = std::unique_lock<std::recursive_mutex>(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
|
|
|
}
|
2016-06-08 06:56:40 +08:00
|
|
|
return inst_sp->GetOperands(&exe_ctx);
|
2011-09-26 15:11:27 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SBInstruction::GetComment(SBTarget target)
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
|
|
|
ExecutionContext exe_ctx;
|
2012-01-30 15:41:31 +08:00
|
|
|
TargetSP target_sp (target.GetSP());
|
2016-05-19 13:13:57 +08:00
|
|
|
std::unique_lock<std::recursive_mutex> lock;
|
2012-01-30 15:41:31 +08:00
|
|
|
if (target_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2016-05-19 13:13:57 +08:00
|
|
|
lock = std::unique_lock<std::recursive_mutex>(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
|
|
|
}
|
2016-06-08 06:56:40 +08:00
|
|
|
return inst_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 ()
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
|
|
|
return inst_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;
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
2011-09-26 15:11:27 +08:00
|
|
|
{
|
2012-04-12 05:13:31 +08:00
|
|
|
DataExtractorSP data_extractor_sp (new DataExtractor());
|
2016-06-08 06:56:40 +08:00
|
|
|
if (inst_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 ()
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
|
|
|
return inst_sp->DoesBranch ();
|
2010-10-06 11:09:58 +08:00
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-01-27 18:16:30 +08:00
|
|
|
bool
|
|
|
|
SBInstruction::HasDelaySlot ()
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
|
|
|
return inst_sp->HasDelaySlot ();
|
2016-01-27 18:16:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP
|
|
|
|
SBInstruction::GetOpaque ()
|
|
|
|
{
|
|
|
|
if (m_opaque_sp)
|
|
|
|
return m_opaque_sp->GetSP();
|
|
|
|
else
|
|
|
|
return lldb::InstructionSP();
|
|
|
|
}
|
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
void
|
2016-06-08 06:56:40 +08:00
|
|
|
SBInstruction::SetOpaque (const lldb::DisassemblerSP &disasm_sp, const lldb::InstructionSP& inst_sp)
|
2010-10-06 11:09:58 +08:00
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
m_opaque_sp.reset(new InstructionImpl(disasm_sp, inst_sp));
|
2010-10-06 11:09:58 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-06 11:09:58 +08:00
|
|
|
bool
|
|
|
|
SBInstruction::GetDescription (lldb::SBStream &s)
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
2010-10-06 11:09:58 +08:00
|
|
|
{
|
2014-10-11 07:07:36 +08:00
|
|
|
SymbolContext sc;
|
2016-06-08 06:56:40 +08:00
|
|
|
const Address &addr = inst_sp->GetAddress();
|
2014-10-11 07:07:36 +08:00
|
|
|
ModuleSP module_sp (addr.GetModule());
|
|
|
|
if (module_sp)
|
|
|
|
module_sp->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc);
|
2010-10-06 11:09:58 +08:00
|
|
|
// Use the "ref()" instead of the "get()" accessor in case the SBStream
|
|
|
|
// didn't have a stream already created, one will get created...
|
2015-02-05 06:00:53 +08:00
|
|
|
FormatEntity::Entry format;
|
|
|
|
FormatEntity::Parse("${addr}: ", format);
|
2016-06-08 06:56:40 +08:00
|
|
|
inst_sp->Dump (&s.ref(), 0, true, false, NULL, &sc, NULL, &format, 0);
|
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;
|
|
|
|
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
2010-10-06 11:09:58 +08:00
|
|
|
{
|
2014-10-11 07:07:36 +08:00
|
|
|
SymbolContext sc;
|
2016-06-08 06:56:40 +08:00
|
|
|
const Address &addr = inst_sp->GetAddress();
|
2014-10-11 07:07:36 +08:00
|
|
|
ModuleSP module_sp (addr.GetModule());
|
|
|
|
if (module_sp)
|
|
|
|
module_sp->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc);
|
2011-02-09 09:08:52 +08:00
|
|
|
StreamFile out_stream (out, false);
|
2015-02-05 06:00:53 +08:00
|
|
|
FormatEntity::Entry format;
|
|
|
|
FormatEntity::Parse("${addr}: ", format);
|
2016-06-08 06:56:40 +08:00
|
|
|
inst_sp->Dump (&out_stream, 0, true, false, NULL, &sc, NULL, &format, 0);
|
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
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
2011-04-06 07:22:54 +08:00
|
|
|
{
|
2013-11-04 17:33:30 +08:00
|
|
|
lldb::StackFrameSP frame_sp (frame.GetFrameSP());
|
2012-01-30 15:41:31 +08:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2016-06-08 06:56:40 +08:00
|
|
|
return inst_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);
|
2012-01-30 15:41:31 +08:00
|
|
|
}
|
2011-04-06 07:22:54 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBInstruction::DumpEmulation (const char *triple)
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp && triple)
|
2011-04-06 07:22:54 +08:00
|
|
|
{
|
2011-04-08 06:46:35 +08:00
|
|
|
lldb_private::ArchSpec arch (triple, NULL);
|
2016-06-08 06:56:40 +08:00
|
|
|
return inst_sp->DumpEmulation (arch);
|
2011-04-06 07:22:54 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-20 07:30:03 +08:00
|
|
|
bool
|
2016-06-08 06:56:40 +08:00
|
|
|
SBInstruction::TestEmulation (lldb::SBStream &output_stream, const char *test_file)
|
2011-04-20 07:30:03 +08:00
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
if (!m_opaque_sp)
|
|
|
|
SetOpaque(lldb::DisassemblerSP(), lldb::InstructionSP(new PseudoInstruction()));
|
|
|
|
|
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
|
|
|
return inst_sp->TestEmulation (output_stream.get(), test_file);
|
|
|
|
return false;
|
2011-04-22 04:27:45 +08:00
|
|
|
}
|
2012-04-13 08:07:34 +08:00
|
|
|
|
|
|
|
lldb::AddressClass
|
|
|
|
SBInstruction::GetAddressClass ()
|
|
|
|
{
|
2016-06-08 06:56:40 +08:00
|
|
|
lldb::InstructionSP inst_sp(GetOpaque());
|
|
|
|
if (inst_sp)
|
|
|
|
return inst_sp->GetAddressClass();
|
2012-04-13 08:07:34 +08:00
|
|
|
return eAddressClassInvalid;
|
|
|
|
}
|