blob: 238c3709354bb291cf6ceabd2ae6bf5a5ae875a4 [file] [log] [blame]
Jim Ingham03c8ee52011-09-21 01:17:13 +00001//===-- 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/Target/Target.h"
21#include "lldb/lldb-private-log.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26//----------------------------------------------------------------------
27// BreakpointResolverFileRegex:
28//----------------------------------------------------------------------
29BreakpointResolverFileRegex::BreakpointResolverFileRegex
30(
31 Breakpoint *bkpt,
32 const FileSpec &file_spec,
33 RegularExpression &regex
34) :
35 BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
36 m_file_spec (file_spec),
37 m_regex (regex)
38{
39}
40
41BreakpointResolverFileRegex::~BreakpointResolverFileRegex ()
42{
43}
44
45Searcher::CallbackReturn
46BreakpointResolverFileRegex::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 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
60
61 CompileUnit *cu = context.comp_unit;
62 FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
63 if (cu_file_spec == m_file_spec
64 || (!m_file_spec.GetDirectory() && cu_file_spec.GetFilename() == m_file_spec.GetFilename()))
65 {
66 std::vector<uint32_t> line_matches;
67 context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
68 uint32_t num_matches = line_matches.size();
69 for (int i = 0; i < num_matches; i++)
70 {
71 uint32_t start_idx = 0;
72 while (1)
73 {
74 LineEntry line_entry;
75
76 // Cycle through all the line entries that might match this one:
77 start_idx = cu->FindLineEntry (start_idx, line_matches[i], NULL, &line_entry);
78 if (start_idx == UINT32_MAX)
79 break;
80 start_idx++;
81
82 Address line_start = line_entry.range.GetBaseAddress();
83 if (line_start.IsValid())
84 {
85 if (filter.AddressPasses(line_start))
86 {
87 BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(line_start));
88 if (log && bp_loc_sp && !m_breakpoint->IsInternal())
89 {
90 StreamString s;
91 bp_loc_sp->GetDescription (&s, lldb::eDescriptionLevelVerbose);
92 log->Printf ("Added location: %s\n", s.GetData());
93 }
94 }
95 else if (log)
96 {
97 log->Printf ("Breakpoint at file address 0x%llx for %s:%d didn't pass filter.\n",
98 line_start.GetFileAddress(),
99 m_file_spec.GetFilename().AsCString("<Unknown>"),
100 line_matches[i]);
101 }
102 }
103 else
104 {
105 if (log)
106 log->Printf ("error: Unable to set breakpoint at file address 0x%llx for %s:%d\n",
107 line_start.GetFileAddress(),
108 m_file_spec.GetFilename().AsCString("<Unknown>"),
109 line_matches[i]);
110 }
111
112 }
113 }
114 assert (m_breakpoint != NULL);
115 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
116
117
118 }
119 return Searcher::eCallbackReturnContinue;
120}
121
122Searcher::Depth
123BreakpointResolverFileRegex::GetDepth()
124{
125 return Searcher::eDepthCompUnit;
126}
127
128void
129BreakpointResolverFileRegex::GetDescription (Stream *s)
130{
131 s->Printf ("file ='%s', regular expression = \"%s\"", m_file_spec.GetFilename().AsCString(), m_regex.GetText());
132}
133
134void
135BreakpointResolverFileRegex::Dump (Stream *s) const
136{
137
138}
139