Don't set breakpoints independently comp unit by comp unit, but look over all the file & line matches

and only pick the "best" ones.
<rdar://problem/10685990>

llvm-svn: 148087
This commit is contained in:
Jim Ingham 2012-01-13 02:04:05 +00:00
parent fa8326334b
commit bc2f918200
1 changed files with 111 additions and 45 deletions

View File

@ -52,17 +52,80 @@ BreakpointResolverFileLine::SearchCallback
)
{
SymbolContextList sc_list;
uint32_t sc_list_size;
CompileUnit *cu = context.comp_unit;
assert (m_breakpoint != NULL);
LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
sc_list_size = cu->ResolveSymbolContext (m_file_spec, m_line_number, m_inlines, false, eSymbolContextEverything, sc_list);
for (uint32_t i = 0; i < sc_list_size; i++)
// There is a tricky bit here. You can have two compilation units that #include the same file, and
// in one of them the function at m_line_number is used (and so code and a line entry for it is generated) but in the
// other it isn't. If we considered the CU's independently, then in the second inclusion, we'd move the breakpoint
// to the next function that actually generated code in the header file. That would end up being confusing.
// So instead, we do the CU iterations by hand here, then scan through the complete list of matches, and figure out
// the closest line number match, and only set breakpoints on that match.
// Note also that if file_spec only had a file name and not a directory, there may be many different file spec's in
// the resultant list. The closest line match for one will not be right for some totally different file.
// So we go through the match list and pull out the sets that have the same file spec in their line_entry
// and treat each set separately.
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 (filter.CompUnitPasses(*(cu_sp.get())))
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;
// Pull out the first entry, and all the others that match its file spec, and stuff them in the tmp list.
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);
// ResolveSymbolContext will always return a number that is >= the line number you pass in.
// So the smaller line number is always better.
if (sc.line_entry.line < closest_line_number)
closest_line_number = sc.line_entry.line;
}
else
current_idx++;
}
// Okay, we've found the closest line number match, now throw away all the others,
// and make breakpoints out of the closest line number match.
uint32_t tmp_sc_list_size = tmp_sc_list.GetSize();
for (uint32_t i = 0; i < tmp_sc_list_size; i++)
{
SymbolContext sc;
if (sc_list.GetContextAtIndex(i, 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())
@ -96,7 +159,7 @@ BreakpointResolverFileLine::SearchCallback
}
else
{
#if 0
#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();
@ -106,16 +169,19 @@ BreakpointResolverFileLine::SearchCallback
s.EOL();
if (sc.line_entry.address.Dump(&s, Address::DumpStyleLoadAddress))
s.EOL();
#endif
#endif
}
}
}
}
return Searcher::eCallbackReturnContinue;
}
Searcher::Depth
BreakpointResolverFileLine::GetDepth()
{
return Searcher::eDepthCompUnit;
return Searcher::eDepthModule;
}
void