[Lldb-commits] [lldb] r191478 - Factor the code that was eliminating redundant breakpoint locations and moving
Jim Ingham
jingham at apple.com
Thu Sep 26 18:16:58 PDT 2013
Author: jingham
Date: Thu Sep 26 20:16:58 2013
New Revision: 191478
URL: http://llvm.org/viewvc/llvm-project?rev=191478&view=rev
Log:
Factor the code that was eliminating redundant breakpoint locations and moving
line breakpoints past the prologue of functions so it can be shared between the
file & line breakpoint resolver, and the source pattern breakpoint resolver,
and then share it.
Modified:
lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h
lldb/trunk/source/Breakpoint/BreakpointResolver.cpp
lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp
lldb/trunk/source/Breakpoint/BreakpointResolverFileRegex.cpp
Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h?rev=191478&r1=191477&r2=191478&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointResolver.h Thu Sep 26 20:16:58 2013
@@ -134,6 +134,13 @@ public:
}
protected:
+ //------------------------------------------------------------------
+ /// SetSCMatchesByLine - Takes a symbol context list of matches which supposedly represent the same file and
+ /// line number in a CU, and find the nearest actual line number that matches, and then filter down the
+ /// matching addresses to unique entries, and skip the prologue if asked to do so, and then set
+ /// breakpoint locations in this breakpoint for all the resultant addresses.
+ void SetSCMatchesByLine (SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue, const char *log_ident);
+
Breakpoint *m_breakpoint; // This is the breakpoint we add locations to.
private:
Modified: lldb/trunk/source/Breakpoint/BreakpointResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolver.cpp?rev=191478&r1=191477&r2=191478&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointResolver.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointResolver.cpp Thu Sep 26 20:16:58 2013
@@ -23,9 +23,12 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/Target.h"
+#include "lldb/Symbol/CompileUnit.h"
+#include "lldb/Symbol/Function.h"
#include "lldb/lldb-private-log.h"
using namespace lldb_private;
+using namespace lldb;
//----------------------------------------------------------------------
// BreakpointResolver:
@@ -59,3 +62,144 @@ BreakpointResolver::ResolveBreakpoint (S
filter.Search (*this);
}
+void
+BreakpointResolver::SetSCMatchesByLine (SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue, const char *log_ident)
+{
+ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
+
+ while (sc_list.GetSize() > 0)
+ {
+ SymbolContextList tmp_sc_list;
+ unsigned 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:
+
+ current_idx = 0;
+ while (current_idx < tmp_sc_list.GetSize())
+ {
+ if (tmp_sc_list.GetContextAtIndex(current_idx, sc))
+ {
+ if (sc.line_entry.line != closest_line_number)
+ tmp_sc_list.RemoveContextAtIndex(current_idx);
+ else
+ current_idx++;
+ }
+ }
+
+ // Next go through and see if there are line table entries that are contiguous, and if so keep only the
+ // first of the contiguous range:
+
+ current_idx = 0;
+ std::map<Block *, lldb::addr_t> blocks_with_breakpoints;
+
+ while (current_idx < tmp_sc_list.GetSize())
+ {
+ if (tmp_sc_list.GetContextAtIndex(current_idx, sc))
+ {
+ if (blocks_with_breakpoints.find (sc.block) != blocks_with_breakpoints.end())
+ tmp_sc_list.RemoveContextAtIndex(current_idx);
+ else
+ {
+ blocks_with_breakpoints.insert (std::pair<Block *, lldb::addr_t>(sc.block, sc.line_entry.range.GetBaseAddress().GetFileAddress()));
+ current_idx++;
+ }
+ }
+ }
+
+ // 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++)
+ {
+ if (tmp_sc_list.GetContextAtIndex(i, sc))
+ {
+ Address line_start = sc.line_entry.range.GetBaseAddress();
+ if (line_start.IsValid())
+ {
+ if (filter.AddressPasses(line_start))
+ {
+ // If the line number is before the prologue end, move it there...
+ bool skipped_prologue = false;
+ if (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 %s at file address 0x%" PRIx64 " didn't pass the filter.\n",
+ log_ident ? log_ident : "",
+ line_start.GetFileAddress());
+ }
+ }
+ else
+ {
+ if (log)
+ log->Printf ("error: Unable to set breakpoint %s at file address 0x%" PRIx64 "\n",
+ log_ident ? log_ident : "",
+ line_start.GetFileAddress());
+ }
+ }
+ }
+ }
+}
Modified: lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp?rev=191478&r1=191477&r2=191478&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointResolverFileLine.cpp Thu Sep 26 20:16:58 2013
@@ -59,7 +59,6 @@ BreakpointResolverFileLine::SearchCallba
SymbolContextList sc_list;
assert (m_breakpoint != NULL);
- Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
// 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
@@ -83,145 +82,13 @@ BreakpointResolverFileLine::SearchCallba
cu_sp->ResolveSymbolContext (m_file_spec, m_line_number, m_inlines, false, eSymbolContextEverything, sc_list);
}
}
-
- while (sc_list.GetSize() > 0)
- {
- SymbolContextList tmp_sc_list;
- unsigned current_idx = 0;
- SymbolContext sc;
- bool first_entry = true;
-
- FileSpec match_file_spec;
- uint32_t closest_line_number = UINT32_MAX;
+ StreamString s;
+ s.Printf ("for %s:%d ",
+ m_file_spec.GetFilename().AsCString("<Unknown>"),
+ m_line_number);
+
+ SetSCMatchesByLine (filter, sc_list, m_skip_prologue, s.GetData());
- // 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:
-
- current_idx = 0;
- while (current_idx < tmp_sc_list.GetSize())
- {
- if (tmp_sc_list.GetContextAtIndex(current_idx, sc))
- {
- if (sc.line_entry.line != closest_line_number)
- tmp_sc_list.RemoveContextAtIndex(current_idx);
- else
- current_idx++;
- }
- }
-
- // Next go through and see if there are line table entries that are contiguous, and if so keep only the
- // first of the contiguous range:
-
- current_idx = 0;
- std::map<Block *, lldb::addr_t> blocks_with_breakpoints;
-
- while (current_idx < tmp_sc_list.GetSize())
- {
- if (tmp_sc_list.GetContextAtIndex(current_idx, sc))
- {
- if (blocks_with_breakpoints.find (sc.block) != blocks_with_breakpoints.end())
- tmp_sc_list.RemoveContextAtIndex(current_idx);
- else
- {
- blocks_with_breakpoints.insert (std::pair<Block *, lldb::addr_t>(sc.block, sc.line_entry.range.GetBaseAddress().GetFileAddress()));
- current_idx++;
- }
- }
- }
-
- // 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++)
- {
- if (tmp_sc_list.GetContextAtIndex(i, sc))
- {
- Address line_start = sc.line_entry.range.GetBaseAddress();
- if (line_start.IsValid())
- {
- if (filter.AddressPasses(line_start))
- {
- // If the line number is before the prologue end, move it there...
- 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%" PRIx64 " 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%" PRIx64 " for %s:%d\n",
- line_start.GetFileAddress(),
- m_file_spec.GetFilename().AsCString("<Unknown>"),
- m_line_number);
- }
- }
- }
- }
-
return Searcher::eCallbackReturnContinue;
}
Modified: lldb/trunk/source/Breakpoint/BreakpointResolverFileRegex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverFileRegex.cpp?rev=191478&r1=191477&r2=191478&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointResolverFileRegex.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointResolverFileRegex.cpp Thu Sep 26 20:16:58 2013
@@ -60,54 +60,19 @@ BreakpointResolverFileRegex::SearchCallb
CompileUnit *cu = context.comp_unit;
FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
std::vector<uint32_t> line_matches;
- context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
+ context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
+
uint32_t num_matches = line_matches.size();
for (uint32_t i = 0; i < num_matches; i++)
{
- uint32_t start_idx = 0;
- bool exact = false;
- while (1)
- {
- LineEntry line_entry;
+ SymbolContextList sc_list;
+ const bool search_inlines = false;
+ const bool exact = false;
- // Cycle through all the line entries that might match this one:
- start_idx = cu->FindLineEntry (start_idx, line_matches[i], NULL, exact, &line_entry);
- if (start_idx == UINT32_MAX)
- break;
- exact = true;
- start_idx++;
-
- Address line_start = line_entry.range.GetBaseAddress();
- if (line_start.IsValid())
- {
- if (filter.AddressPasses(line_start))
- {
- 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: %s\n", s.GetData());
- }
- }
- else if (log)
- {
- log->Printf ("Breakpoint at file address 0x%" PRIx64 " for %s:%d didn't pass filter.\n",
- line_start.GetFileAddress(),
- cu_file_spec.GetFilename().AsCString("<Unknown>"),
- line_matches[i]);
- }
- }
- else
- {
- if (log)
- log->Printf ("error: Unable to set breakpoint at file address 0x%" PRIx64 " for %s:%d\n",
- line_start.GetFileAddress(),
- cu_file_spec.GetFilename().AsCString("<Unknown>"),
- line_matches[i]);
- }
-
- }
+ cu->ResolveSymbolContext (cu_file_spec, line_matches[i], search_inlines, exact, eSymbolContextEverything, sc_list);
+ const bool skip_prologue = true;
+
+ BreakpointResolver::SetSCMatchesByLine (filter, sc_list, skip_prologue, m_regex.GetText());
}
assert (m_breakpoint != NULL);
More information about the lldb-commits
mailing list