1//===-- AddressResolverFileLine.cpp -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Core/AddressResolverFileLine.h"
10
11#include "lldb/Core/Address.h"
12#include "lldb/Core/AddressRange.h"
13#include "lldb/Symbol/CompileUnit.h"
14#include "lldb/Symbol/LineEntry.h"
15#include "lldb/Symbol/SymbolContext.h"
16#include "lldb/Utility/ConstString.h"
17#include "lldb/Utility/Log.h"
18#include "lldb/Utility/Logging.h"
19#include "lldb/Utility/Stream.h"
20#include "lldb/Utility/StreamString.h"
21#include "lldb/lldb-enumerations.h"
22#include "lldb/lldb-types.h"
23
24#include <inttypes.h>
25#include <vector>
26
27using namespace lldb;
28using namespace lldb_private;
29
30// AddressResolverFileLine:
31AddressResolverFileLine::AddressResolverFileLine(const FileSpec &file_spec,
32                                                 uint32_t line_no,
33                                                 bool check_inlines)
34    : AddressResolver(), m_file_spec(file_spec), m_line_number(line_no),
35      m_inlines(check_inlines) {}
36
37AddressResolverFileLine::~AddressResolverFileLine() {}
38
39Searcher::CallbackReturn
40AddressResolverFileLine::SearchCallback(SearchFilter &filter,
41                                        SymbolContext &context, Address *addr) {
42  SymbolContextList sc_list;
43  CompileUnit *cu = context.comp_unit;
44
45  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
46
47  cu->ResolveSymbolContext(m_file_spec, m_line_number, m_inlines, false,
48                           eSymbolContextEverything, sc_list);
49  uint32_t sc_list_size = sc_list.GetSize();
50  for (uint32_t i = 0; i < sc_list_size; i++) {
51    SymbolContext sc;
52    if (sc_list.GetContextAtIndex(i, sc)) {
53      Address line_start = sc.line_entry.range.GetBaseAddress();
54      addr_t byte_size = sc.line_entry.range.GetByteSize();
55      if (line_start.IsValid()) {
56        AddressRange new_range(line_start, byte_size);
57        m_address_ranges.push_back(new_range);
58        if (log) {
59          StreamString s;
60          // new_bp_loc->GetDescription (&s, lldb::eDescriptionLevelVerbose);
61          // LLDB_LOGF(log, "Added address: %s\n", s.GetData());
62        }
63      } else {
64        LLDB_LOGF(log,
65                  "error: Unable to resolve address at file address 0x%" PRIx64
66                  " for %s:%d\n",
67                  line_start.GetFileAddress(),
68                  m_file_spec.GetFilename().AsCString("<Unknown>"),
69                  m_line_number);
70      }
71    }
72  }
73  return Searcher::eCallbackReturnContinue;
74}
75
76lldb::SearchDepth AddressResolverFileLine::GetDepth() {
77  return lldb::eSearchDepthCompUnit;
78}
79
80void AddressResolverFileLine::GetDescription(Stream *s) {
81  s->Printf("File and line address - file: \"%s\" line: %u",
82            m_file_spec.GetFilename().AsCString("<Unknown>"), m_line_number);
83}
84