LLDB mainline
BreakpointResolverAddress.cpp
Go to the documentation of this file.
1//===-- BreakpointResolverAddress.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
11#include "lldb/Core/Module.h"
12#include "lldb/Core/Section.h"
13#include "lldb/Target/Process.h"
14#include "lldb/Target/Target.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
21// BreakpointResolverAddress:
27
32
34 const StructuredData::Dictionary &options_dict, Status &error) {
35 llvm::StringRef module_name;
36 lldb::offset_t addr_offset;
37 FileSpec module_filespec;
38 bool success;
39
40 success = options_dict.GetValueForKeyAsInteger(
42 if (!success) {
44 "BRFL::CFSD: Couldn't find address offset entry.");
45 return nullptr;
46 }
47 Address address(addr_offset);
48
49 success = options_dict.HasKey(GetKey(OptionNames::ModuleName));
50 if (success) {
51 success = options_dict.GetValueForKeyAsString(
52 GetKey(OptionNames::ModuleName), module_name);
53 if (!success) {
55 "BRA::CFSD: Couldn't read module name entry.");
56 return nullptr;
57 }
58 module_filespec.SetFile(module_name, FileSpec::Style::native);
59 }
60 return std::make_shared<BreakpointResolverAddress>(nullptr, address,
61 module_filespec);
62}
63
66 StructuredData::DictionarySP options_dict_sp(
68 SectionSP section_sp = m_addr.GetSection();
69 if (section_sp) {
70 if (ModuleSP module_sp = section_sp->GetModule()) {
71 const FileSpec &module_fspec = module_sp->GetFileSpec();
72 options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
73 module_fspec.GetPath().c_str());
74 }
75 options_dict_sp->AddIntegerItem(GetKey(OptionNames::AddressOffset),
76 m_addr.GetOffset());
77 } else {
78 options_dict_sp->AddIntegerItem(GetKey(OptionNames::AddressOffset),
79 m_addr.GetOffset());
81 options_dict_sp->AddStringItem(GetKey(OptionNames::ModuleName),
82 m_module_filespec.GetPath());
83 }
84 }
85
86 return WrapOptionsDict(options_dict_sp);
87}
88
90 // If the address is not section relative, then we should not try to re-
91 // resolve it, it is just some random address and we wouldn't know what to do
92 // on reload. But if it is section relative, we need to re-resolve it since
93 // the section it's in may have shifted on re-run.
94 bool re_resolve = false;
95 if (m_addr.GetSection() || m_module_filespec)
96 re_resolve = true;
97 else if (GetBreakpoint()->GetNumLocations() == 0)
98 re_resolve = true;
99
100 if (re_resolve)
102}
103
105 SearchFilter &filter, ModuleList &modules) {
106 // See comment in ResolveBreakpoint.
107 bool re_resolve = false;
108 if (m_addr.GetSection())
109 re_resolve = true;
110 else if (GetBreakpoint()->GetNumLocations() == 0)
111 re_resolve = true;
112
113 if (re_resolve)
115}
116
118 SearchFilter &filter, SymbolContext &context, Address *addr) {
120 BreakpointSP breakpoint_sp = GetBreakpoint();
121 Breakpoint &breakpoint = *breakpoint_sp;
122
123 if (filter.AddressPasses(m_addr)) {
124 if (breakpoint.GetNumLocations() == 0) {
125 // If the address is just an offset, and we're given a module, see if we
126 // can find the appropriate module loaded in the binary, and fix up
127 // m_addr to use that.
128 if (!m_addr.IsSectionOffset() && m_module_filespec) {
129 Target &target = breakpoint.GetTarget();
130 ModuleSpec module_spec(m_module_filespec);
131 ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec);
132 if (module_sp) {
133 Address tmp_address;
134 if (module_sp->ResolveFileAddress(m_addr.GetOffset(), tmp_address))
135 m_addr = tmp_address;
136 else
138 } else {
139 // If we didn't find the module, then we can't resolve the address.
141 }
142 }
143
144 m_resolved_addr = m_addr.GetLoadAddress(&breakpoint.GetTarget());
146 if (bp_loc_sp && !breakpoint.IsInternal()) {
147 StreamString s;
148 bp_loc_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
149 LLDB_LOGF(log, "Added location: %s\n", s.GetData());
150 }
151 } else {
152 BreakpointLocationSP loc_sp = breakpoint.GetLocationAtIndex(0);
153 lldb::addr_t cur_load_location =
154 m_addr.GetLoadAddress(&breakpoint.GetTarget());
155 if (cur_load_location != m_resolved_addr) {
156 m_resolved_addr = cur_load_location;
157 if (llvm::Error error = loc_sp->ClearBreakpointSite())
158 LLDB_LOG_ERROR(log, std::move(error), "{0}");
159 if (llvm::Error error = loc_sp->ResolveBreakpointSite())
160 LLDB_LOG_ERROR(log, std::move(error), "{0}");
161 }
162 }
163 }
165}
166
170
172 s->PutCString("address = ");
173 m_addr.Dump(s, GetBreakpoint()->GetTarget().GetProcessSP().get(),
176}
177
179
183 new BreakpointResolverAddress(breakpoint, m_addr));
184 return ret_sp;
185}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
A section + offset based address class.
Definition Address.h:62
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition Address.h:93
@ DumpStyleLoadAddress
Display as the load address (if resolved).
Definition Address.h:99
StructuredData::ObjectSP SerializeToStructuredData() override
Searcher::CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr) override
void GetDescription(Stream *s) override
Prints a canonical description for the breakpoint to the stream s.
static lldb::BreakpointResolverSP CreateFromStructuredData(const StructuredData::Dictionary &options_dict, Status &error)
lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP &breakpoint) override
void ResolveBreakpointInModules(SearchFilter &filter, ModuleList &modules) override
In response to this method the resolver scans the modules in the module list modules,...
void ResolveBreakpoint(SearchFilter &filter) override
In response to this method the resolver scans all the modules in the breakpoint's target,...
BreakpointResolverAddress(const lldb::BreakpointSP &bkpt, const Address &addr)
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
lldb::BreakpointLocationSP AddLocation(Address loc_addr, bool *new_location=nullptr)
static const char * GetKey(OptionNames enum_value)
StructuredData::DictionarySP WrapOptionsDict(StructuredData::DictionarySP options_dict_sp)
lldb::BreakpointSP GetBreakpoint() const
This gets the breakpoint for this resolver.
virtual void ResolveBreakpointInModules(SearchFilter &filter, ModuleList &modules)
In response to this method the resolver scans the modules in the module list modules,...
virtual void ResolveBreakpoint(SearchFilter &filter)
In response to this method the resolver scans all the modules in the breakpoint's target,...
BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType, lldb::addr_t offset=0, bool offset_is_insn_count=false)
The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint to make sense.
lldb::BreakpointLocationSP GetLocationAtIndex(size_t index)
Get breakpoint locations by index.
Target & GetTarget()
Accessor for the breakpoint Target.
Definition Breakpoint.h:459
size_t GetNumLocations() const
Return the number of breakpoint locations.
bool IsInternal() const
Tell whether this breakpoint is an "internal" breakpoint.
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
A collection class for Module objects.
Definition ModuleList.h:104
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Finds the first module whose file specification matches module_spec.
General Outline: Provides the callback and search depth for the SearchFilter search.
virtual bool AddressPasses(Address &addr)
Call this method with a Address to see if address passes the filter.
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
const char * GetData() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool HasKey(llvm::StringRef key) const
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1014
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
@ eDescriptionLevelVerbose
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP