BreakpointResolverFileLine.cpp [plain text]
#include "lldb/Breakpoint/BreakpointResolverFileLine.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Log.h"
#include "lldb/Core/StreamString.h"
#include "lldb/Target/Target.h"
#include "lldb/lldb-private-log.h"
using namespace lldb;
using namespace lldb_private;
BreakpointResolverFileLine::BreakpointResolverFileLine
(
Breakpoint *bkpt,
const FileSpec &file_spec,
uint32_t line_no,
bool check_inlines,
bool skip_prologue
) :
BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
m_file_spec (file_spec),
m_line_number (line_no),
m_inlines (check_inlines),
m_skip_prologue(skip_prologue)
{
}
BreakpointResolverFileLine::~BreakpointResolverFileLine ()
{
}
Searcher::CallbackReturn
BreakpointResolverFileLine::SearchCallback
(
SearchFilter &filter,
SymbolContext &context,
Address *addr,
bool containing
)
{
SymbolContextList sc_list;
assert (m_breakpoint != NULL);
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
uint32_t num_comp_units = context.module_sp->GetNumCompileUnits();
for (uint32_t i = 0; i < num_comp_units; i++)
{
CompUnitSP cu_sp (context.module_sp->GetCompileUnitAtIndex (i));
if (cu_sp)
{
if (filter.CompUnitPasses(*cu_sp))
cu_sp->ResolveSymbolContext (m_file_spec, m_line_number, m_inlines, false, eSymbolContextEverything, sc_list);
}
}
while (sc_list.GetSize() > 0)
{
SymbolContextList tmp_sc_list;
int current_idx = 0;
SymbolContext sc;
bool first_entry = true;
FileSpec match_file_spec;
uint32_t closest_line_number = UINT32_MAX;
while (current_idx < sc_list.GetSize())
{
bool matches;
sc_list.GetContextAtIndex (current_idx, sc);
if (first_entry)
{
match_file_spec = sc.line_entry.file;
matches = true;
first_entry = false;
}
else
matches = (sc.line_entry.file == match_file_spec);
if (matches)
{
tmp_sc_list.Append (sc);
sc_list.RemoveContextAtIndex(current_idx);
if (sc.line_entry.line < closest_line_number)
closest_line_number = sc.line_entry.line;
}
else
current_idx++;
}
uint32_t tmp_sc_list_size = tmp_sc_list.GetSize();
for (uint32_t i = 0; i < tmp_sc_list_size; i++)
{
SymbolContext sc;
if (tmp_sc_list.GetContextAtIndex(i, sc))
{
if (sc.line_entry.line == closest_line_number)
{
Address line_start = sc.line_entry.range.GetBaseAddress();
if (line_start.IsValid())
{
if (filter.AddressPasses(line_start))
{
bool skipped_prologue = false;
if (m_skip_prologue)
{
if (sc.function)
{
Address prologue_addr(sc.function->GetAddressRange().GetBaseAddress());
if (prologue_addr.IsValid() && (line_start == prologue_addr))
{
const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
if (prologue_byte_size)
{
prologue_addr.Slide(prologue_byte_size);
if (filter.AddressPasses(prologue_addr))
{
skipped_prologue = true;
line_start = prologue_addr;
}
}
}
}
}
BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(line_start));
if (log && bp_loc_sp && !m_breakpoint->IsInternal())
{
StreamString s;
bp_loc_sp->GetDescription (&s, lldb::eDescriptionLevelVerbose);
log->Printf ("Added location (skipped prologue: %s): %s \n", skipped_prologue ? "yes" : "no", s.GetData());
}
}
else if (log)
{
log->Printf ("Breakpoint at file address 0x%llx for %s:%d didn't pass the filter.\n",
line_start.GetFileAddress(),
m_file_spec.GetFilename().AsCString("<Unknown>"),
m_line_number);
}
}
else
{
if (log)
log->Printf ("error: Unable to set breakpoint at file address 0x%llx for %s:%d\n",
line_start.GetFileAddress(),
m_file_spec.GetFilename().AsCString("<Unknown>"),
m_line_number);
}
}
else
{
#if 0
s << "error: Breakpoint at '" << pos->c_str() << "' isn't resolved yet: \n";
if (sc.line_entry.address.Dump(&s, Address::DumpStyleSectionNameOffset))
s.EOL();
if (sc.line_entry.address.Dump(&s, Address::DumpStyleSectionPointerOffset))
s.EOL();
if (sc.line_entry.address.Dump(&s, Address::DumpStyleFileAddress))
s.EOL();
if (sc.line_entry.address.Dump(&s, Address::DumpStyleLoadAddress))
s.EOL();
#endif
}
}
}
}
return Searcher::eCallbackReturnContinue;
}
Searcher::Depth
BreakpointResolverFileLine::GetDepth()
{
return Searcher::eDepthModule;
}
void
BreakpointResolverFileLine::GetDescription (Stream *s)
{
s->Printf ("file ='%s', line = %u", m_file_spec.GetFilename().AsCString(), m_line_number);
}
void
BreakpointResolverFileLine::Dump (Stream *s) const
{
}