blob: ae7f58acb91e29ee58b00093b2a69903cbb5be8b [file] [log] [blame]
Jim Ingham969795f2011-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"
Greg Clayton1f746072012-08-29 21:13:06 +000020#include "lldb/Symbol/CompileUnit.h"
Jim Ingham969795f2011-09-21 01:17:13 +000021#include "lldb/Target/Target.h"
Jim Ingham969795f2011-09-21 01:17:13 +000022
23using namespace lldb;
24using namespace lldb_private;
25
26//----------------------------------------------------------------------
27// BreakpointResolverFileRegex:
28//----------------------------------------------------------------------
29BreakpointResolverFileRegex::BreakpointResolverFileRegex
30(
31 Breakpoint *bkpt,
Ilia K055ad9b2015-05-18 13:41:01 +000032 RegularExpression &regex,
Jim Ingham76bb8d62016-04-28 01:40:57 +000033 const std::unordered_set<std::string> &func_names,
Ilia K055ad9b2015-05-18 13:41:01 +000034 bool exact_match
Jim Ingham969795f2011-09-21 01:17:13 +000035) :
36 BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
Ilia K055ad9b2015-05-18 13:41:01 +000037 m_regex (regex),
Jim Ingham76bb8d62016-04-28 01:40:57 +000038 m_exact_match (exact_match),
39 m_function_names(func_names)
Jim Ingham969795f2011-09-21 01:17:13 +000040{
41}
42
43BreakpointResolverFileRegex::~BreakpointResolverFileRegex ()
44{
45}
46
47Searcher::CallbackReturn
48BreakpointResolverFileRegex::SearchCallback
49(
50 SearchFilter &filter,
51 SymbolContext &context,
52 Address *addr,
53 bool containing
54)
55{
56
57 assert (m_breakpoint != NULL);
58 if (!context.target_sp)
59 return eCallbackReturnContinue;
Jim Ingham969795f2011-09-21 01:17:13 +000060
61 CompileUnit *cu = context.comp_unit;
62 FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu));
Jim Ingham87df91b2011-09-23 00:54:11 +000063 std::vector<uint32_t> line_matches;
Jim Inghamf6423732013-09-27 01:16:58 +000064 context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches);
65
Jim Ingham87df91b2011-09-23 00:54:11 +000066 uint32_t num_matches = line_matches.size();
Andy Gibbsa297a972013-06-19 19:04:53 +000067 for (uint32_t i = 0; i < num_matches; i++)
Jim Ingham969795f2011-09-21 01:17:13 +000068 {
Jim Inghamf6423732013-09-27 01:16:58 +000069 SymbolContextList sc_list;
70 const bool search_inlines = false;
Jim Ingham87df91b2011-09-23 00:54:11 +000071
Ilia K055ad9b2015-05-18 13:41:01 +000072 cu->ResolveSymbolContext (cu_file_spec, line_matches[i], search_inlines, m_exact_match, eSymbolContextEverything, sc_list);
Jim Ingham76bb8d62016-04-28 01:40:57 +000073 // Find all the function names:
74 if (!m_function_names.empty())
75 {
76 std::vector<size_t> sc_to_remove;
77 for (size_t i = 0; i < sc_list.GetSize(); i++)
78 {
79 SymbolContext sc_ctx;
80 sc_list.GetContextAtIndex(i, sc_ctx);
81 std::string name(sc_ctx.GetFunctionName(Mangled::NamePreference::ePreferDemangledWithoutArguments).AsCString());
82 if (!m_function_names.count(name))
83 {
84 sc_to_remove.push_back(i);
85 }
86 }
87
88 if (!sc_to_remove.empty())
89 {
90 std::vector<size_t>::reverse_iterator iter;
91 std::vector<size_t>::reverse_iterator rend = sc_to_remove.rend();
92 for (iter = sc_to_remove.rbegin(); iter != rend; iter++)
93 {
94 sc_list.RemoveContextAtIndex(*iter);
95 }
96 }
97 }
98
Jim Inghamf6423732013-09-27 01:16:58 +000099 const bool skip_prologue = true;
100
101 BreakpointResolver::SetSCMatchesByLine (filter, sc_list, skip_prologue, m_regex.GetText());
Jim Ingham969795f2011-09-21 01:17:13 +0000102 }
Jim Ingham87df91b2011-09-23 00:54:11 +0000103 assert (m_breakpoint != NULL);
104
Jim Ingham969795f2011-09-21 01:17:13 +0000105 return Searcher::eCallbackReturnContinue;
106}
107
108Searcher::Depth
109BreakpointResolverFileRegex::GetDepth()
110{
111 return Searcher::eDepthCompUnit;
112}
113
114void
115BreakpointResolverFileRegex::GetDescription (Stream *s)
116{
Ilia K055ad9b2015-05-18 13:41:01 +0000117 s->Printf ("source regex = \"%s\", exact_match = %d", m_regex.GetText(), m_exact_match);
Jim Ingham969795f2011-09-21 01:17:13 +0000118}
119
120void
121BreakpointResolverFileRegex::Dump (Stream *s) const
122{
123
124}
125
Jim Ingham33df7cd2014-12-06 01:28:03 +0000126lldb::BreakpointResolverSP
127BreakpointResolverFileRegex::CopyForBreakpoint (Breakpoint &breakpoint)
128{
Jim Ingham76bb8d62016-04-28 01:40:57 +0000129 lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileRegex(&breakpoint, m_regex, m_function_names, m_exact_match));
Jim Ingham33df7cd2014-12-06 01:28:03 +0000130 return ret_sp;
131}
132
Jim Ingham76bb8d62016-04-28 01:40:57 +0000133void
134BreakpointResolverFileRegex::AddFunctionName(const char *func_name)
135{
136 m_function_names.insert(func_name);
137}
138