Added a new bool parameter to many of the DumpStopContext() methods that

might dump file paths that allows the dumping of full paths or just the
basenames. Switched the stack frame dumping code to use just the basenames for
the files instead of the full path.

Modified the StackID class to no rely on needing the start PC for the current
function/symbol since we can use the SymbolContextScope to uniquely identify
that, unless there is no symbol context scope. In that case we can rely upon
the current PC value. This saves the StackID from having to calculate the 
start PC when the StackFrame::GetStackID() accessor is called.

Also improved the StackID less than operator to correctly handle inlined stack
frames in the same stack.

llvm-svn: 112867
This commit is contained in:
Greg Clayton 2010-09-02 21:44:10 +00:00
parent fd81cea70c
commit 6dadd508e7
21 changed files with 132 additions and 95 deletions

View File

@ -133,6 +133,9 @@ public:
bool
Contains (const VMRange& range) const;
bool
Contains (const Block *block) const;
//------------------------------------------------------------------
/// Dump the block contents.
///
@ -156,7 +159,7 @@ public:
Dump (Stream *s, lldb::addr_t base_addr, int32_t depth, bool show_context) const;
void
DumpStopContext (Stream *s, const SymbolContext *sc);
DumpStopContext (Stream *s, const SymbolContext *sc, bool show_fullpaths);
//------------------------------------------------------------------
/// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)

View File

@ -103,7 +103,7 @@ public:
Dump (Stream *s) const;
void
DumpStopContext (Stream *s) const;
DumpStopContext (Stream *s, bool show_fullpaths) const;
//------------------------------------------------------------------
/// Get accessor for the declaration column number.
///

View File

@ -110,7 +110,7 @@ struct LineEntry
/// \b false otherwise.
//------------------------------------------------------------------
bool
DumpStopContext (Stream *s) const;
DumpStopContext (Stream *s, bool show_fullpaths) const;
//------------------------------------------------------------------
/// Check if a line entry object is valid.

View File

@ -163,6 +163,7 @@ public:
DumpStopContext (Stream *s,
ExecutionContextScope *exe_scope,
const Address &so_addr,
bool show_fullpaths,
bool show_module,
bool show_inlined_frames) const;

View File

@ -100,7 +100,7 @@ public:
Disassemble ();
void
Dump (Stream *strm, bool show_frame_index);
Dump (Stream *strm, bool show_frame_index, bool show_fullpaths);
bool
IsInlined ();

View File

@ -26,22 +26,22 @@ public:
// Constructors and Destructors
//------------------------------------------------------------------
StackID () :
m_start_pc (LLDB_INVALID_ADDRESS),
m_pc (LLDB_INVALID_ADDRESS),
m_cfa (LLDB_INVALID_ADDRESS),
m_symbol_scope (NULL)
{
}
explicit
StackID (lldb::addr_t start_pc, lldb::addr_t cfa, SymbolContextScope *symbol_scope) :
m_start_pc (start_pc),
StackID (lldb::addr_t pc, lldb::addr_t cfa, SymbolContextScope *symbol_scope) :
m_pc (pc),
m_cfa (cfa),
m_symbol_scope (symbol_scope)
{
}
StackID (const StackID& rhs) :
m_start_pc (rhs.m_start_pc),
m_pc (rhs.m_pc),
m_cfa (rhs.m_cfa),
m_symbol_scope (rhs.m_symbol_scope)
{
@ -52,15 +52,9 @@ public:
}
const lldb::addr_t
GetStartAddress() const
GetPC() const
{
return m_start_pc;
}
void
SetStartAddress(lldb::addr_t start_pc)
{
m_start_pc = start_pc;
return m_pc;
}
lldb::addr_t
@ -92,7 +86,7 @@ public:
{
if (this != &rhs)
{
m_start_pc = rhs.m_start_pc;
m_pc = rhs.m_pc;
m_cfa = rhs.m_cfa;
m_symbol_scope = rhs.m_symbol_scope;
}
@ -103,7 +97,10 @@ protected:
//------------------------------------------------------------------
// Classes that inherit from StackID can see and modify these
//------------------------------------------------------------------
lldb::addr_t m_start_pc; // The start address for the function/symbol for this frame
lldb::addr_t m_pc; // The pc value for the function/symbol for this frame. This will
// only get used if the symbol scope is NULL (the code where we are
// stopped is not represented by any function or symbol in any
// shared library).
lldb::addr_t m_cfa; // The call frame address (stack pointer) value
// at the beginning of the function that uniquely
// identifies this frame (along with m_symbol_scope below)

View File

@ -288,7 +288,7 @@ SBThread::DisplaySingleFrameForSelectedContext (FILE *out,
frame_idx,
GetThreadID(),
(long long)pc);
sc->DumpStopContext (&str, &m_opaque_sp->GetProcess(), *frame.GetPCAddress(), true, false);
sc->DumpStopContext (&str, &m_opaque_sp->GetProcess(), *frame.GetPCAddress(), false, true, false);
fprintf (out, "\n");
success = true;
}

View File

@ -285,7 +285,7 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
if (level == lldb::eDescriptionLevelFull)
{
s->PutCString("where = ");
sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, true, false);
sc.DumpStopContext (s, m_owner.GetTarget().GetProcessSP().get(), m_address, true, true, false);
}
else
{
@ -313,7 +313,7 @@ BreakpointLocation::GetDescription (Stream *s, lldb::DescriptionLevel level)
{
s->EOL();
s->Indent("location = ");
sc.line_entry.DumpStopContext (s);
sc.line_entry.DumpStopContext (s, true);
}
}

View File

@ -71,7 +71,7 @@ public:
ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext());
if (exe_ctx.frame)
{
exe_ctx.frame->Dump (&result.GetOutputStream(), true);
exe_ctx.frame->Dump (&result.GetOutputStream(), true, false);
result.GetOutputStream().EOL();
result.SetStatus (eReturnStatusSuccessFinishResult);
}

View File

@ -341,7 +341,7 @@ DumpSymbolContextList (CommandInterpreter &interpreter, Stream &strm, SymbolCont
strm.PutCString(" in ");
}
}
sc.DumpStopContext(&strm, interpreter.GetDebugger().GetExecutionContext().process, sc.line_entry.range.GetBaseAddress(), true, false);
sc.DumpStopContext(&strm, interpreter.GetDebugger().GetExecutionContext().process, sc.line_entry.range.GetBaseAddress(), true, true, false);
}
}
strm.IndentLess ();

View File

@ -224,7 +224,7 @@ lldb_private::DisplayFrameForExecutionContext
if (show_frame_info)
{
strm.Indent();
frame->Dump (&strm, true);
frame->Dump (&strm, true, false);
strm.EOL();
}

View File

@ -503,7 +503,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
#endif
Address cstr_addr(*this);
cstr_addr.SetOffset(cstr_addr.GetOffset() + pointer_size);
func_sc.DumpStopContext(s, exe_scope, so_addr, true, false);
func_sc.DumpStopContext(s, exe_scope, so_addr, true, true, false);
if (ReadAddress (exe_scope, cstr_addr, pointer_size, so_addr))
{
#if VERBOSE_OUTPUT
@ -586,7 +586,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
if (pointer_sc.function || pointer_sc.symbol)
{
s->PutCString(": ");
pointer_sc.DumpStopContext(s, exe_scope, so_addr, false, false);
pointer_sc.DumpStopContext(s, exe_scope, so_addr, true, false, false);
}
}
}
@ -625,7 +625,7 @@ Address::Dump (Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, Dum
{
// We have a function or a symbol from the same
// sections as this address.
sc.DumpStopContext(s, exe_scope, *this, show_module, false);
sc.DumpStopContext(s, exe_scope, *this, true, show_module, false);
}
else
{

View File

@ -238,7 +238,7 @@ Disassembler::Disassemble
if (offset != 0)
strm.EOL();
sc.DumpStopContext(&strm, process, addr, true, false);
sc.DumpStopContext(&strm, process, addr, true, true, false);
if (sc.comp_unit && sc.line_entry.IsValid())
{

View File

@ -145,7 +145,7 @@ Block::CalculateSymbolContext (SymbolContext* sc)
}
void
Block::DumpStopContext (Stream *s, const SymbolContext *sc)
Block::DumpStopContext (Stream *s, const SymbolContext *sc, bool show_fullpaths)
{
Block* parent_block = GetParent();
@ -170,7 +170,7 @@ Block::DumpStopContext (Stream *s, const SymbolContext *sc)
if (call_site.IsValid())
{
s->PutCString(" at ");
call_site.DumpStopContext (s);
call_site.DumpStopContext (s, show_fullpaths);
}
}
}
@ -182,11 +182,11 @@ Block::DumpStopContext (Stream *s, const SymbolContext *sc)
if (sc->line_entry.IsValid())
{
s->PutCString(" at ");
sc->line_entry.DumpStopContext (s);
sc->line_entry.DumpStopContext (s, show_fullpaths);
}
}
if (parent_block)
parent_block->Block::DumpStopContext (s, NULL);
parent_block->Block::DumpStopContext (s, NULL, show_fullpaths);
}
@ -206,6 +206,24 @@ Block::Contains (addr_t range_offset) const
return VMRange::ContainsValue(m_ranges, range_offset);
}
bool
Block::Contains (const Block *block) const
{
// Block objects can't contain themselves...
if (this == block)
return false;
const Block *block_parent;
for (block_parent = block->GetParent();
block_parent != NULL;
block_parent = block_parent->GetParent())
{
if (block_parent == block)
return true;
}
return false;
}
bool
Block::Contains (const VMRange& range) const
{

View File

@ -81,11 +81,11 @@ Declaration::Dump(Stream *s) const
}
void
Declaration::DumpStopContext (Stream *s) const
Declaration::DumpStopContext (Stream *s, bool show_fullpaths) const
{
if (m_file)
{
if (s->GetVerbose())
if (show_fullpaths || s->GetVerbose())
*s << m_file;
else
m_file.GetFilename().Dump(s);

View File

@ -74,12 +74,16 @@ LineEntry::IsValid() const
}
bool
LineEntry::DumpStopContext(Stream *s) const
LineEntry::DumpStopContext(Stream *s, bool show_fullpaths) const
{
bool result = false;
if (file)
{
file.Dump (s);
if (show_fullpaths)
file.Dump (s);
else
file.GetFilename().Dump (s);
if (line)
s->PutChar(':');
result = true;

View File

@ -114,13 +114,18 @@ SymbolContext::DumpStopContext
Stream *s,
ExecutionContextScope *exe_scope,
const Address &addr,
bool show_fullpaths,
bool show_module,
bool show_inlined_frames
) const
{
if (show_module && module_sp)
{
*s << module_sp->GetFileSpec().GetFilename() << '`';
if (show_fullpaths)
*s << module_sp->GetFileSpec();
else
*s << module_sp->GetFileSpec().GetFilename();
s->PutChar('`');
}
if (function != NULL)
@ -128,7 +133,6 @@ SymbolContext::DumpStopContext
if (function->GetMangled().GetName())
function->GetMangled().GetName().Dump(s);
if (show_inlined_frames && block)
{
const InlineFunctionInfo *inline_info = block->InlinedFunctionInfo();
@ -147,7 +151,7 @@ SymbolContext::DumpStopContext
if (line_entry.IsValid())
{
s->PutCString(" at ");
line_entry.DumpStopContext(s);
line_entry.DumpStopContext(s, show_fullpaths);
}
return;
}
@ -159,7 +163,7 @@ SymbolContext::DumpStopContext
if (block != NULL)
{
s->IndentMore();
block->DumpStopContext(s, this);
block->DumpStopContext(s, this, show_fullpaths);
s->IndentLess();
}
else
@ -167,7 +171,7 @@ SymbolContext::DumpStopContext
if (line_entry.IsValid())
{
s->PutCString(" at ");
if (line_entry.DumpStopContext(s))
if (line_entry.DumpStopContext(s, show_fullpaths))
return;
}
}

View File

@ -32,8 +32,7 @@ using namespace lldb_private;
// so we know if we have tried to look up information in our internal symbol
// context (m_sc) already.
#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
#define RESOLVED_FRAME_ID_START_ADDR (RESOLVED_FRAME_CODE_ADDR << 1)
#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_ID_START_ADDR << 1)
#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
@ -50,7 +49,7 @@ StackFrame::StackFrame
m_unwind_frame_index (unwind_frame_index),
m_thread (thread),
m_reg_context_sp (),
m_id (LLDB_INVALID_ADDRESS, cfa, NULL),
m_id (pc, cfa, NULL),
m_frame_code_addr (NULL, pc),
m_sc (),
m_flags (),
@ -80,7 +79,7 @@ StackFrame::StackFrame
m_unwind_frame_index (unwind_frame_index),
m_thread (thread),
m_reg_context_sp (reg_context_sp),
m_id (LLDB_INVALID_ADDRESS, cfa, NULL),
m_id (pc, cfa, NULL),
m_frame_code_addr (NULL, pc),
m_sc (),
m_flags (),
@ -116,7 +115,7 @@ StackFrame::StackFrame
m_unwind_frame_index (unwind_frame_index),
m_thread (thread),
m_reg_context_sp (reg_context_sp),
m_id (LLDB_INVALID_ADDRESS, cfa, NULL),
m_id (pc_addr.GetLoadAddress (&thread.GetProcess()), cfa, NULL),
m_frame_code_addr (pc_addr),
m_sc (),
m_flags (),
@ -159,42 +158,12 @@ StackFrame::~StackFrame()
StackID&
StackFrame::GetStackID()
{
// Make sure we have resolved our stack ID's start PC before we give
// it out to any external clients. This allows us to not have to lookup
// this information if it is never asked for.
if (m_flags.IsClear(RESOLVED_FRAME_ID_START_ADDR))
{
m_flags.Set (RESOLVED_FRAME_ID_START_ADDR);
// Make sure we have resolved the StackID object's symbol context scope if
// we already haven't looked it up.
if (m_id.GetStartAddress() == LLDB_INVALID_ADDRESS)
{
// Resolve our PC to section offset if we haven't alreday done so
// and if we don't have a module. The resolved address section will
// contain the module to which it belongs.
if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
GetFrameCodeAddress();
if (GetSymbolContext (eSymbolContextFunction).function)
{
m_id.SetStartAddress (m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
}
else if (GetSymbolContext (eSymbolContextSymbol).symbol)
{
AddressRange *symbol_range_ptr = m_sc.symbol->GetAddressRangePtr();
if (symbol_range_ptr)
m_id.SetStartAddress(symbol_range_ptr->GetBaseAddress().GetLoadAddress (&m_thread.GetProcess()));
}
// We didn't find a function or symbol, just use the frame code address
// which will be the same as the PC in the frame.
if (m_id.GetStartAddress() == LLDB_INVALID_ADDRESS)
m_id.SetStartAddress (m_frame_code_addr.GetLoadAddress (&m_thread.GetProcess()));
}
}
if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE))
{
if (m_id.GetSymbolContextScope ())
if (m_id.GetSymbolContextScope () == NULL)
{
m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE);
}
@ -627,20 +596,18 @@ StackFrame::Calculate (ExecutionContext &exe_ctx)
}
void
StackFrame::Dump (Stream *strm, bool show_frame_index)
StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths)
{
if (strm == NULL)
return;
if (show_frame_index)
strm->Printf("frame #%u: ", m_frame_index);
strm->Printf("0x%0*llx", m_thread.GetProcess().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()));
strm->Printf("0x%0*llx ", m_thread.GetProcess().GetAddressByteSize() * 2, GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()));
GetSymbolContext(eSymbolContextEverything);
strm->PutCString(", where = ");
// TODO: need to get the
const bool show_module = true;
const bool show_inline = true;
m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_module, show_inline);
m_sc.DumpStopContext(strm, &m_thread.GetProcess(), GetFrameCodeAddress(), show_fullpaths, show_module, show_inline);
}
void

View File

@ -256,7 +256,7 @@ StackFrameList::Dump (Stream *s)
if (frame)
{
frame->GetStackID().Dump (s);
frame->Dump(s, true);
frame->Dump(s, true, false);
}
else
s->Printf("frame #%u", std::distance (begin, pos));

View File

@ -24,7 +24,7 @@ using namespace lldb_private;
void
StackID::Dump (Stream *s)
{
s->Printf("StackID (start_pc = 0x%16.16llx, cfa = 0x%16.16llx, symbol_scope = %p", (uint64_t)m_start_pc, (uint64_t)m_cfa, m_symbol_scope);
s->Printf("StackID (pc = 0x%16.16llx, cfa = 0x%16.16llx, symbol_scope = %p", (uint64_t)m_pc, (uint64_t)m_cfa, m_symbol_scope);
if (m_symbol_scope)
{
SymbolContext sc;
@ -41,21 +41,64 @@ StackID::Dump (Stream *s)
bool
lldb_private::operator== (const StackID& lhs, const StackID& rhs)
{
return lhs.GetCallFrameAddress() == rhs.GetCallFrameAddress() &&
lhs.GetSymbolContextScope() == rhs.GetSymbolContextScope() &&
lhs.GetStartAddress() == rhs.GetStartAddress();
if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())
return false;
SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
// Only compare the PC values if both symbol context scopes are NULL
if (lhs_scope == NULL && rhs_scope == NULL)
return lhs.GetPC() == rhs.GetPC();
return lhs_scope == rhs_scope;
}
bool
lldb_private::operator!= (const StackID& lhs, const StackID& rhs)
{
return lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress() ||
lhs.GetSymbolContextScope() != rhs.GetSymbolContextScope() ||
lhs.GetStartAddress() != rhs.GetStartAddress();
if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())
return true;
SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
if (lhs_scope == NULL && rhs_scope == NULL)
return lhs.GetPC() != rhs.GetPC();
return lhs_scope != rhs_scope;
}
bool
lldb_private::operator< (const StackID& lhs, const StackID& rhs)
{
return lhs.GetCallFrameAddress() < rhs.GetCallFrameAddress();
const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress();
const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress();
if (lhs_cfa != rhs_cfa)
return lhs_cfa < rhs_cfa;
SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
SymbolContextScope *rhs_scope = rhs.GetSymbolContextScope();
if (lhs_scope != NULL && rhs_scope != NULL)
{
// Same exact scope, lhs is not less than (younger than rhs)
if (lhs_scope == rhs_scope)
return false;
SymbolContext lhs_sc;
SymbolContext rhs_sc;
lhs_scope->CalculateSymbolContext (&lhs_sc);
rhs_scope->CalculateSymbolContext (&rhs_sc);
// Items with the same function can only be compared
if (lhs_sc.function == rhs_sc.function &&
lhs_sc.function != NULL && lhs_sc.block != NULL &&
rhs_sc.function != NULL && rhs_sc.block != NULL)
{
return rhs_sc.block->Contains (lhs_sc.block);
}
}
return false;
}

View File

@ -820,7 +820,7 @@ Thread::ClearStackFrames ()
lldb::StackFrameSP
Thread::GetStackFrameAtIndex (uint32_t idx)
{
return StackFrameSP (GetStackFrameList().GetFrameAtIndex(idx));
return GetStackFrameList().GetFrameAtIndex(idx);
}
lldb::StackFrameSP
@ -859,7 +859,7 @@ Thread::DumpInfo
if (frame_sp)
{
strm.PutCString(", ");
frame_sp->Dump (&strm, false);
frame_sp->Dump (&strm, false, false);
}
}