llvm-project/lldb/source/API/SBFrame.cpp

422 lines
10 KiB
C++
Raw Normal View History

//===-- SBFrame.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/SBFrame.h"
#include <string>
#include <algorithm>
#include "lldb/lldb-types.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Core/ValueObjectRegister.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Symbol/Variable.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Thread.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBValue.h"
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBStream.h"
#include "lldb/API/SBSymbolContext.h"
#include "lldb/API/SBThread.h"
using namespace lldb;
using namespace lldb_private;
SBFrame::SBFrame () :
m_opaque_sp ()
{
}
SBFrame::SBFrame (const lldb::StackFrameSP &lldb_object_sp) :
m_opaque_sp (lldb_object_sp)
{
}
SBFrame::~SBFrame()
{
}
void
SBFrame::SetFrame (const lldb::StackFrameSP &lldb_object_sp)
{
m_opaque_sp = lldb_object_sp;
}
bool
SBFrame::IsValid() const
{
return (m_opaque_sp.get() != NULL);
}
SBSymbolContext
SBFrame::GetSymbolContext (uint32_t resolve_scope) const
{
SBSymbolContext sb_sym_ctx;
if (m_opaque_sp)
sb_sym_ctx.SetSymbolContext(&m_opaque_sp->GetSymbolContext (resolve_scope));
return sb_sym_ctx;
}
SBModule
SBFrame::GetModule () const
{
SBModule sb_module (m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp);
return sb_module;
}
SBCompileUnit
SBFrame::GetCompileUnit () const
{
SBCompileUnit sb_comp_unit(m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit);
return sb_comp_unit;
}
SBFunction
SBFrame::GetFunction () const
{
SBFunction sb_function(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function);
return sb_function;
}
SBSymbol
SBFrame::GetSymbol () const
{
SBSymbol sb_symbol(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol);
return sb_symbol;
}
SBBlock
SBFrame::GetBlock () const
{
SBBlock sb_block(m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block);
return sb_block;
}
SBBlock
SBFrame::GetFrameBlock () const
{
SBBlock sb_block(m_opaque_sp->GetFrameBlock ());
return sb_block;
}
SBLineEntry
SBFrame::GetLineEntry () const
{
SBLineEntry sb_line_entry(&m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry);
return sb_line_entry;
}
uint32_t
SBFrame::GetFrameID () const
{
if (m_opaque_sp)
Added support for inlined stack frames being represented as real stack frames which is now on by default. Frames are gotten from the unwinder as concrete frames, then if inline frames are to be shown, extra information to track and reconstruct these frames is cached with each Thread and exanded as needed. I added an inline height as part of the lldb_private::StackID class, the class that helps us uniquely identify stack frames. This allows for two frames to shared the same call frame address, yet differ only in inline height. Fixed setting breakpoint by address to not require addresses to resolve. A quick example: % cat main.cpp % ./build/Debug/lldb test/stl/a.out Current executable set to 'test/stl/a.out' (x86_64). (lldb) breakpoint set --address 0x0000000100000d31 Breakpoint created: 1: address = 0x0000000100000d31, locations = 1 (lldb) r Launching 'a.out' (x86_64) (lldb) Process 38031 Stopped * thread #1: tid = 0x2e03, pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::_M_data() const at /usr/include/c++/4.2.1/bits/basic_string.h:280, stop reason = breakpoint 1.1, queue = com.apple.main-thread 277 278 _CharT* 279 _M_data() const 280 -> { return _M_dataplus._M_p; } 281 282 _CharT* 283 _M_data(_CharT* __p) (lldb) bt thread #1: tid = 0x2e03, stop reason = breakpoint 1.1, queue = com.apple.main-thread frame #0: pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::_M_data() const at /usr/include/c++/4.2.1/bits/basic_string.h:280 frame #1: pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::_M_rep() const at /usr/include/c++/4.2.1/bits/basic_string.h:288 frame #2: pc = 0x0000000100000d31, where = a.out`main [inlined] std::string::size() const at /usr/include/c++/4.2.1/bits/basic_string.h:606 frame #3: pc = 0x0000000100000d31, where = a.out`main [inlined] operator<< <char, std::char_traits<char>, std::allocator<char> > at /usr/include/c++/4.2.1/bits/basic_string.h:2414 frame #4: pc = 0x0000000100000d31, where = a.out`main + 33 at /Volumes/work/gclayton/Documents/src/lldb/test/stl/main.cpp:14 frame #5: pc = 0x0000000100000d08, where = a.out`start + 52 Each inline frame contains only the variables that they contain and each inlined stack frame is treated as a single entity. llvm-svn: 111877
2010-08-24 08:45:41 +08:00
return m_opaque_sp->GetFrameIndex ();
else
return UINT32_MAX;
}
lldb::addr_t
SBFrame::GetPC () const
{
if (m_opaque_sp)
return m_opaque_sp->GetFrameCodeAddress().GetLoadAddress (&m_opaque_sp->GetThread().GetProcess().GetTarget());
return LLDB_INVALID_ADDRESS;
}
bool
SBFrame::SetPC (lldb::addr_t new_pc)
{
if (m_opaque_sp)
return m_opaque_sp->GetRegisterContext()->SetPC (new_pc);
return false;
}
lldb::addr_t
SBFrame::GetSP () const
{
if (m_opaque_sp)
return m_opaque_sp->GetRegisterContext()->GetSP();
return LLDB_INVALID_ADDRESS;
}
lldb::addr_t
SBFrame::GetFP () const
{
if (m_opaque_sp)
return m_opaque_sp->GetRegisterContext()->GetFP();
return LLDB_INVALID_ADDRESS;
}
SBAddress
SBFrame::GetPCAddress () const
{
SBAddress sb_addr;
if (m_opaque_sp)
sb_addr.SetAddress (&m_opaque_sp->GetFrameCodeAddress());
return sb_addr;
}
void
SBFrame::Clear()
{
m_opaque_sp.reset();
}
SBValue
SBFrame::LookupVar (const char *var_name)
{
lldb::VariableSP var_sp;
if (IsValid ())
{
lldb_private::VariableList variable_list;
SBSymbolContext sc = GetSymbolContext (eSymbolContextEverything);
SBBlock block = sc.GetBlock();
if (block.IsValid())
block.AppendVariables (true, true, &variable_list);
const uint32_t num_variables = variable_list.GetSize();
bool found = false;
for (uint32_t i = 0; i < num_variables && !found; ++i)
{
var_sp = variable_list.GetVariableAtIndex(i);
if (var_sp
&& (var_sp.get()->GetName() == lldb_private::ConstString(var_name)))
found = true;
}
if (!found)
var_sp.reset();
}
if (var_sp)
{
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
return sb_value;
}
SBValue sb_value;
return sb_value;
}
SBValue
SBFrame::LookupVarInScope (const char *var_name, const char *scope)
{
lldb::VariableSP var_sp;
if (IsValid())
{
std::string scope_str = scope;
lldb::ValueType var_scope = eValueTypeInvalid;
// Convert scope_str to be all lowercase;
std::transform (scope_str.begin(), scope_str.end(), scope_str.begin(), ::tolower);
if (scope_str.compare ("global") == 0)
var_scope = eValueTypeVariableGlobal;
else if (scope_str.compare ("local") == 0)
var_scope = eValueTypeVariableLocal;
else if (scope_str.compare ("parameter") == 0)
var_scope = eValueTypeVariableArgument;
if (var_scope != eValueTypeInvalid)
{
lldb_private::VariableList variable_list;
SBSymbolContext sc = GetSymbolContext (eSymbolContextEverything);
SBBlock block = sc.GetBlock();
if (block.IsValid())
block.AppendVariables (true, true, &variable_list);
const uint32_t num_variables = variable_list.GetSize();
bool found = false;
for (uint32_t i = 0; i < num_variables && !found; ++i)
{
var_sp = variable_list.GetVariableAtIndex(i);
if (var_sp
&& (var_sp.get()->GetName() == lldb_private::ConstString(var_name))
&& var_sp.get()->GetScope() == var_scope)
found = true;
}
if (!found)
var_sp.reset();
}
}
if (var_sp)
{
SBValue sb_value (ValueObjectSP (new ValueObjectVariable (var_sp)));
return sb_value;
}
SBValue sb_value;
return sb_value;
}
bool
SBFrame::operator == (const SBFrame &rhs) const
{
return m_opaque_sp.get() == rhs.m_opaque_sp.get();
}
bool
SBFrame::operator != (const SBFrame &rhs) const
{
return m_opaque_sp.get() != rhs.m_opaque_sp.get();
}
lldb_private::StackFrame *
SBFrame::operator->() const
{
return m_opaque_sp.get();
}
lldb_private::StackFrame *
SBFrame::get() const
{
return m_opaque_sp.get();
}
SBThread
SBFrame::GetThread () const
{
SBThread sb_thread (m_opaque_sp->GetThread().GetSP());
return sb_thread;
}
const char *
SBFrame::Disassemble () const
{
if (m_opaque_sp)
return m_opaque_sp->Disassemble();
return NULL;
}
lldb_private::StackFrame *
SBFrame::GetLLDBObjectPtr ()
{
return m_opaque_sp.get();
}
SBValueList
SBFrame::GetVariables (bool arguments,
bool locals,
bool statics,
bool in_scope_only)
{
SBValueList value_list;
if (m_opaque_sp)
{
size_t i;
VariableList *variable_list = m_opaque_sp->GetVariableList(true);
if (variable_list)
{
const size_t num_variables = variable_list->GetSize();
if (num_variables)
{
for (i = 0; i < num_variables; ++i)
{
VariableSP variable_sp (variable_list->GetVariableAtIndex(i));
if (variable_sp)
{
bool add_variable = false;
switch (variable_sp->GetScope())
{
case eValueTypeVariableGlobal:
case eValueTypeVariableStatic:
add_variable = statics;
break;
case eValueTypeVariableArgument:
add_variable = arguments;
break;
case eValueTypeVariableLocal:
add_variable = locals;
break;
default:
break;
}
if (add_variable)
{
if (in_scope_only && !variable_sp->IsInScope(m_opaque_sp.get()))
continue;
value_list.Append(m_opaque_sp->GetValueObjectForFrameVariable (variable_sp));
}
}
}
}
}
}
return value_list;
}
lldb::SBValueList
SBFrame::GetRegisters ()
{
SBValueList value_list;
if (m_opaque_sp)
{
RegisterContext *reg_ctx = m_opaque_sp->GetRegisterContext();
if (reg_ctx)
{
const uint32_t num_sets = reg_ctx->GetRegisterSetCount();
for (uint32_t set_idx = 0; set_idx < num_sets; ++set_idx)
{
value_list.Append(ValueObjectSP (new ValueObjectRegisterSet (reg_ctx, set_idx)));
}
}
}
return value_list;
}
bool
SBFrame::GetDescription (SBStream &description)
{
if (m_opaque_sp)
{
description.ref();
There are now to new "settings set" variables that live in each debugger instance: settings set frame-format <string> settings set thread-format <string> This allows users to control the information that is seen when dumping threads and frames. The default values are set such that they do what they used to do prior to changing over the the user defined formats. This allows users with terminals that can display color to make different items different colors using the escape control codes. A few alias examples that will colorize your thread and frame prompts are: settings set frame-format 'frame #${frame.index}: \033[0;33m${frame.pc}\033[0m{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{ \033[0;35mat \033[1;35m${line.file.basename}:${line.number}}\033[0m\n' settings set thread-format 'thread #${thread.index}: \033[1;33mtid\033[0;33m = ${thread.id}\033[0m{, \033[0;33m${frame.pc}\033[0m}{ \033[1;4;36m${module.file.basename}\033[0;36m ${function.name}{${function.pc-offset}}\033[0m}{, \033[1;35mstop reason\033[0;35m = ${thread.stop-reason}\033[0m}{, \033[1;36mname = \033[0;36m${thread.name}\033[0m}{, \033[1;32mqueue = \033[0;32m${thread.queue}}\033[0m\n' A quick web search for "colorize terminal output" should allow you to see what you can do to make your output look like you want it. The "settings set" commands above can of course be added to your ~/.lldbinit file for permanent use. Changed the pure virtual void ExecutionContextScope::Calculate (ExecutionContext&); To: void ExecutionContextScope::CalculateExecutionContext (ExecutionContext&); I did this because this is a class that anything in the execution context heirarchy inherits from and "target->Calculate (exe_ctx)" didn't always tell you what it was really trying to do unless you look at the parameter. llvm-svn: 115485
2010-10-04 09:05:56 +08:00
m_opaque_sp->DumpUsingSettingsFormat (description.get());
}
else
description.Printf ("No value");
return true;
}
lldb::SBValue
SBFrame::EvaluateExpression (const char *expr)
{
lldb::SBValue expr_result_value;
if (m_opaque_sp)
{
}
return expr_result_value;
}