1 //===-- BreakpointResolverFileLine.cpp --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Breakpoint/BreakpointResolverFileLine.h"
14 // Other libraries and framework includes
16 #include "lldb/Breakpoint/BreakpointLocation.h"
17 #include "lldb/Core/Log.h"
18 #include "lldb/Core/Module.h"
19 #include "lldb/Core/StreamString.h"
20 #include "lldb/Symbol/CompileUnit.h"
21 #include "lldb/Symbol/Function.h"
24 using namespace lldb_private;
26 //----------------------------------------------------------------------
27 // BreakpointResolverFileLine:
28 //----------------------------------------------------------------------
29 BreakpointResolverFileLine::BreakpointResolverFileLine
32 const FileSpec &file_spec,
38 BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
39 m_file_spec (file_spec),
40 m_line_number (line_no),
41 m_inlines (check_inlines),
42 m_skip_prologue(skip_prologue),
43 m_exact_match(exact_match)
47 BreakpointResolverFileLine::~BreakpointResolverFileLine ()
51 Searcher::CallbackReturn
52 BreakpointResolverFileLine::SearchCallback
55 SymbolContext &context,
60 SymbolContextList sc_list;
62 assert (m_breakpoint != NULL);
64 // There is a tricky bit here. You can have two compilation units that #include the same file, and
65 // 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
66 // other it isn't. If we considered the CU's independently, then in the second inclusion, we'd move the breakpoint
67 // to the next function that actually generated code in the header file. That would end up being confusing.
68 // So instead, we do the CU iterations by hand here, then scan through the complete list of matches, and figure out
69 // the closest line number match, and only set breakpoints on that match.
71 // Note also that if file_spec only had a file name and not a directory, there may be many different file spec's in
72 // the resultant list. The closest line match for one will not be right for some totally different file.
73 // So we go through the match list and pull out the sets that have the same file spec in their line_entry
74 // and treat each set separately.
76 const size_t num_comp_units = context.module_sp->GetNumCompileUnits();
77 for (size_t i = 0; i < num_comp_units; i++)
79 CompUnitSP cu_sp (context.module_sp->GetCompileUnitAtIndex (i));
82 if (filter.CompUnitPasses(*cu_sp))
83 cu_sp->ResolveSymbolContext (m_file_spec, m_line_number, m_inlines, m_exact_match, eSymbolContextEverything, sc_list);
87 s.Printf ("for %s:%d ",
88 m_file_spec.GetFilename().AsCString("<Unknown>"),
91 SetSCMatchesByLine (filter, sc_list, m_skip_prologue, s.GetData());
93 return Searcher::eCallbackReturnContinue;
97 BreakpointResolverFileLine::GetDepth()
99 return Searcher::eDepthModule;
103 BreakpointResolverFileLine::GetDescription (Stream *s)
105 s->Printf ("file = '%s', line = %u, exact_match = %d", m_file_spec.GetPath().c_str(), m_line_number, m_exact_match);
109 BreakpointResolverFileLine::Dump (Stream *s) const
114 lldb::BreakpointResolverSP
115 BreakpointResolverFileLine::CopyForBreakpoint (Breakpoint &breakpoint)
117 lldb::BreakpointResolverSP ret_sp(new BreakpointResolverFileLine(&breakpoint,