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/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(
32 SourceLocationSpec location_spec)
33 : AddressResolver(), m_src_location_spec(location_spec) {}
34
35AddressResolverFileLine::~AddressResolverFileLine() {}
36
37Searcher::CallbackReturn
38AddressResolverFileLine::SearchCallback(SearchFilter &filter,
39 SymbolContext &context, Address *addr) {
40 SymbolContextList sc_list;
41 CompileUnit *cu = context.comp_unit;
42
43 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
44
45 // TODO: Handle SourceLocationSpec column information
46 cu->ResolveSymbolContext(m_src_location_spec, eSymbolContextEverything,
47 sc_list);
48 uint32_t sc_list_size = sc_list.GetSize();
49 for (uint32_t i = 0; i < sc_list_size; i++) {
50 SymbolContext sc;
51 if (sc_list.GetContextAtIndex(i, sc)) {
52 Address line_start = sc.line_entry.range.GetBaseAddress();
53 addr_t byte_size = sc.line_entry.range.GetByteSize();
54 if (line_start.IsValid()) {
55 AddressRange new_range(line_start, byte_size);
56 m_address_ranges.push_back(new_range);
57 } else {
58 LLDB_LOGF(log,
59 "error: Unable to resolve address at file address 0x%" PRIx64
60 " for %s:%d\n",
61 line_start.GetFileAddress(),
62 m_src_location_spec.GetFileSpec().GetFilename().AsCString(
63 "<Unknown>"),
64 m_src_location_spec.GetLine().getValueOr(0));
65 }
66 }
67 }
68 return Searcher::eCallbackReturnContinue;
69}
70
71lldb::SearchDepth AddressResolverFileLine::GetDepth() {
72 return lldb::eSearchDepthCompUnit;
73}
74
75void AddressResolverFileLine::GetDescription(Stream *s) {
76 s->Printf(
77 "File and line address - file: \"%s\" line: %u",
78 m_src_location_spec.GetFileSpec().GetFilename().AsCString("<Unknown>"),
79 m_src_location_spec.GetLine().getValueOr(0));
80}
81