1969795f1SJim Ingham //===-- BreakpointResolverFileRegex.cpp --------------------------*- C++ -*-===//
2969795f1SJim Ingham //
3969795f1SJim Ingham //                     The LLVM Compiler Infrastructure
4969795f1SJim Ingham //
5969795f1SJim Ingham // This file is distributed under the University of Illinois Open Source
6969795f1SJim Ingham // License. See LICENSE.TXT for details.
7969795f1SJim Ingham //
8969795f1SJim Ingham //===----------------------------------------------------------------------===//
9969795f1SJim Ingham 
10969795f1SJim Ingham #include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
11969795f1SJim Ingham 
12969795f1SJim Ingham // C Includes
13969795f1SJim Ingham // C++ Includes
14969795f1SJim Ingham // Other libraries and framework includes
15969795f1SJim Ingham // Project includes
16969795f1SJim Ingham #include "lldb/Breakpoint/BreakpointLocation.h"
17969795f1SJim Ingham #include "lldb/Core/SourceManager.h"
18969795f1SJim Ingham #include "lldb/Core/Log.h"
19969795f1SJim Ingham #include "lldb/Core/StreamString.h"
201f746071SGreg Clayton #include "lldb/Symbol/CompileUnit.h"
21969795f1SJim Ingham #include "lldb/Target/Target.h"
22969795f1SJim Ingham #include "lldb/lldb-private-log.h"
23969795f1SJim Ingham 
24969795f1SJim Ingham using namespace lldb;
25969795f1SJim Ingham using namespace lldb_private;
26969795f1SJim Ingham 
27969795f1SJim Ingham //----------------------------------------------------------------------
28969795f1SJim Ingham // BreakpointResolverFileRegex:
29969795f1SJim Ingham //----------------------------------------------------------------------
30969795f1SJim Ingham BreakpointResolverFileRegex::BreakpointResolverFileRegex
31969795f1SJim Ingham (
32969795f1SJim Ingham     Breakpoint *bkpt,
33969795f1SJim Ingham     RegularExpression &regex
34969795f1SJim Ingham ) :
35969795f1SJim Ingham     BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
36969795f1SJim Ingham     m_regex (regex)
37969795f1SJim Ingham {
38969795f1SJim Ingham }
39969795f1SJim Ingham 
40969795f1SJim Ingham BreakpointResolverFileRegex::~BreakpointResolverFileRegex ()
41969795f1SJim Ingham {
42969795f1SJim Ingham }
43969795f1SJim Ingham 
44969795f1SJim Ingham Searcher::CallbackReturn
45969795f1SJim Ingham BreakpointResolverFileRegex::SearchCallback
46969795f1SJim Ingham (
47969795f1SJim Ingham     SearchFilter &filter,
48969795f1SJim Ingham     SymbolContext &context,
49969795f1SJim Ingham     Address *addr,
50969795f1SJim Ingham     bool containing
51969795f1SJim Ingham )
52969795f1SJim Ingham {
53969795f1SJim Ingham 
54969795f1SJim Ingham     assert (m_breakpoint != NULL);
55969795f1SJim Ingham     if (!context.target_sp)
56969795f1SJim Ingham         return eCallbackReturnContinue;
57969795f1SJim Ingham 
58969795f1SJim Ingham     CompileUnit *cu = context.comp_unit;
59969795f1SJim Ingham     FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
60969795f1SJim Ingham     std::vector<uint32_t> line_matches;
61969795f1SJim Ingham     context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
62f642373cSJim Ingham 
63969795f1SJim Ingham     uint32_t num_matches = line_matches.size();
64a297a97eSAndy Gibbs     for (uint32_t i = 0; i < num_matches; i++)
65969795f1SJim Ingham     {
66f642373cSJim Ingham         SymbolContextList sc_list;
67f642373cSJim Ingham         const bool search_inlines = false;
68f642373cSJim Ingham         const bool exact = false;
69969795f1SJim Ingham 
70f642373cSJim Ingham         cu->ResolveSymbolContext (cu_file_spec, line_matches[i], search_inlines, exact, eSymbolContextEverything, sc_list);
71f642373cSJim Ingham         const bool skip_prologue = true;
72969795f1SJim Ingham 
73f642373cSJim Ingham         BreakpointResolver::SetSCMatchesByLine (filter, sc_list, skip_prologue, m_regex.GetText());
74969795f1SJim Ingham     }
75969795f1SJim Ingham     assert (m_breakpoint != NULL);
76969795f1SJim Ingham 
77969795f1SJim Ingham     return Searcher::eCallbackReturnContinue;
78969795f1SJim Ingham }
79969795f1SJim Ingham 
80969795f1SJim Ingham Searcher::Depth
81969795f1SJim Ingham BreakpointResolverFileRegex::GetDepth()
82969795f1SJim Ingham {
83969795f1SJim Ingham     return Searcher::eDepthCompUnit;
84969795f1SJim Ingham }
85969795f1SJim Ingham 
86969795f1SJim Ingham void
87969795f1SJim Ingham BreakpointResolverFileRegex::GetDescription (Stream *s)
88969795f1SJim Ingham {
8987df91b8SJim Ingham     s->Printf ("source regex = \"%s\"", m_regex.GetText());
90969795f1SJim Ingham }
91969795f1SJim Ingham 
92969795f1SJim Ingham void
93969795f1SJim Ingham BreakpointResolverFileRegex::Dump (Stream *s) const
94969795f1SJim Ingham {
95969795f1SJim Ingham 
96969795f1SJim Ingham }
97969795f1SJim Ingham 
98*33df7cd3SJim Ingham lldb::BreakpointResolverSP
99*33df7cd3SJim Ingham BreakpointResolverFileRegex::CopyForBreakpoint (Breakpoint &breakpoint)
100*33df7cd3SJim Ingham {
101*33df7cd3SJim Ingham     lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileRegex(&breakpoint, m_regex));
102*33df7cd3SJim Ingham     return ret_sp;
103*33df7cd3SJim Ingham }
104*33df7cd3SJim Ingham 
105