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 
23969795f1SJim Ingham using namespace lldb;
24969795f1SJim Ingham using namespace lldb_private;
25969795f1SJim Ingham 
26969795f1SJim Ingham //----------------------------------------------------------------------
27969795f1SJim Ingham // BreakpointResolverFileRegex:
28969795f1SJim Ingham //----------------------------------------------------------------------
29969795f1SJim Ingham BreakpointResolverFileRegex::BreakpointResolverFileRegex
30969795f1SJim Ingham (
31969795f1SJim Ingham     Breakpoint *bkpt,
32*055ad9beSIlia K     RegularExpression &regex,
33*055ad9beSIlia K     bool exact_match
34969795f1SJim Ingham ) :
35969795f1SJim Ingham     BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
36*055ad9beSIlia K     m_regex (regex),
37*055ad9beSIlia K     m_exact_match (exact_match)
38969795f1SJim Ingham {
39969795f1SJim Ingham }
40969795f1SJim Ingham 
41969795f1SJim Ingham BreakpointResolverFileRegex::~BreakpointResolverFileRegex ()
42969795f1SJim Ingham {
43969795f1SJim Ingham }
44969795f1SJim Ingham 
45969795f1SJim Ingham Searcher::CallbackReturn
46969795f1SJim Ingham BreakpointResolverFileRegex::SearchCallback
47969795f1SJim Ingham (
48969795f1SJim Ingham     SearchFilter &filter,
49969795f1SJim Ingham     SymbolContext &context,
50969795f1SJim Ingham     Address *addr,
51969795f1SJim Ingham     bool containing
52969795f1SJim Ingham )
53969795f1SJim Ingham {
54969795f1SJim Ingham 
55969795f1SJim Ingham     assert (m_breakpoint != NULL);
56969795f1SJim Ingham     if (!context.target_sp)
57969795f1SJim Ingham         return eCallbackReturnContinue;
58969795f1SJim Ingham 
59969795f1SJim Ingham     CompileUnit *cu = context.comp_unit;
60969795f1SJim Ingham     FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
61969795f1SJim Ingham     std::vector<uint32_t> line_matches;
62969795f1SJim Ingham     context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
63f642373cSJim Ingham 
64969795f1SJim Ingham     uint32_t num_matches = line_matches.size();
65a297a97eSAndy Gibbs     for (uint32_t i = 0; i < num_matches; i++)
66969795f1SJim Ingham     {
67f642373cSJim Ingham         SymbolContextList sc_list;
68f642373cSJim Ingham         const bool search_inlines = false;
69969795f1SJim Ingham 
70*055ad9beSIlia K         cu->ResolveSymbolContext (cu_file_spec, line_matches[i], search_inlines, m_exact_match, 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 {
89*055ad9beSIlia K     s->Printf ("source regex = \"%s\", exact_match = %d", m_regex.GetText(), m_exact_match);
90969795f1SJim Ingham }
91969795f1SJim Ingham 
92969795f1SJim Ingham void
93969795f1SJim Ingham BreakpointResolverFileRegex::Dump (Stream *s) const
94969795f1SJim Ingham {
95969795f1SJim Ingham 
96969795f1SJim Ingham }
97969795f1SJim Ingham 
9833df7cd3SJim Ingham lldb::BreakpointResolverSP
9933df7cd3SJim Ingham BreakpointResolverFileRegex::CopyForBreakpoint (Breakpoint &breakpoint)
10033df7cd3SJim Ingham {
101*055ad9beSIlia K     lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileRegex(&breakpoint, m_regex, m_exact_match));
10233df7cd3SJim Ingham     return ret_sp;
10333df7cd3SJim Ingham }
10433df7cd3SJim Ingham 
105