1ac7ddfbfSEd Maste //===-- AddressResolverFileLine.cpp -----------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/Core/AddressResolverFileLine.h"
11ac7ddfbfSEd Maste 
12*b5893f02SDimitry Andric #include "lldb/Core/Address.h"
13*b5893f02SDimitry Andric #include "lldb/Core/AddressRange.h"
14ac7ddfbfSEd Maste #include "lldb/Symbol/CompileUnit.h"
15*b5893f02SDimitry Andric #include "lldb/Symbol/LineEntry.h"
16ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolContext.h"
17*b5893f02SDimitry Andric #include "lldb/Utility/ConstString.h"
18f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
19*b5893f02SDimitry Andric #include "lldb/Utility/Logging.h"
20*b5893f02SDimitry Andric #include "lldb/Utility/Stream.h"
21f678e45dSDimitry Andric #include "lldb/Utility/StreamString.h"
22*b5893f02SDimitry Andric #include "lldb/lldb-enumerations.h"
23*b5893f02SDimitry Andric #include "lldb/lldb-types.h"
24f678e45dSDimitry Andric 
25*b5893f02SDimitry Andric #include <inttypes.h>
26*b5893f02SDimitry Andric #include <vector>
27ac7ddfbfSEd Maste 
28ac7ddfbfSEd Maste using namespace lldb;
29ac7ddfbfSEd Maste using namespace lldb_private;
30ac7ddfbfSEd Maste 
31ac7ddfbfSEd Maste //----------------------------------------------------------------------
32ac7ddfbfSEd Maste // AddressResolverFileLine:
33ac7ddfbfSEd Maste //----------------------------------------------------------------------
AddressResolverFileLine(const FileSpec & file_spec,uint32_t line_no,bool check_inlines)34435933ddSDimitry Andric AddressResolverFileLine::AddressResolverFileLine(const FileSpec &file_spec,
35ac7ddfbfSEd Maste                                                  uint32_t line_no,
36435933ddSDimitry Andric                                                  bool check_inlines)
37435933ddSDimitry Andric     : AddressResolver(), m_file_spec(file_spec), m_line_number(line_no),
38435933ddSDimitry Andric       m_inlines(check_inlines) {}
39ac7ddfbfSEd Maste 
~AddressResolverFileLine()40435933ddSDimitry Andric AddressResolverFileLine::~AddressResolverFileLine() {}
41ac7ddfbfSEd Maste 
42ac7ddfbfSEd Maste Searcher::CallbackReturn
SearchCallback(SearchFilter & filter,SymbolContext & context,Address * addr,bool containing)43435933ddSDimitry Andric AddressResolverFileLine::SearchCallback(SearchFilter &filter,
44435933ddSDimitry Andric                                         SymbolContext &context, Address *addr,
45435933ddSDimitry Andric                                         bool containing) {
46ac7ddfbfSEd Maste   SymbolContextList sc_list;
47ac7ddfbfSEd Maste   uint32_t sc_list_size;
48ac7ddfbfSEd Maste   CompileUnit *cu = context.comp_unit;
49ac7ddfbfSEd Maste 
50ac7ddfbfSEd Maste   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
51ac7ddfbfSEd Maste 
52435933ddSDimitry Andric   sc_list_size =
53435933ddSDimitry Andric       cu->ResolveSymbolContext(m_file_spec, m_line_number, m_inlines, false,
54435933ddSDimitry Andric                                eSymbolContextEverything, sc_list);
55435933ddSDimitry Andric   for (uint32_t i = 0; i < sc_list_size; i++) {
56ac7ddfbfSEd Maste     SymbolContext sc;
57435933ddSDimitry Andric     if (sc_list.GetContextAtIndex(i, sc)) {
58ac7ddfbfSEd Maste       Address line_start = sc.line_entry.range.GetBaseAddress();
59ac7ddfbfSEd Maste       addr_t byte_size = sc.line_entry.range.GetByteSize();
60435933ddSDimitry Andric       if (line_start.IsValid()) {
61ac7ddfbfSEd Maste         AddressRange new_range(line_start, byte_size);
62ac7ddfbfSEd Maste         m_address_ranges.push_back(new_range);
63435933ddSDimitry Andric         if (log) {
64ac7ddfbfSEd Maste           StreamString s;
65ac7ddfbfSEd Maste           // new_bp_loc->GetDescription (&s, lldb::eDescriptionLevelVerbose);
66ac7ddfbfSEd Maste           // log->Printf ("Added address: %s\n", s.GetData());
67ac7ddfbfSEd Maste         }
68435933ddSDimitry Andric       } else {
69ac7ddfbfSEd Maste         if (log)
70435933ddSDimitry Andric           log->Printf(
71435933ddSDimitry Andric               "error: Unable to resolve address at file address 0x%" PRIx64
72435933ddSDimitry Andric               " for %s:%d\n",
73ac7ddfbfSEd Maste               line_start.GetFileAddress(),
74435933ddSDimitry Andric               m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number);
75ac7ddfbfSEd Maste       }
76ac7ddfbfSEd Maste     }
77ac7ddfbfSEd Maste   }
78ac7ddfbfSEd Maste   return Searcher::eCallbackReturnContinue;
79ac7ddfbfSEd Maste }
80ac7ddfbfSEd Maste 
GetDepth()81*b5893f02SDimitry Andric lldb::SearchDepth AddressResolverFileLine::GetDepth() {
82*b5893f02SDimitry Andric   return lldb::eSearchDepthCompUnit;
83ac7ddfbfSEd Maste }
84ac7ddfbfSEd Maste 
GetDescription(Stream * s)85435933ddSDimitry Andric void AddressResolverFileLine::GetDescription(Stream *s) {
86435933ddSDimitry Andric   s->Printf("File and line address - file: \"%s\" line: %u",
87435933ddSDimitry Andric             m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number);
88ac7ddfbfSEd Maste }
89