| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- BreakpointResolverFileLine.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/BreakpointResolverFileLine.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/Log.h" |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Module.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/StreamString.h" |
| Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/CompileUnit.h" |
| 21 | #include "lldb/Symbol/Function.h" |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/lldb-private-log.h" |
| 23 | |
| 24 | using namespace lldb; |
| 25 | using namespace lldb_private; |
| 26 | |
| 27 | //---------------------------------------------------------------------- |
| 28 | // BreakpointResolverFileLine: |
| 29 | //---------------------------------------------------------------------- |
| 30 | BreakpointResolverFileLine::BreakpointResolverFileLine |
| 31 | ( |
| 32 | Breakpoint *bkpt, |
| 33 | const FileSpec &file_spec, |
| 34 | uint32_t line_no, |
| Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 35 | bool check_inlines, |
| 36 | bool skip_prologue |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | ) : |
| Johnny Chen | b7234e4 | 2010-10-28 17:27:46 +0000 | [diff] [blame] | 38 | BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver), |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | m_file_spec (file_spec), |
| 40 | m_line_number (line_no), |
| Jim Ingham | a8558b6 | 2012-05-22 00:12:20 +0000 | [diff] [blame] | 41 | m_inlines (check_inlines), |
| 42 | m_skip_prologue(skip_prologue) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | BreakpointResolverFileLine::~BreakpointResolverFileLine () |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | Searcher::CallbackReturn |
| 51 | BreakpointResolverFileLine::SearchCallback |
| 52 | ( |
| 53 | SearchFilter &filter, |
| 54 | SymbolContext &context, |
| 55 | Address *addr, |
| 56 | bool containing |
| 57 | ) |
| 58 | { |
| 59 | SymbolContextList sc_list; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | |
| 61 | assert (m_breakpoint != NULL); |
| Jim Ingham | bc2f918 | 2012-01-13 02:04:05 +0000 | [diff] [blame] | 62 | |
| 63 | // There is a tricky bit here. You can have two compilation units that #include the same file, and |
| 64 | // in one of them the function at m_line_number is used (and so code and a line entry for it is generated) but in the |
| 65 | // other it isn't. If we considered the CU's independently, then in the second inclusion, we'd move the breakpoint |
| 66 | // to the next function that actually generated code in the header file. That would end up being confusing. |
| 67 | // So instead, we do the CU iterations by hand here, then scan through the complete list of matches, and figure out |
| 68 | // the closest line number match, and only set breakpoints on that match. |
| 69 | |
| 70 | // Note also that if file_spec only had a file name and not a directory, there may be many different file spec's in |
| 71 | // the resultant list. The closest line match for one will not be right for some totally different file. |
| 72 | // So we go through the match list and pull out the sets that have the same file spec in their line_entry |
| 73 | // and treat each set separately. |
| 74 | |
| Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 75 | const size_t num_comp_units = context.module_sp->GetNumCompileUnits(); |
| 76 | for (size_t i = 0; i < num_comp_units; i++) |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | { |
| Jim Ingham | bc2f918 | 2012-01-13 02:04:05 +0000 | [diff] [blame] | 78 | CompUnitSP cu_sp (context.module_sp->GetCompileUnitAtIndex (i)); |
| Greg Clayton | 2dafd8e | 2012-04-23 22:00:21 +0000 | [diff] [blame] | 79 | if (cu_sp) |
| 80 | { |
| 81 | if (filter.CompUnitPasses(*cu_sp)) |
| 82 | cu_sp->ResolveSymbolContext (m_file_spec, m_line_number, m_inlines, false, eSymbolContextEverything, sc_list); |
| 83 | } |
| Jim Ingham | bc2f918 | 2012-01-13 02:04:05 +0000 | [diff] [blame] | 84 | } |
| Jim Ingham | f642373 | 2013-09-27 01:16:58 +0000 | [diff] [blame] | 85 | StreamString s; |
| 86 | s.Printf ("for %s:%d ", |
| 87 | m_file_spec.GetFilename().AsCString("<Unknown>"), |
| 88 | m_line_number); |
| Jim Ingham | bc2f918 | 2012-01-13 02:04:05 +0000 | [diff] [blame] | 89 | |
| Jim Ingham | f642373 | 2013-09-27 01:16:58 +0000 | [diff] [blame] | 90 | SetSCMatchesByLine (filter, sc_list, m_skip_prologue, s.GetData()); |
| 91 | |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | return Searcher::eCallbackReturnContinue; |
| 93 | } |
| 94 | |
| 95 | Searcher::Depth |
| 96 | BreakpointResolverFileLine::GetDepth() |
| 97 | { |
| Jim Ingham | bc2f918 | 2012-01-13 02:04:05 +0000 | [diff] [blame] | 98 | return Searcher::eDepthModule; |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void |
| 102 | BreakpointResolverFileLine::GetDescription (Stream *s) |
| 103 | { |
| Greg Clayton | 405fab9 | 2013-06-13 19:39:56 +0000 | [diff] [blame] | 104 | s->Printf ("file = '%s', line = %u", m_file_spec.GetPath().c_str(), m_line_number); |
| Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void |
| 108 | BreakpointResolverFileLine::Dump (Stream *s) const |
| 109 | { |
| 110 | |
| 111 | } |
| 112 | |