hanchenye-llvm-project/lldb/source/API/SBBlock.cpp

161 lines
3.5 KiB
C++
Raw Normal View History

//===-- SBBlock.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/SBBlock.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBStream.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/Function.h"
#include "lldb/Symbol/SymbolContext.h"
using namespace lldb;
using namespace lldb_private;
SBBlock::SBBlock () :
m_opaque_ptr (NULL)
{
}
SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) :
m_opaque_ptr (lldb_object_ptr)
{
}
SBBlock::~SBBlock ()
{
m_opaque_ptr = NULL;
}
bool
SBBlock::IsValid () const
{
return m_opaque_ptr != NULL;
}
bool
SBBlock::IsInlined () const
{
if (m_opaque_ptr)
return m_opaque_ptr->GetInlinedFunctionInfo () != NULL;
return false;
}
const char *
SBBlock::GetInlinedName () const
{
if (m_opaque_ptr)
{
const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
if (inlined_info)
return inlined_info->GetName().AsCString (NULL);
}
return NULL;
}
SBFileSpec
SBBlock::GetInlinedCallSiteFile () const
{
SBFileSpec sb_file;
if (m_opaque_ptr)
{
const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
if (inlined_info)
sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile());
}
return sb_file;
}
uint32_t
SBBlock::GetInlinedCallSiteLine () const
{
if (m_opaque_ptr)
{
const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
if (inlined_info)
return inlined_info->GetCallSite().GetLine();
}
return 0;
}
uint32_t
SBBlock::GetInlinedCallSiteColumn () const
{
if (m_opaque_ptr)
{
const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
if (inlined_info)
return inlined_info->GetCallSite().GetColumn();
}
return 0;
}
void
SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
{
if (IsValid())
{
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
bool show_inline = true;
m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list);
}
}
SBBlock
SBBlock::GetParent ()
{
SBBlock sb_block;
if (m_opaque_ptr)
sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
return sb_block;
}
SBBlock
SBBlock::GetSibling ()
{
SBBlock sb_block;
if (m_opaque_ptr)
sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling();
return sb_block;
}
SBBlock
SBBlock::GetFirstChild ()
{
SBBlock sb_block;
if (m_opaque_ptr)
sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild();
return sb_block;
}
bool
SBBlock::GetDescription (SBStream &description)
{
if (m_opaque_ptr)
2010-09-21 00:21:41 +08:00
{
lldb::user_id_t id = m_opaque_ptr->GetID();
description.Printf ("Block: {id: %d} ", id);
if (IsInlined())
2010-09-21 00:21:41 +08:00
{
description.Printf (" (inlined, '%s') ", GetInlinedName());
2010-09-21 00:21:41 +08:00
}
lldb_private::SymbolContext sc;
m_opaque_ptr->CalculateSymbolContext (&sc);
if (sc.function)
2010-09-21 00:21:41 +08:00
{
m_opaque_ptr->DumpAddressRanges (description.get(),
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
2010-09-21 00:21:41 +08:00
}
}
else
description.Printf ("No value");
return true;
}