Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 1 | //===-- 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 Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/CompileUnit.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Target.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace lldb; |
| 24 | using namespace lldb_private; |
| 25 | |
| 26 | //---------------------------------------------------------------------- |
| 27 | // BreakpointResolverFileRegex: |
| 28 | //---------------------------------------------------------------------- |
| 29 | BreakpointResolverFileRegex::BreakpointResolverFileRegex |
| 30 | ( |
| 31 | Breakpoint *bkpt, |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 32 | RegularExpression ®ex, |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 33 | const std::unordered_set<std::string> &func_names, |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 34 | bool exact_match |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 35 | ) : |
| 36 | BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver), |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 37 | m_regex (regex), |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 38 | m_exact_match (exact_match), |
| 39 | m_function_names(func_names) |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
| 43 | BreakpointResolverFileRegex::~BreakpointResolverFileRegex () |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | Searcher::CallbackReturn |
| 48 | BreakpointResolverFileRegex::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 Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 60 | |
| 61 | CompileUnit *cu = context.comp_unit; |
| 62 | FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu)); |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 63 | std::vector<uint32_t> line_matches; |
Jim Ingham | f642373 | 2013-09-27 01:16:58 +0000 | [diff] [blame] | 64 | context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches); |
| 65 | |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 66 | uint32_t num_matches = line_matches.size(); |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 67 | for (uint32_t i = 0; i < num_matches; i++) |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 68 | { |
Jim Ingham | f642373 | 2013-09-27 01:16:58 +0000 | [diff] [blame] | 69 | SymbolContextList sc_list; |
| 70 | const bool search_inlines = false; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 71 | |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 72 | cu->ResolveSymbolContext (cu_file_spec, line_matches[i], search_inlines, m_exact_match, eSymbolContextEverything, sc_list); |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 73 | // 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 Ingham | f642373 | 2013-09-27 01:16:58 +0000 | [diff] [blame] | 99 | const bool skip_prologue = true; |
| 100 | |
| 101 | BreakpointResolver::SetSCMatchesByLine (filter, sc_list, skip_prologue, m_regex.GetText()); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 102 | } |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 103 | assert (m_breakpoint != NULL); |
| 104 | |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 105 | return Searcher::eCallbackReturnContinue; |
| 106 | } |
| 107 | |
| 108 | Searcher::Depth |
| 109 | BreakpointResolverFileRegex::GetDepth() |
| 110 | { |
| 111 | return Searcher::eDepthCompUnit; |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | BreakpointResolverFileRegex::GetDescription (Stream *s) |
| 116 | { |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 117 | s->Printf ("source regex = \"%s\", exact_match = %d", m_regex.GetText(), m_exact_match); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void |
| 121 | BreakpointResolverFileRegex::Dump (Stream *s) const |
| 122 | { |
| 123 | |
| 124 | } |
| 125 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 126 | lldb::BreakpointResolverSP |
| 127 | BreakpointResolverFileRegex::CopyForBreakpoint (Breakpoint &breakpoint) |
| 128 | { |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 129 | lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileRegex(&breakpoint, m_regex, m_function_names, m_exact_match)); |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 130 | return ret_sp; |
| 131 | } |
| 132 | |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 133 | void |
| 134 | BreakpointResolverFileRegex::AddFunctionName(const char *func_name) |
| 135 | { |
| 136 | m_function_names.insert(func_name); |
| 137 | } |
| 138 | |