blob: e4b596af55e6745116af63215c3a2c75ea6caea1 [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,
Jim Ingham03c8ee52011-09-21 01:17:13 +000032 RegularExpression &regex
33) :
34 BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
Jim Ingham03c8ee52011-09-21 01:17:13 +000035 m_regex (regex)
36{
37}
38
39BreakpointResolverFileRegex::~BreakpointResolverFileRegex ()
40{
41}
42
43Searcher::CallbackReturn
44BreakpointResolverFileRegex::SearchCallback
45(
46 SearchFilter &filter,
47 SymbolContext &context,
48 Address *addr,
49 bool containing
50)
51{
52
53 assert (m_breakpoint != NULL);
54 if (!context.target_sp)
55 return eCallbackReturnContinue;
56
57 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
58
59 CompileUnit *cu = context.comp_unit;
60 FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
Jim Inghamd6d47972011-09-23 00:54:11 +000061 std::vector<uint32_t> line_matches;
62 context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
63 uint32_t num_matches = line_matches.size();
64 for (int i = 0; i < num_matches; i++)
Jim Ingham03c8ee52011-09-21 01:17:13 +000065 {
Jim Inghamd6d47972011-09-23 00:54:11 +000066 uint32_t start_idx = 0;
67 bool exact = false;
68 while (1)
Jim Ingham03c8ee52011-09-21 01:17:13 +000069 {
Jim Inghamd6d47972011-09-23 00:54:11 +000070 LineEntry line_entry;
71
72 // Cycle through all the line entries that might match this one:
73 start_idx = cu->FindLineEntry (start_idx, line_matches[i], NULL, exact, &line_entry);
74 if (start_idx == UINT32_MAX)
75 break;
76 exact = true;
77 start_idx++;
Jim Ingham03c8ee52011-09-21 01:17:13 +000078
Jim Inghamd6d47972011-09-23 00:54:11 +000079 Address line_start = line_entry.range.GetBaseAddress();
80 if (line_start.IsValid())
81 {
82 if (filter.AddressPasses(line_start))
Jim Ingham03c8ee52011-09-21 01:17:13 +000083 {
Jim Inghamd6d47972011-09-23 00:54:11 +000084 BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(line_start));
85 if (log && bp_loc_sp && !m_breakpoint->IsInternal())
Jim Ingham03c8ee52011-09-21 01:17:13 +000086 {
Jim Inghamd6d47972011-09-23 00:54:11 +000087 StreamString s;
88 bp_loc_sp->GetDescription (&s, lldb::eDescriptionLevelVerbose);
89 log->Printf ("Added location: %s\n", s.GetData());
Jim Ingham03c8ee52011-09-21 01:17:13 +000090 }
91 }
Jim Inghamd6d47972011-09-23 00:54:11 +000092 else if (log)
Jim Ingham03c8ee52011-09-21 01:17:13 +000093 {
Jim Inghamd6d47972011-09-23 00:54:11 +000094 log->Printf ("Breakpoint at file address 0x%llx for %s:%d didn't pass filter.\n",
95 line_start.GetFileAddress(),
96 cu_file_spec.GetFilename().AsCString("<Unknown>"),
97 line_matches[i]);
Jim Ingham03c8ee52011-09-21 01:17:13 +000098 }
Jim Ingham03c8ee52011-09-21 01:17:13 +000099 }
Jim Inghamd6d47972011-09-23 00:54:11 +0000100 else
101 {
102 if (log)
103 log->Printf ("error: Unable to set breakpoint at file address 0x%llx for %s:%d\n",
104 line_start.GetFileAddress(),
105 cu_file_spec.GetFilename().AsCString("<Unknown>"),
106 line_matches[i]);
107 }
108
Jim Ingham03c8ee52011-09-21 01:17:13 +0000109 }
Jim Ingham03c8ee52011-09-21 01:17:13 +0000110 }
Jim Inghamd6d47972011-09-23 00:54:11 +0000111 assert (m_breakpoint != NULL);
112
Jim Ingham03c8ee52011-09-21 01:17:13 +0000113 return Searcher::eCallbackReturnContinue;
114}
115
116Searcher::Depth
117BreakpointResolverFileRegex::GetDepth()
118{
119 return Searcher::eDepthCompUnit;
120}
121
122void
123BreakpointResolverFileRegex::GetDescription (Stream *s)
124{
Jim Inghamd6d47972011-09-23 00:54:11 +0000125 s->Printf ("source regex = \"%s\"", m_regex.GetText());
Jim Ingham03c8ee52011-09-21 01:17:13 +0000126}
127
128void
129BreakpointResolverFileRegex::Dump (Stream *s) const
130{
131
132}
133