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"
18 #include "lldb/Core/StreamString.h"
19 #include "lldb/lldb-private-log.h"
20 
21 using namespace lldb;
22 using namespace lldb_private;
23 
24 //----------------------------------------------------------------------
25 // BreakpointResolverFileLine:
26 //----------------------------------------------------------------------
27 BreakpointResolverFileLine::BreakpointResolverFileLine
28 (
29     Breakpoint *bkpt,
30     const FileSpec &file_spec,
31     uint32_t line_no,
32     bool check_inlines
33 ) :
34     BreakpointResolver (bkpt, BreakpointResolver::FileLineResolver),
35     m_file_spec (file_spec),
36     m_line_number (line_no),
37     m_inlines (check_inlines)
38 {
39 }
40 
41 BreakpointResolverFileLine::~BreakpointResolverFileLine ()
42 {
43 }
44 
45 Searcher::CallbackReturn
46 BreakpointResolverFileLine::SearchCallback
47 (
48     SearchFilter &filter,
49     SymbolContext &context,
50     Address *addr,
51     bool containing
52 )
53 {
54     SymbolContextList sc_list;
55     uint32_t sc_list_size;
56     CompileUnit *cu = context.comp_unit;
57 
58     assert (m_breakpoint != NULL);
59     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
60 
61     sc_list_size = cu->ResolveSymbolContext (m_file_spec, m_line_number, m_inlines, false, eSymbolContextEverything, sc_list);
62     for (uint32_t i = 0; i < sc_list_size; i++)
63     {
64         SymbolContext sc;
65         if (sc_list.GetContextAtIndex(i, sc))
66         {
67             Address line_start = sc.line_entry.range.GetBaseAddress();
68             if (line_start.IsValid())
69             {
70                 if (filter.AddressPasses(line_start))
71                 {
72                     BreakpointLocationSP bp_loc_sp (m_breakpoint->AddLocation(line_start));
73                     if (log && bp_loc_sp && !m_breakpoint->IsInternal())
74                     {
75                         StreamString s;
76                         bp_loc_sp->GetDescription (&s, lldb::eDescriptionLevelVerbose);
77                         log->Printf ("Added location: %s\n", s.GetData());
78                     }
79                 }
80                 else if (log)
81                 {
82                     log->Printf ("Breakpoint at file address 0x%llx for %s:%d didn't pass the filter.\n",
83                                  line_start.GetFileAddress(),
84                                  m_file_spec.GetFilename().AsCString("<Unknown>"),
85                                  m_line_number);
86                 }
87             }
88             else
89             {
90                 if (log)
91                     log->Printf ("error: Unable to set breakpoint at file address 0x%llx for %s:%d\n",
92                                  line_start.GetFileAddress(),
93                                  m_file_spec.GetFilename().AsCString("<Unknown>"),
94                                  m_line_number);
95             }
96         }
97         else
98         {
99 #if 0
100             s << "error: Breakpoint at '" << pos->c_str() << "' isn't resolved yet: \n";
101             if (sc.line_entry.address.Dump(&s, Address::DumpStyleSectionNameOffset))
102                 s.EOL();
103             if (sc.line_entry.address.Dump(&s, Address::DumpStyleSectionPointerOffset))
104                 s.EOL();
105             if (sc.line_entry.address.Dump(&s, Address::DumpStyleFileAddress))
106                 s.EOL();
107             if (sc.line_entry.address.Dump(&s, Address::DumpStyleLoadAddress))
108                 s.EOL();
109 #endif
110         }
111     }
112     return Searcher::eCallbackReturnContinue;
113 }
114 
115 Searcher::Depth
116 BreakpointResolverFileLine::GetDepth()
117 {
118     return Searcher::eDepthCompUnit;
119 }
120 
121 void
122 BreakpointResolverFileLine::GetDescription (Stream *s)
123 {
124     s->Printf ("file ='%s', line = %u", m_file_spec.GetFilename().AsCString(), m_line_number);
125 }
126 
127 void
128 BreakpointResolverFileLine::Dump (Stream *s) const
129 {
130 
131 }
132 
133