]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Core/AddressResolverFileLine.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Core / AddressResolverFileLine.cpp
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 #include "lldb/Core/Address.h"
13 #include "lldb/Core/AddressRange.h"
14 #include "lldb/Symbol/CompileUnit.h"
15 #include "lldb/Symbol/LineEntry.h"
16 #include "lldb/Symbol/SymbolContext.h"
17 #include "lldb/Utility/ConstString.h"
18 #include "lldb/Utility/Log.h"
19 #include "lldb/Utility/Logging.h"
20 #include "lldb/Utility/Stream.h"
21 #include "lldb/Utility/StreamString.h"
22 #include "lldb/lldb-enumerations.h"
23 #include "lldb/lldb-types.h"
24
25 #include <inttypes.h>
26 #include <vector>
27
28 using namespace lldb;
29 using namespace lldb_private;
30
31 //----------------------------------------------------------------------
32 // AddressResolverFileLine:
33 //----------------------------------------------------------------------
34 AddressResolverFileLine::AddressResolverFileLine(const FileSpec &file_spec,
35                                                  uint32_t line_no,
36                                                  bool check_inlines)
37     : AddressResolver(), m_file_spec(file_spec), m_line_number(line_no),
38       m_inlines(check_inlines) {}
39
40 AddressResolverFileLine::~AddressResolverFileLine() {}
41
42 Searcher::CallbackReturn
43 AddressResolverFileLine::SearchCallback(SearchFilter &filter,
44                                         SymbolContext &context, Address *addr,
45                                         bool containing) {
46   SymbolContextList sc_list;
47   uint32_t sc_list_size;
48   CompileUnit *cu = context.comp_unit;
49
50   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
51
52   sc_list_size =
53       cu->ResolveSymbolContext(m_file_spec, m_line_number, m_inlines, false,
54                                eSymbolContextEverything, sc_list);
55   for (uint32_t i = 0; i < sc_list_size; i++) {
56     SymbolContext sc;
57     if (sc_list.GetContextAtIndex(i, sc)) {
58       Address line_start = sc.line_entry.range.GetBaseAddress();
59       addr_t byte_size = sc.line_entry.range.GetByteSize();
60       if (line_start.IsValid()) {
61         AddressRange new_range(line_start, byte_size);
62         m_address_ranges.push_back(new_range);
63         if (log) {
64           StreamString s;
65           // new_bp_loc->GetDescription (&s, lldb::eDescriptionLevelVerbose);
66           // log->Printf ("Added address: %s\n", s.GetData());
67         }
68       } else {
69         if (log)
70           log->Printf(
71               "error: Unable to resolve address at file address 0x%" PRIx64
72               " for %s:%d\n",
73               line_start.GetFileAddress(),
74               m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number);
75       }
76     }
77   }
78   return Searcher::eCallbackReturnContinue;
79 }
80
81 lldb::SearchDepth AddressResolverFileLine::GetDepth() {
82   return lldb::eSearchDepthCompUnit;
83 }
84
85 void AddressResolverFileLine::GetDescription(Stream *s) {
86   s->Printf("File and line address - file: \"%s\" line: %u",
87             m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number);
88 }