1969795f1SJim Ingham //===-- BreakpointResolverFileRegex.cpp --------------------------*- C++ -*-===// 2969795f1SJim Ingham // 3969795f1SJim Ingham // The LLVM Compiler Infrastructure 4969795f1SJim Ingham // 5969795f1SJim Ingham // This file is distributed under the University of Illinois Open Source 6969795f1SJim Ingham // License. See LICENSE.TXT for details. 7969795f1SJim Ingham // 8969795f1SJim Ingham //===----------------------------------------------------------------------===// 9969795f1SJim Ingham 10969795f1SJim Ingham #include "lldb/Breakpoint/BreakpointResolverFileRegex.h" 11969795f1SJim Ingham 12969795f1SJim Ingham // C Includes 13969795f1SJim Ingham // C++ Includes 14969795f1SJim Ingham // Other libraries and framework includes 15969795f1SJim Ingham // Project includes 16969795f1SJim Ingham #include "lldb/Breakpoint/BreakpointLocation.h" 17969795f1SJim Ingham #include "lldb/Core/SourceManager.h" 18969795f1SJim Ingham #include "lldb/Core/Log.h" 19969795f1SJim Ingham #include "lldb/Core/StreamString.h" 20969795f1SJim Ingham #include "lldb/Target/Target.h" 21969795f1SJim Ingham #include "lldb/lldb-private-log.h" 22969795f1SJim Ingham 23969795f1SJim Ingham using namespace lldb; 24969795f1SJim Ingham using namespace lldb_private; 25969795f1SJim Ingham 26969795f1SJim Ingham //---------------------------------------------------------------------- 27969795f1SJim Ingham // BreakpointResolverFileRegex: 28969795f1SJim Ingham //---------------------------------------------------------------------- 29969795f1SJim Ingham BreakpointResolverFileRegex::BreakpointResolverFileRegex 30969795f1SJim Ingham ( 31969795f1SJim Ingham Breakpoint *bkpt, 32969795f1SJim Ingham RegularExpression ®ex 33969795f1SJim Ingham ) : 34969795f1SJim Ingham BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver), 35969795f1SJim Ingham m_regex (regex) 36969795f1SJim Ingham { 37969795f1SJim Ingham } 38969795f1SJim Ingham 39969795f1SJim Ingham BreakpointResolverFileRegex::~BreakpointResolverFileRegex () 40969795f1SJim Ingham { 41969795f1SJim Ingham } 42969795f1SJim Ingham 43969795f1SJim Ingham Searcher::CallbackReturn 44969795f1SJim Ingham BreakpointResolverFileRegex::SearchCallback 45969795f1SJim Ingham ( 46969795f1SJim Ingham SearchFilter &filter, 47969795f1SJim Ingham SymbolContext &context, 48969795f1SJim Ingham Address *addr, 49969795f1SJim Ingham bool containing 50969795f1SJim Ingham ) 51969795f1SJim Ingham { 52969795f1SJim Ingham 53969795f1SJim Ingham assert (m_breakpoint != NULL); 54969795f1SJim Ingham if (!context.target_sp) 55969795f1SJim Ingham return eCallbackReturnContinue; 56969795f1SJim Ingham 57969795f1SJim Ingham LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 58969795f1SJim Ingham 59969795f1SJim Ingham CompileUnit *cu = context.comp_unit; 60969795f1SJim Ingham FileSpec cu_file_spec = *(static_cast<FileSpec *>(cu)); 61969795f1SJim Ingham std::vector<uint32_t> line_matches; 62969795f1SJim Ingham context.target_sp->GetSourceManager().FindLinesMatchingRegex(cu_file_spec, m_regex, 1, UINT32_MAX, line_matches); 63969795f1SJim Ingham uint32_t num_matches = line_matches.size(); 64969795f1SJim Ingham for (int i = 0; i < num_matches; i++) 65969795f1SJim Ingham { 66969795f1SJim Ingham uint32_t start_idx = 0; 67*87df91b8SJim Ingham bool exact = false; 68969795f1SJim Ingham while (1) 69969795f1SJim Ingham { 70969795f1SJim Ingham LineEntry line_entry; 71969795f1SJim Ingham 72969795f1SJim Ingham // Cycle through all the line entries that might match this one: 73*87df91b8SJim Ingham start_idx = cu->FindLineEntry (start_idx, line_matches[i], NULL, exact, &line_entry); 74969795f1SJim Ingham if (start_idx == UINT32_MAX) 75969795f1SJim Ingham break; 76*87df91b8SJim Ingham exact = true; 77969795f1SJim Ingham start_idx++; 78969795f1SJim Ingham 79969795f1SJim Ingham Address line_start = line_entry.range.GetBaseAddress(); 80969795f1SJim Ingham if (line_start.IsValid()) 81969795f1SJim Ingham { 82969795f1SJim Ingham if (filter.AddressPasses(line_start)) 83969795f1SJim Ingham { 84969795f1SJim Ingham BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(line_start)); 85969795f1SJim Ingham if (log && bp_loc_sp && !m_breakpoint->IsInternal()) 86969795f1SJim Ingham { 87969795f1SJim Ingham StreamString s; 88969795f1SJim Ingham bp_loc_sp->GetDescription (&s, lldb::eDescriptionLevelVerbose); 89969795f1SJim Ingham log->Printf ("Added location: %s\n", s.GetData()); 90969795f1SJim Ingham } 91969795f1SJim Ingham } 92969795f1SJim Ingham else if (log) 93969795f1SJim Ingham { 94969795f1SJim Ingham log->Printf ("Breakpoint at file address 0x%llx for %s:%d didn't pass filter.\n", 95969795f1SJim Ingham line_start.GetFileAddress(), 96*87df91b8SJim Ingham cu_file_spec.GetFilename().AsCString("<Unknown>"), 97969795f1SJim Ingham line_matches[i]); 98969795f1SJim Ingham } 99969795f1SJim Ingham } 100969795f1SJim Ingham else 101969795f1SJim Ingham { 102969795f1SJim Ingham if (log) 103969795f1SJim Ingham log->Printf ("error: Unable to set breakpoint at file address 0x%llx for %s:%d\n", 104969795f1SJim Ingham line_start.GetFileAddress(), 105*87df91b8SJim Ingham cu_file_spec.GetFilename().AsCString("<Unknown>"), 106969795f1SJim Ingham line_matches[i]); 107969795f1SJim Ingham } 108969795f1SJim Ingham 109969795f1SJim Ingham } 110969795f1SJim Ingham } 111969795f1SJim Ingham assert (m_breakpoint != NULL); 112969795f1SJim Ingham 113969795f1SJim Ingham return Searcher::eCallbackReturnContinue; 114969795f1SJim Ingham } 115969795f1SJim Ingham 116969795f1SJim Ingham Searcher::Depth 117969795f1SJim Ingham BreakpointResolverFileRegex::GetDepth() 118969795f1SJim Ingham { 119969795f1SJim Ingham return Searcher::eDepthCompUnit; 120969795f1SJim Ingham } 121969795f1SJim Ingham 122969795f1SJim Ingham void 123969795f1SJim Ingham BreakpointResolverFileRegex::GetDescription (Stream *s) 124969795f1SJim Ingham { 125*87df91b8SJim Ingham s->Printf ("source regex = \"%s\"", m_regex.GetText()); 126969795f1SJim Ingham } 127969795f1SJim Ingham 128969795f1SJim Ingham void 129969795f1SJim Ingham BreakpointResolverFileRegex::Dump (Stream *s) const 130969795f1SJim Ingham { 131969795f1SJim Ingham 132969795f1SJim Ingham } 133969795f1SJim Ingham 134