xref: /src/contrib/llvm-project/lldb/source/Core/AddressResolverFileLine.cpp (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1cfca06d7SDimitry Andric //===-- AddressResolverFileLine.cpp ---------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f034231aSEd Maste #include "lldb/Core/AddressResolverFileLine.h"
10f034231aSEd Maste 
1194994d37SDimitry Andric #include "lldb/Core/Address.h"
1294994d37SDimitry Andric #include "lldb/Core/AddressRange.h"
13f034231aSEd Maste #include "lldb/Symbol/CompileUnit.h"
1494994d37SDimitry Andric #include "lldb/Symbol/LineEntry.h"
15f034231aSEd Maste #include "lldb/Symbol/SymbolContext.h"
1694994d37SDimitry Andric #include "lldb/Utility/ConstString.h"
17145449b1SDimitry Andric #include "lldb/Utility/LLDBLog.h"
1874a628f7SDimitry Andric #include "lldb/Utility/Log.h"
1994994d37SDimitry Andric #include "lldb/Utility/Stream.h"
2074a628f7SDimitry Andric #include "lldb/Utility/StreamString.h"
2194994d37SDimitry Andric #include "lldb/lldb-enumerations.h"
2294994d37SDimitry Andric #include "lldb/lldb-types.h"
2374a628f7SDimitry Andric 
24344a3780SDimitry Andric #include <cinttypes>
2594994d37SDimitry Andric #include <vector>
26f034231aSEd Maste 
27f034231aSEd Maste using namespace lldb;
28f034231aSEd Maste using namespace lldb_private;
29f034231aSEd Maste 
30f034231aSEd Maste // AddressResolverFileLine:
AddressResolverFileLine(SourceLocationSpec location_spec)31344a3780SDimitry Andric AddressResolverFileLine::AddressResolverFileLine(
32344a3780SDimitry Andric     SourceLocationSpec location_spec)
33344a3780SDimitry Andric     : AddressResolver(), m_src_location_spec(location_spec) {}
34f034231aSEd Maste 
35344a3780SDimitry Andric AddressResolverFileLine::~AddressResolverFileLine() = default;
36f034231aSEd Maste 
37f034231aSEd Maste Searcher::CallbackReturn
SearchCallback(SearchFilter & filter,SymbolContext & context,Address * addr)3814f1b3e8SDimitry Andric AddressResolverFileLine::SearchCallback(SearchFilter &filter,
39ead24645SDimitry Andric                                         SymbolContext &context, Address *addr) {
40f034231aSEd Maste   SymbolContextList sc_list;
41f034231aSEd Maste   CompileUnit *cu = context.comp_unit;
42f034231aSEd Maste 
43145449b1SDimitry Andric   Log *log = GetLog(LLDBLog::Breakpoints);
44f034231aSEd Maste 
45344a3780SDimitry Andric   // TODO: Handle SourceLocationSpec column information
46344a3780SDimitry Andric   cu->ResolveSymbolContext(m_src_location_spec, eSymbolContextEverything,
47344a3780SDimitry Andric                            sc_list);
487fa27ce4SDimitry Andric   for (const SymbolContext &sc : sc_list) {
49f034231aSEd Maste     Address line_start = sc.line_entry.range.GetBaseAddress();
50f034231aSEd Maste     addr_t byte_size = sc.line_entry.range.GetByteSize();
5114f1b3e8SDimitry Andric     if (line_start.IsValid()) {
52f034231aSEd Maste       AddressRange new_range(line_start, byte_size);
53f034231aSEd Maste       m_address_ranges.push_back(new_range);
5414f1b3e8SDimitry Andric     } else {
55ead24645SDimitry Andric       LLDB_LOGF(log,
5614f1b3e8SDimitry Andric                 "error: Unable to resolve address at file address 0x%" PRIx64
5714f1b3e8SDimitry Andric                 " for %s:%d\n",
58f034231aSEd Maste                 line_start.GetFileAddress(),
59344a3780SDimitry Andric                 m_src_location_spec.GetFileSpec().GetFilename().AsCString(
60344a3780SDimitry Andric                     "<Unknown>"),
61145449b1SDimitry Andric                 m_src_location_spec.GetLine().value_or(0));
62f034231aSEd Maste     }
63f034231aSEd Maste   }
64f034231aSEd Maste   return Searcher::eCallbackReturnContinue;
65f034231aSEd Maste }
66f034231aSEd Maste 
GetDepth()6794994d37SDimitry Andric lldb::SearchDepth AddressResolverFileLine::GetDepth() {
6894994d37SDimitry Andric   return lldb::eSearchDepthCompUnit;
69f034231aSEd Maste }
70f034231aSEd Maste 
GetDescription(Stream * s)7114f1b3e8SDimitry Andric void AddressResolverFileLine::GetDescription(Stream *s) {
72344a3780SDimitry Andric   s->Printf(
73344a3780SDimitry Andric       "File and line address - file: \"%s\" line: %u",
74344a3780SDimitry Andric       m_src_location_spec.GetFileSpec().GetFilename().AsCString("<Unknown>"),
75145449b1SDimitry Andric       m_src_location_spec.GetLine().value_or(0));
76f034231aSEd Maste }
77