1 //===-- AddressResolverFileLine.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/Core/AddressResolverFileLine.h"
11 
12 // Project includes
13 #include "lldb/Core/Log.h"
14 #include "lldb/Core/StreamString.h"
15 #include "lldb/lldb-private-log.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 //----------------------------------------------------------------------
21 // AddressResolverFileLine:
22 //----------------------------------------------------------------------
23 AddressResolverFileLine::AddressResolverFileLine
24 (
25     const FileSpec &file_spec,
26     uint32_t line_no,
27     bool check_inlines
28 ) :
29     AddressResolver (),
30     m_file_spec (file_spec),
31     m_line_number (line_no),
32     m_inlines (check_inlines)
33 {
34 }
35 
36 AddressResolverFileLine::~AddressResolverFileLine ()
37 {
38 }
39 
40 Searcher::CallbackReturn
41 AddressResolverFileLine::SearchCallback
42 (
43     SearchFilter &filter,
44     SymbolContext &context,
45     Address *addr,
46     bool containing
47 )
48 {
49     SymbolContextList sc_list;
50     uint32_t sc_list_size;
51     CompileUnit *cu = context.comp_unit;
52 
53     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
54 
55     sc_list_size = cu->ResolveSymbolContext (m_file_spec, m_line_number, m_inlines, false, eSymbolContextEverything,
56                                              sc_list);
57     for (uint32_t i = 0; i < sc_list_size; i++)
58     {
59         SymbolContext sc;
60         if (sc_list.GetContextAtIndex(i, sc))
61         {
62             Address line_start = sc.line_entry.range.GetBaseAddress();
63             addr_t byte_size = sc.line_entry.range.GetByteSize();
64             if (line_start.IsValid())
65             {
66                 AddressRange new_range (line_start, byte_size);
67                 m_address_ranges.push_back (new_range);
68                 if (log)
69                 {
70                     StreamString s;
71                     //new_bp_loc->GetDescription (&s, lldb::eDescriptionLevelVerbose);
72                     //log->Printf ("Added address: %s\n", s.GetData());
73                 }
74             }
75             else
76             {
77                 if (log)
78                   log->Printf ("error: Unable to resolve address at file address 0x%llx for %s:%d\n",
79                                line_start.GetFileAddress(),
80                                m_file_spec.GetFilename().AsCString("<Unknown>"),
81                                m_line_number);
82             }
83         }
84     }
85     return Searcher::eCallbackReturnContinue;
86 }
87 
88 Searcher::Depth
89 AddressResolverFileLine::GetDepth()
90 {
91     return Searcher::eDepthCompUnit;
92 }
93 
94 void
95 AddressResolverFileLine::GetDescription (Stream *s)
96 {
97     s->Printf ("File and line address - file: \"%s\" line: %u", m_file_spec.GetFilename().AsCString(), m_line_number);
98 }
99 
100 
101