1 //===-- BreakpointResolverFileRegex.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/BreakpointResolverFileRegex.h"
14 // Other libraries and framework includes
16 #include "lldb/Breakpoint/BreakpointLocation.h"
17 #include "lldb/Core/SourceManager.h"
18 #include "lldb/Core/Log.h"
19 #include "lldb/Core/StreamString.h"
20 #include "lldb/Symbol/CompileUnit.h"
21 #include "lldb/Target/Target.h"
22 #include "lldb/lldb-private-log.h"
25 using namespace lldb_private;
27 //----------------------------------------------------------------------
28 // BreakpointResolverFileRegex:
29 //----------------------------------------------------------------------
30 BreakpointResolverFileRegex::BreakpointResolverFileRegex
33 RegularExpression ®ex
35 BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
40 BreakpointResolverFileRegex::~BreakpointResolverFileRegex ()
44 Searcher::CallbackReturn
45 BreakpointResolverFileRegex::SearchCallback
48 SymbolContext &context,
54 assert (m_breakpoint != NULL);
55 if (!context.target_sp)
56 return eCallbackReturnContinue;
58 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
60 CompileUnit *cu = context.comp_unit;
61 FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
62 std::vector<uint32_t> line_matches;
63 context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
64 uint32_t num_matches = line_matches.size();
65 for (uint32_t i = 0; i < num_matches; i++)
67 uint32_t start_idx = 0;
73 // Cycle through all the line entries that might match this one:
74 start_idx = cu->FindLineEntry (start_idx, line_matches[i], NULL, exact, &line_entry);
75 if (start_idx == UINT32_MAX)
80 Address line_start = line_entry.range.GetBaseAddress();
81 if (line_start.IsValid())
83 if (filter.AddressPasses(line_start))
85 BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(line_start));
86 if (log && bp_loc_sp && !m_breakpoint->IsInternal())
89 bp_loc_sp->GetDescription (&s, lldb::eDescriptionLevelVerbose);
90 log->Printf ("Added location: %s\n", s.GetData());
95 log->Printf ("Breakpoint at file address 0x%" PRIx64 " for %s:%d didn't pass filter.\n",
96 line_start.GetFileAddress(),
97 cu_file_spec.GetFilename().AsCString("<Unknown>"),
104 log->Printf ("error: Unable to set breakpoint at file address 0x%" PRIx64 " for %s:%d\n",
105 line_start.GetFileAddress(),
106 cu_file_spec.GetFilename().AsCString("<Unknown>"),
112 assert (m_breakpoint != NULL);
114 return Searcher::eCallbackReturnContinue;
118 BreakpointResolverFileRegex::GetDepth()
120 return Searcher::eDepthCompUnit;
124 BreakpointResolverFileRegex::GetDescription (Stream *s)
126 s->Printf ("source regex = \"%s\"", m_regex.GetText());
130 BreakpointResolverFileRegex::Dump (Stream *s) const