1 //===-- BreakpointResolver.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Breakpoint/BreakpointResolver.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Address.h"
17 #include "lldb/Breakpoint/Breakpoint.h"
18 #include "lldb/Breakpoint/BreakpointLocation.h"
19 #include "lldb/Core/Log.h"
20 #include "lldb/Core/ModuleList.h"
21 #include "lldb/Core/SearchFilter.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Core/StreamString.h"
24 #include "lldb/Symbol/SymbolContext.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Symbol/CompileUnit.h"
27 #include "lldb/Symbol/Function.h"
28 #include "lldb/lldb-private-log.h"
30 using namespace lldb_private;
33 //----------------------------------------------------------------------
34 // BreakpointResolver:
35 //----------------------------------------------------------------------
36 BreakpointResolver::BreakpointResolver (Breakpoint *bkpt, const unsigned char resolverTy) :
38 SubclassID (resolverTy)
42 BreakpointResolver::~BreakpointResolver ()
48 BreakpointResolver::SetBreakpoint (Breakpoint *bkpt)
54 BreakpointResolver::ResolveBreakpointInModules (SearchFilter &filter, ModuleList &modules)
56 filter.SearchInModuleList(*this, modules);
60 BreakpointResolver::ResolveBreakpoint (SearchFilter &filter)
62 filter.Search (*this);
66 BreakpointResolver::SetSCMatchesByLine (SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue, const char *log_ident)
68 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
70 while (sc_list.GetSize() > 0)
72 SymbolContextList tmp_sc_list;
73 unsigned current_idx = 0;
75 bool first_entry = true;
77 FileSpec match_file_spec;
78 uint32_t closest_line_number = UINT32_MAX;
80 // Pull out the first entry, and all the others that match its file spec, and stuff them in the tmp list.
81 while (current_idx < sc_list.GetSize())
85 sc_list.GetContextAtIndex (current_idx, sc);
88 match_file_spec = sc.line_entry.file;
93 matches = (sc.line_entry.file == match_file_spec);
97 tmp_sc_list.Append (sc);
98 sc_list.RemoveContextAtIndex(current_idx);
100 // ResolveSymbolContext will always return a number that is >= the line number you pass in.
101 // So the smaller line number is always better.
102 if (sc.line_entry.line < closest_line_number)
103 closest_line_number = sc.line_entry.line;
109 // Okay, we've found the closest line number match, now throw away all the others:
112 while (current_idx < tmp_sc_list.GetSize())
114 if (tmp_sc_list.GetContextAtIndex(current_idx, sc))
116 if (sc.line_entry.line != closest_line_number)
117 tmp_sc_list.RemoveContextAtIndex(current_idx);
123 // Next go through and see if there are line table entries that are contiguous, and if so keep only the
124 // first of the contiguous range:
127 std::map<Block *, lldb::addr_t> blocks_with_breakpoints;
129 while (current_idx < tmp_sc_list.GetSize())
131 if (tmp_sc_list.GetContextAtIndex(current_idx, sc))
133 if (blocks_with_breakpoints.find (sc.block) != blocks_with_breakpoints.end())
134 tmp_sc_list.RemoveContextAtIndex(current_idx);
137 blocks_with_breakpoints.insert (std::pair<Block *, lldb::addr_t>(sc.block, sc.line_entry.range.GetBaseAddress().GetFileAddress()));
143 // and make breakpoints out of the closest line number match.
145 uint32_t tmp_sc_list_size = tmp_sc_list.GetSize();
147 for (uint32_t i = 0; i < tmp_sc_list_size; i++)
149 if (tmp_sc_list.GetContextAtIndex(i, sc))
151 Address line_start = sc.line_entry.range.GetBaseAddress();
152 if (line_start.IsValid())
154 if (filter.AddressPasses(line_start))
156 // If the line number is before the prologue end, move it there...
157 bool skipped_prologue = false;
162 Address prologue_addr(sc.function->GetAddressRange().GetBaseAddress());
163 if (prologue_addr.IsValid() && (line_start == prologue_addr))
165 const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
166 if (prologue_byte_size)
168 prologue_addr.Slide(prologue_byte_size);
170 if (filter.AddressPasses(prologue_addr))
172 skipped_prologue = true;
173 line_start = prologue_addr;
180 BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(line_start));
181 if (log && bp_loc_sp && !m_breakpoint->IsInternal())
184 bp_loc_sp->GetDescription (&s, lldb::eDescriptionLevelVerbose);
185 log->Printf ("Added location (skipped prologue: %s): %s \n", skipped_prologue ? "yes" : "no", s.GetData());
190 log->Printf ("Breakpoint %s at file address 0x%" PRIx64 " didn't pass the filter.\n",
191 log_ident ? log_ident : "",
192 line_start.GetFileAddress());
198 log->Printf ("error: Unable to set breakpoint %s at file address 0x%" PRIx64 "\n",
199 log_ident ? log_ident : "",
200 line_start.GetFileAddress());