LLDB  mainline
BreakpointResolver.h
Go to the documentation of this file.
1 //===-- BreakpointResolver.h ------------------------------------*- C++ -*-===//
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 #ifndef LLDB_BREAKPOINT_BREAKPOINTRESOLVER_H
10 #define LLDB_BREAKPOINT_BREAKPOINTRESOLVER_H
11 
13 #include "lldb/Core/Address.h"
14 #include "lldb/Core/SearchFilter.h"
16 #include "lldb/Utility/FileSpec.h"
18 #include "lldb/lldb-private.h"
19 
20 namespace lldb_private {
21 
22 /// \class BreakpointResolver BreakpointResolver.h
23 /// "lldb/Breakpoint/BreakpointResolver.h" This class works with SearchFilter
24 /// to resolve logical breakpoints to their of concrete breakpoint locations.
25 
26 /// General Outline:
27 /// The BreakpointResolver is a Searcher. In that protocol, the SearchFilter
28 /// asks the question "At what depth of the symbol context descent do you want
29 /// your callback to get called?" of the filter. The resolver answers this
30 /// question (in the GetDepth method) and provides the resolution callback.
31 /// Each Breakpoint has a BreakpointResolver, and it calls either
32 /// ResolveBreakpoint or ResolveBreakpointInModules to tell it to look for new
33 /// breakpoint locations.
34 
35 class BreakpointResolver : public Searcher {
36  friend class Breakpoint;
37 
38 public:
39  /// The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint
40  /// to make sense. It can be constructed without a breakpoint, but you have
41  /// to call SetBreakpoint before ResolveBreakpoint.
42  ///
43  /// \param[in] bkpt
44  /// The breakpoint that owns this resolver.
45  /// \param[in] resolverType
46  /// The concrete breakpoint resolver type for this breakpoint.
47  BreakpointResolver(const lldb::BreakpointSP &bkpt,
48  unsigned char resolverType,
49  lldb::addr_t offset = 0);
50 
51  /// The Destructor is virtual, all significant breakpoint resolvers derive
52  /// from this class.
53  ~BreakpointResolver() override;
54 
55  /// This sets the breakpoint for this resolver.
56  ///
57  /// \param[in] bkpt
58  /// The breakpoint that owns this resolver.
59  void SetBreakpoint(const lldb::BreakpointSP &bkpt);
60 
61  /// This gets the breakpoint for this resolver.
62  lldb::BreakpointSP GetBreakpoint() const {
63  auto breakpoint_sp = m_breakpoint.expired() ? lldb::BreakpointSP() :
64  m_breakpoint.lock();
65  assert(breakpoint_sp);
66  return breakpoint_sp;
67  }
68 
69  /// This updates the offset for this breakpoint. All the locations
70  /// currently set for this breakpoint will have their offset adjusted when
71  /// this is called.
72  ///
73  /// \param[in] offset
74  /// The offset to add to all locations.
75  void SetOffset(lldb::addr_t offset);
76 
77  lldb::addr_t GetOffset() const { return m_offset; }
78 
79  /// In response to this method the resolver scans all the modules in the
80  /// breakpoint's target, and adds any new locations it finds.
81  ///
82  /// \param[in] filter
83  /// The filter that will manage the search for this resolver.
84  virtual void ResolveBreakpoint(SearchFilter &filter);
85 
86  /// In response to this method the resolver scans the modules in the module
87  /// list \a modules, and adds any new locations it finds.
88  ///
89  /// \param[in] filter
90  /// The filter that will manage the search for this resolver.
91  virtual void ResolveBreakpointInModules(SearchFilter &filter,
92  ModuleList &modules);
93 
94  /// Prints a canonical description for the breakpoint to the stream \a s.
95  ///
96  /// \param[in] s
97  /// Stream to which the output is copied.
98  void GetDescription(Stream *s) override = 0;
99 
100  /// Standard "Dump" method. At present it does nothing.
101  virtual void Dump(Stream *s) const = 0;
102 
103  /// This section handles serializing and deserializing from StructuredData
104  /// objects.
105 
106  static lldb::BreakpointResolverSP
108  Status &error);
109 
111  return StructuredData::ObjectSP();
112  }
113 
114  static const char *GetSerializationKey() { return "BKPTResolver"; }
115 
116  static const char *GetSerializationSubclassKey() { return "Type"; }
117 
118  static const char *GetSerializationSubclassOptionsKey() { return "Options"; }
119 
122 
123  /// An enumeration for keeping track of the concrete subclass that is
124  /// actually instantiated. Values of this enumeration are kept in the
125  /// BreakpointResolver's SubclassID field. They are used for concrete type
126  /// identification.
127  enum ResolverTy {
128  FileLineResolver = 0, // This is an instance of BreakpointResolverFileLine
129  AddressResolver, // This is an instance of BreakpointResolverAddress
130  NameResolver, // This is an instance of BreakpointResolverName
136  };
137 
138  // Translate the Ty to name for serialization, the "+2" is one for size vrs.
139  // index, and one for UnknownResolver.
140  static const char *g_ty_to_name[LastKnownResolverType + 2];
141 
142  /// getResolverID - Return an ID for the concrete type of this object. This
143  /// is used to implement the LLVM classof checks. This should not be used
144  /// for any other purpose, as the values may change as LLDB evolves.
145  unsigned getResolverID() const { return SubclassID; }
146 
148  if (SubclassID > ResolverTy::LastKnownResolverType)
149  return ResolverTy::UnknownResolver;
150  else
151  return (enum ResolverTy)SubclassID;
152  }
153 
154  const char *GetResolverName() { return ResolverTyToName(GetResolverTy()); }
155 
156  static const char *ResolverTyToName(enum ResolverTy);
157 
158  static ResolverTy NameToResolverTy(llvm::StringRef name);
159 
160  virtual lldb::BreakpointResolverSP
161  CopyForBreakpoint(lldb::BreakpointSP &breakpoint) = 0;
162 
163 protected:
164  // Used for serializing resolver options:
165  // The options in this enum and the strings in the g_option_names must be
166  // kept in sync.
167  enum class OptionNames : uint32_t {
168  AddressOffset = 0,
169  ExactMatch,
170  FileName,
171  Inlines,
172  LanguageName,
173  LineNumber,
174  Column,
175  ModuleName,
177  Offset,
179  RegexString,
180  ScriptArgs,
181  SectionName,
182  SearchDepth,
183  SkipPrologue,
186  };
187  static const char
189 
190  virtual void NotifyBreakpointSet() {};
191 
192 public:
193  static const char *GetKey(OptionNames enum_value) {
194  return g_option_names[static_cast<uint32_t>(enum_value)];
195  }
196 
197 protected:
198  /// Takes a symbol context list of matches which supposedly represent the
199  /// same file and line number in a CU, and find the nearest actual line
200  /// number that matches, and then filter down the matching addresses to
201  /// unique entries, and skip the prologue if asked to do so, and then set
202  /// breakpoint locations in this breakpoint for all the resultant addresses.
203  /// When \p column is nonzero the \p line and \p column args are used to
204  /// filter the results to find the first breakpoint >= (line, column).
205  void SetSCMatchesByLine(SearchFilter &filter, SymbolContextList &sc_list,
206  bool skip_prologue, llvm::StringRef log_ident,
207  uint32_t line = 0,
208  llvm::Optional<uint16_t> column = llvm::None);
210  const char *) = delete;
211 
212  lldb::BreakpointLocationSP AddLocation(Address loc_addr,
213  bool *new_location = nullptr);
214 
215 private:
216  /// Helper for \p SetSCMatchesByLine.
217  void AddLocation(SearchFilter &filter, const SymbolContext &sc,
218  bool skip_prologue, llvm::StringRef log_ident);
219 
220  lldb::BreakpointWP m_breakpoint; // This is the breakpoint we add locations to.
221  lldb::addr_t m_offset; // A random offset the user asked us to add to any
222  // breakpoints we set.
223 
224  // Subclass identifier (for llvm isa/dyn_cast)
225  const unsigned char SubclassID;
226  BreakpointResolver(const BreakpointResolver &) = delete;
227  const BreakpointResolver &operator=(const BreakpointResolver &) = delete;
228 };
229 
230 } // namespace lldb_private
231 
232 #endif // LLDB_BREAKPOINT_BREAKPOINTRESOLVER_H
RegularExpression.h
lldb_private::BreakpointResolver::NameToResolverTy
static ResolverTy NameToResolverTy(llvm::StringRef name)
Definition: BreakpointResolver.cpp:55
lldb_private::BreakpointResolver::~BreakpointResolver
~BreakpointResolver() override
The Destructor is virtual, all significant breakpoint resolvers derive from this class.
lldb_private::BreakpointResolver::OptionNames::SearchDepth
@ SearchDepth
lldb_private::BreakpointResolver::ResolverTy
ResolverTy
An enumeration for keeping track of the concrete subclass that is actually instantiated.
Definition: BreakpointResolver.h:127
lldb_private::StructuredData::Dictionary
Definition: StructuredData.h:352
lldb_private::BreakpointResolver::OptionNames::FileName
@ FileName
lldb_private::BreakpointResolver::GetResolverTy
enum ResolverTy GetResolverTy()
Definition: BreakpointResolver.h:147
lldb_private::BreakpointResolver::OptionNames::Inlines
@ Inlines
lldb_private::BreakpointResolver::m_breakpoint
lldb::BreakpointWP m_breakpoint
Definition: BreakpointResolver.h:220
lldb_private::BreakpointResolver::OptionNames::ScriptArgs
@ ScriptArgs
lldb_private::BreakpointResolver::SubclassID
const unsigned char SubclassID
Definition: BreakpointResolver.h:225
lldb_private::BreakpointResolver::g_option_names
static const char * g_option_names[static_cast< uint32_t >(OptionNames::LastOptionName)]
Definition: BreakpointResolver.h:188
lldb_private::BreakpointResolver::OptionNames::PythonClassName
@ PythonClassName
lldb_private::BreakpointResolver::AddressResolver
@ AddressResolver
Definition: BreakpointResolver.h:129
lldb_private::BreakpointResolver::OptionNames::SkipPrologue
@ SkipPrologue
lldb_private::BreakpointResolver::CopyForBreakpoint
virtual lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP &breakpoint)=0
lldb_private::SymbolContextList
Definition: SymbolContext.h:379
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::BreakpointResolver::OptionNames::NameMaskArray
@ NameMaskArray
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::BreakpointResolver::PythonResolver
@ PythonResolver
Definition: BreakpointResolver.h:132
lldb_private::FileLineResolver
Definition: FileLineResolver.h:27
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::BreakpointResolver::OptionNames::LineNumber
@ LineNumber
lldb_private::BreakpointResolver::ResolveBreakpointInModules
virtual void ResolveBreakpointInModules(SearchFilter &filter, ModuleList &modules)
In response to this method the resolver scans the modules in the module list modules,...
Definition: BreakpointResolver.cpp:171
lldb_private::BreakpointResolver::OptionNames::LastOptionName
@ LastOptionName
lldb_private::BreakpointResolver::CreateFromStructuredData
static lldb::BreakpointResolverSP CreateFromStructuredData(const StructuredData::Dictionary &resolver_dict, Status &error)
This section handles serializing and deserializing from StructuredData objects.
Definition: BreakpointResolver.cpp:70
lldb_private::BreakpointResolver::NotifyBreakpointSet
virtual void NotifyBreakpointSet()
Definition: BreakpointResolver.h:190
lldb_private::BreakpointResolver::BreakpointResolver
BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType, lldb::addr_t offset=0)
The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint to make sense.
lldb_private::ModuleList
Definition: ModuleList.h:72
lldb_private::SearchFilter
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
lldb_private::BreakpointResolver::NameResolver
@ NameResolver
Definition: BreakpointResolver.h:130
lldb_private::BreakpointResolver::OptionNames::AddressOffset
@ AddressOffset
lldb_private::BreakpointResolver::LastKnownResolverType
@ LastKnownResolverType
Definition: BreakpointResolver.h:134
lldb_private::BreakpointResolver::SerializeToStructuredData
virtual StructuredData::ObjectSP SerializeToStructuredData()
Definition: BreakpointResolver.h:110
SearchFilter.h
lldb_private::BreakpointResolver::OptionNames::Column
@ Column
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb_private::BreakpointResolver::ExceptionResolver
@ ExceptionResolver
Definition: BreakpointResolver.h:133
lldb_private::BreakpointResolver::ResolverTyToName
static const char * ResolverTyToName(enum ResolverTy)
Definition: BreakpointResolver.cpp:47
lldb_private::BreakpointResolver::GetResolverName
const char * GetResolverName()
Definition: BreakpointResolver.h:154
lldb_private::BreakpointResolver::OptionNames::RegexString
@ RegexString
lldb_private::BreakpointResolver::UnknownResolver
@ UnknownResolver
Definition: BreakpointResolver.h:135
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb_private::BreakpointResolver::operator=
const BreakpointResolver & operator=(const BreakpointResolver &)=delete
lldb_private::BreakpointResolver::SetBreakpoint
void SetBreakpoint(const lldb::BreakpointSP &bkpt)
This sets the breakpoint for this resolver.
Definition: BreakpointResolver.cpp:165
lldb_private::BreakpointResolver::OptionNames::LanguageName
@ LanguageName
Address.h
lldb_private::BreakpointResolver::AddLocation
lldb::BreakpointLocationSP AddLocation(Address loc_addr, bool *new_location=nullptr)
Definition: BreakpointResolver.cpp:338
lldb-private.h
lldb_private::BreakpointResolver
General Outline: The BreakpointResolver is a Searcher.
Definition: BreakpointResolver.h:35
lldb_private::BreakpointResolver::WrapOptionsDict
StructuredData::DictionarySP WrapOptionsDict(StructuredData::DictionarySP options_dict_sp)
Definition: BreakpointResolver.cpp:150
lldb_private::BreakpointResolver::OptionNames::SectionName
@ SectionName
lldb_private::BreakpointResolver::OptionNames::ModuleName
@ ModuleName
lldb_private::BreakpointResolver::OptionNames::Offset
@ Offset
lldb_private::Status
Definition: Status.h:44
lldb_private::BreakpointResolver::g_ty_to_name
static const char * g_ty_to_name[LastKnownResolverType+2]
Definition: BreakpointResolver.h:140
lldb_private::BreakpointResolver::FileRegexResolver
@ FileRegexResolver
Definition: BreakpointResolver.h:131
uint32_t
lldb_private::Address
Definition: Address.h:59
lldb_private::BreakpointResolver::SetSCMatchesByLine
void SetSCMatchesByLine(SearchFilter &filter, SymbolContextList &sc_list, bool skip_prologue, llvm::StringRef log_ident, uint32_t line=0, llvm::Optional< uint16_t > column=llvm::None)
Takes a symbol context list of matches which supposedly represent the same file and line number in a ...
Definition: BreakpointResolver.cpp:203
lldb_private::BreakpointResolver::GetKey
static const char * GetKey(OptionNames enum_value)
Definition: BreakpointResolver.h:193
lldb_private::BreakpointResolver::GetSerializationSubclassOptionsKey
static const char * GetSerializationSubclassOptionsKey()
Definition: BreakpointResolver.h:118
lldb_private::BreakpointResolver::OptionNames::SymbolNameArray
@ SymbolNameArray
lldb_private::BreakpointResolver::Dump
virtual void Dump(Stream *s) const =0
Standard "Dump" method. At present it does nothing.
lldb_private::BreakpointResolver::SetOffset
void SetOffset(lldb::addr_t offset)
This updates the offset for this breakpoint.
Definition: BreakpointResolver.cpp:344
lldb_private::BreakpointResolver::GetOffset
lldb::addr_t GetOffset() const
Definition: BreakpointResolver.h:77
lldb_private::BreakpointResolver::ResolveBreakpoint
virtual void ResolveBreakpoint(SearchFilter &filter)
In response to this method the resolver scans all the modules in the breakpoint's target,...
Definition: BreakpointResolver.cpp:176
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Breakpoint.h
FileSpec.h
lldb_private::BreakpointResolver::GetDescription
void GetDescription(Stream *s) override=0
Prints a canonical description for the breakpoint to the stream s.
ConstString.h
lldb_private::Searcher
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:42
lldb_private::BreakpointResolver::GetSerializationSubclassKey
static const char * GetSerializationSubclassKey()
Definition: BreakpointResolver.h:116
lldb_private::BreakpointResolver::OptionNames::ExactMatch
@ ExactMatch
lldb_private::BreakpointResolver::GetSerializationKey
static const char * GetSerializationKey()
Definition: BreakpointResolver.h:114
lldb_private::BreakpointResolver::GetBreakpoint
lldb::BreakpointSP GetBreakpoint() const
This gets the breakpoint for this resolver.
Definition: BreakpointResolver.h:62
lldb_private::Breakpoint
General Outline: A breakpoint has four main parts, a filter, a resolver, the list of breakpoint locat...
Definition: Breakpoint.h:79
lldb_private::BreakpointResolver::OptionNames
OptionNames
Definition: BreakpointResolver.h:167
lldb_private::BreakpointResolver::m_offset
lldb::addr_t m_offset
Definition: BreakpointResolver.h:221
lldb_private::BreakpointResolver::getResolverID
unsigned getResolverID() const
getResolverID - Return an ID for the concrete type of this object.
Definition: BreakpointResolver.h:145