Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 1 | //===-- BreakpointResolverFileRegex.cpp --------------------------*- C++ |
| 2 | //-*-===// |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
| 6 | // This file is distributed under the University of Illinois Open Source |
| 7 | // License. See LICENSE.TXT for details. |
| 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #include "lldb/Breakpoint/BreakpointResolverFileRegex.h" |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
| 15 | // Other libraries and framework includes |
| 16 | // Project includes |
| 17 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Log.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 19 | #include "lldb/Core/SourceManager.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 20 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/CompileUnit.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Target.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
| 26 | |
| 27 | //---------------------------------------------------------------------- |
| 28 | // BreakpointResolverFileRegex: |
| 29 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 30 | BreakpointResolverFileRegex::BreakpointResolverFileRegex( |
| 31 | Breakpoint *bkpt, RegularExpression ®ex, |
| 32 | const std::unordered_set<std::string> &func_names, bool exact_match) |
| 33 | : BreakpointResolver(bkpt, BreakpointResolver::FileLineResolver), |
| 34 | m_regex(regex), m_exact_match(exact_match), m_function_names(func_names) { |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 37 | BreakpointResolverFileRegex::~BreakpointResolverFileRegex() {} |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 38 | |
| 39 | Searcher::CallbackReturn |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 40 | BreakpointResolverFileRegex::SearchCallback(SearchFilter &filter, |
| 41 | SymbolContext &context, |
| 42 | Address *addr, bool containing) { |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 43 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 44 | assert(m_breakpoint != NULL); |
| 45 | if (!context.target_sp) |
| 46 | return eCallbackReturnContinue; |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 48 | CompileUnit *cu = context.comp_unit; |
| 49 | FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu)); |
| 50 | std::vector<uint32_t> line_matches; |
| 51 | context.target_sp->GetSourceManager().FindLinesMatchingRegex( |
| 52 | cu_file_spec, m_regex, 1, UINT32_MAX, line_matches); |
| 53 | |
| 54 | uint32_t num_matches = line_matches.size(); |
| 55 | for (uint32_t i = 0; i < num_matches; i++) { |
| 56 | SymbolContextList sc_list; |
| 57 | const bool search_inlines = false; |
| 58 | |
| 59 | cu->ResolveSymbolContext(cu_file_spec, line_matches[i], search_inlines, |
| 60 | m_exact_match, eSymbolContextEverything, sc_list); |
| 61 | // Find all the function names: |
| 62 | if (!m_function_names.empty()) { |
| 63 | std::vector<size_t> sc_to_remove; |
| 64 | for (size_t i = 0; i < sc_list.GetSize(); i++) { |
| 65 | SymbolContext sc_ctx; |
| 66 | sc_list.GetContextAtIndex(i, sc_ctx); |
| 67 | std::string name( |
| 68 | sc_ctx |
| 69 | .GetFunctionName( |
| 70 | Mangled::NamePreference::ePreferDemangledWithoutArguments) |
| 71 | .AsCString()); |
| 72 | if (!m_function_names.count(name)) { |
| 73 | sc_to_remove.push_back(i); |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 74 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 75 | } |
| 76 | |
| 77 | if (!sc_to_remove.empty()) { |
| 78 | std::vector<size_t>::reverse_iterator iter; |
| 79 | std::vector<size_t>::reverse_iterator rend = sc_to_remove.rend(); |
| 80 | for (iter = sc_to_remove.rbegin(); iter != rend; iter++) { |
| 81 | sc_list.RemoveContextAtIndex(*iter); |
| 82 | } |
| 83 | } |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 84 | } |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 86 | const bool skip_prologue = true; |
| 87 | |
| 88 | BreakpointResolver::SetSCMatchesByLine(filter, sc_list, skip_prologue, |
| 89 | m_regex.GetText()); |
| 90 | } |
| 91 | assert(m_breakpoint != NULL); |
| 92 | |
| 93 | return Searcher::eCallbackReturnContinue; |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 96 | Searcher::Depth BreakpointResolverFileRegex::GetDepth() { |
| 97 | return Searcher::eDepthCompUnit; |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 100 | void BreakpointResolverFileRegex::GetDescription(Stream *s) { |
| 101 | s->Printf("source regex = \"%s\", exact_match = %d", m_regex.GetText(), |
| 102 | m_exact_match); |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 105 | void BreakpointResolverFileRegex::Dump(Stream *s) const {} |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 106 | |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 107 | lldb::BreakpointResolverSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 108 | BreakpointResolverFileRegex::CopyForBreakpoint(Breakpoint &breakpoint) { |
| 109 | lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileRegex( |
| 110 | &breakpoint, m_regex, m_function_names, m_exact_match)); |
| 111 | return ret_sp; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 114 | void BreakpointResolverFileRegex::AddFunctionName(const char *func_name) { |
| 115 | m_function_names.insert(func_name); |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 116 | } |