Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/AddressResolverFileLine.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- AddressResolverFileLine.cpp ---------------------------------------===//
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/LLDBLog.h"
18
#include "lldb/Utility/Log.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 <cinttypes>
25
#include <vector>
26
27
using namespace lldb;
28
using namespace lldb_private;
29
30
// AddressResolverFileLine:
31
AddressResolverFileLine::AddressResolverFileLine(
32
    SourceLocationSpec location_spec)
33
904
    : AddressResolver(), m_src_location_spec(location_spec) {}
34
35
904
AddressResolverFileLine::~AddressResolverFileLine() = default;
36
37
Searcher::CallbackReturn
38
AddressResolverFileLine::SearchCallback(SearchFilter &filter,
39
136
                                        SymbolContext &context, Address *addr) {
40
136
  SymbolContextList sc_list;
41
136
  CompileUnit *cu = context.comp_unit;
42
43
136
  Log *log = GetLog(LLDBLog::Breakpoints);
44
45
  // TODO: Handle SourceLocationSpec column information
46
136
  cu->ResolveSymbolContext(m_src_location_spec, eSymbolContextEverything,
47
136
                           sc_list);
48
136
  for (const SymbolContext &sc : sc_list) {
49
74
    Address line_start = sc.line_entry.range.GetBaseAddress();
50
74
    addr_t byte_size = sc.line_entry.range.GetByteSize();
51
74
    if (line_start.IsValid()) {
52
74
      AddressRange new_range(line_start, byte_size);
53
74
      m_address_ranges.push_back(new_range);
54
74
    } else {
55
0
      LLDB_LOGF(log,
56
0
                "error: Unable to resolve address at file address 0x%" PRIx64
57
0
                " for %s:%d\n",
58
0
                line_start.GetFileAddress(),
59
0
                m_src_location_spec.GetFileSpec().GetFilename().AsCString(
60
0
                    "<Unknown>"),
61
0
                m_src_location_spec.GetLine().value_or(0));
62
0
    }
63
74
  }
64
136
  return Searcher::eCallbackReturnContinue;
65
136
}
66
67
2.91k
lldb::SearchDepth AddressResolverFileLine::GetDepth() {
68
2.91k
  return lldb::eSearchDepthCompUnit;
69
2.91k
}
70
71
0
void AddressResolverFileLine::GetDescription(Stream *s) {
72
0
  s->Printf(
73
0
      "File and line address - file: \"%s\" line: %u",
74
0
      m_src_location_spec.GetFileSpec().GetFilename().AsCString("<Unknown>"),
75
0
      m_src_location_spec.GetLine().value_or(0));
76
0
}