1 //===-- BreakpointResolverFileRegex.cpp --------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
11 
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project 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 
23 using namespace lldb;
24 using namespace lldb_private;
25 
26 //----------------------------------------------------------------------
27 // BreakpointResolverFileRegex:
28 //----------------------------------------------------------------------
29 BreakpointResolverFileRegex::BreakpointResolverFileRegex
30 (
31     Breakpoint *bkpt,
32     RegularExpression &regex,
33     bool exact_match
34 ) :
35     BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
36     m_regex (regex),
37     m_exact_match (exact_match)
38 {
39 }
40 
41 BreakpointResolverFileRegex::~BreakpointResolverFileRegex ()
42 {
43 }
44 
45 Searcher::CallbackReturn
46 BreakpointResolverFileRegex::SearchCallback
47 (
48     SearchFilter &filter,
49     SymbolContext &context,
50     Address *addr,
51     bool containing
52 )
53 {
54 
55     assert (m_breakpoint != NULL);
56     if (!context.target_sp)
57         return eCallbackReturnContinue;
58 
59     CompileUnit *cu = context.comp_unit;
60     FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
61     std::vector<uint32_t> line_matches;
62     context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
63 
64     uint32_t num_matches = line_matches.size();
65     for (uint32_t i = 0; i < num_matches; i++)
66     {
67         SymbolContextList sc_list;
68         const bool search_inlines = false;
69 
70         cu->ResolveSymbolContext (cu_file_spec, line_matches[i], search_inlines, m_exact_match, eSymbolContextEverything, sc_list);
71         const bool skip_prologue = true;
72 
73         BreakpointResolver::SetSCMatchesByLine (filter, sc_list, skip_prologue, m_regex.GetText());
74     }
75     assert (m_breakpoint != NULL);
76 
77     return Searcher::eCallbackReturnContinue;
78 }
79 
80 Searcher::Depth
81 BreakpointResolverFileRegex::GetDepth()
82 {
83     return Searcher::eDepthCompUnit;
84 }
85 
86 void
87 BreakpointResolverFileRegex::GetDescription (Stream *s)
88 {
89     s->Printf ("source regex = \"%s\", exact_match = %d", m_regex.GetText(), m_exact_match);
90 }
91 
92 void
93 BreakpointResolverFileRegex::Dump (Stream *s) const
94 {
95 
96 }
97 
98 lldb::BreakpointResolverSP
99 BreakpointResolverFileRegex::CopyForBreakpoint (Breakpoint &breakpoint)
100 {
101     lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileRegex(&breakpoint, m_regex, m_exact_match));
102     return ret_sp;
103 }
104 
105