LLDB  mainline
AddressResolverFileLine.cpp
Go to the documentation of this file.
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 
10 
11 #include "lldb/Core/Address.h"
12 #include "lldb/Core/AddressRange.h"
14 #include "lldb/Symbol/LineEntry.h"
17 #include "lldb/Utility/Log.h"
18 #include "lldb/Utility/Logging.h"
19 #include "lldb/Utility/Stream.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  : AddressResolver(), m_src_location_spec(location_spec) {}
34 
36 
39  SymbolContext &context, Address *addr) {
40  SymbolContextList sc_list;
41  CompileUnit *cu = context.comp_unit;
42 
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(),
63  "<Unknown>"),
64  m_src_location_spec.GetLine().getValueOr(0));
65  }
66  }
67  }
69 }
70 
73 }
74 
76  s->Printf(
77  "File and line address - file: \"%s\" line: %u",
79  m_src_location_spec.GetLine().getValueOr(0));
80 }
lldb_private::SourceLocationSpec::GetFileSpec
FileSpec GetFileSpec() const
Definition: SourceLocationSpec.h:166
lldb_private::AddressRange::GetBaseAddress
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
lldb::eSearchDepthCompUnit
@ eSearchDepthCompUnit
Definition: lldb-enumerations.h:287
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
lldb_private::AddressResolver::m_address_ranges
std::vector< AddressRange > m_address_ranges
Definition: AddressResolver.h:55
lldb::SearchDepth
SearchDepth
Definition: lldb-enumerations.h:283
lldb_private::Address::IsValid
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:336
CompileUnit.h
lldb_private::SourceLocationSpec
Definition: SourceLocationSpec.h:27
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::AddressRange::GetByteSize
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:221
lldb_private::SymbolContextList
Definition: SymbolContext.h:379
lldb_private::SymbolContextList::GetContextAtIndex
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
Definition: SymbolContext.cpp:1262
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::CompileUnit
Definition: CompileUnit.h:38
lldb_private::AddressResolverFileLine::SearchCallback
Searcher::CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr) override
Definition: AddressResolverFileLine.cpp:38
lldb_private::SearchFilter
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
Log.h
LineEntry.h
lldb_private::AddressResolverFileLine::m_src_location_spec
SourceLocationSpec m_src_location_spec
Definition: AddressResolverFileLine.h:44
StreamString.h
lldb_private::Address::GetFileAddress
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:290
lldb_private::SymbolContextList::GetSize
uint32_t GetSize() const
Get accessor for a symbol context list size.
Definition: SymbolContext.cpp:1278
lldb_private::Searcher::CallbackReturn
CallbackReturn
Definition: SearchFilter.h:44
lldb_private::AddressResolverFileLine::GetDescription
void GetDescription(Stream *s) override
Prints a canonical description for the searcher to the stream s.
Definition: AddressResolverFileLine.cpp:75
lldb-enumerations.h
lldb_private::AddressRange
Definition: AddressRange.h:25
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
lldb_private::AddressResolverFileLine::GetDepth
lldb::SearchDepth GetDepth() override
Definition: AddressResolverFileLine.cpp:71
lldb_private::AddressResolver
General Outline: The AddressResolver is a Searcher.
Definition: AddressResolver.h:33
Address.h
lldb-types.h
lldb_private::AddressResolverFileLine::~AddressResolverFileLine
~AddressResolverFileLine() override
uint32_t
LIBLLDB_LOG_BREAKPOINTS
#define LIBLLDB_LOG_BREAKPOINTS
Definition: Logging.h:19
lldb_private::Address
Definition: Address.h:59
lldb_private::LineEntry::range
AddressRange range
The section offset address range for this line entry.
Definition: LineEntry.h:139
lldb_private::CompileUnit::ResolveSymbolContext
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list)
Resolve symbol contexts by file and line.
Definition: CompileUnit.cpp:248
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
SymbolContext.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
ConstString.h
Logging.h
Stream.h
lldb_private::Log
Definition: Log.h:49
lldb_private::SymbolContext::line_entry
LineEntry line_entry
The LineEntry for a given query.
Definition: SymbolContext.h:322
AddressResolverFileLine.h
AddressRange.h
lldb
Definition: SBAddress.h:15
lldb_private::FileSpec::GetFilename
ConstString & GetFilename()
Filename string get accessor.
Definition: FileSpec.cpp:341
lldb_private::SourceLocationSpec::GetLine
llvm::Optional< uint32_t > GetLine() const
Definition: SourceLocationSpec.cpp:69
lldb_private::Searcher::eCallbackReturnContinue
@ eCallbackReturnContinue
Definition: SearchFilter.h:46