1 //===-- BreakpointResolverFileLine.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_BREAKPOINTRESOLVERFILELINE_H
10 #define LLDB_BREAKPOINT_BREAKPOINTRESOLVERFILELINE_H
11 
12 #include "lldb/Breakpoint/BreakpointResolver.h"
13 #include "lldb/Core/SourceLocationSpec.h"
14 #include <optional>
15 
16 namespace lldb_private {
17 
18 /// \class BreakpointResolverFileLine BreakpointResolverFileLine.h
19 /// "lldb/Breakpoint/BreakpointResolverFileLine.h" This class sets breakpoints
20 /// by file and line.  Optionally, it will look for inlined instances of the
21 /// file and line specification.
22 
23 class BreakpointResolverFileLine : public BreakpointResolver {
24 public:
25   BreakpointResolverFileLine(
26       const lldb::BreakpointSP &bkpt, lldb::addr_t offset, bool skip_prologue,
27       const SourceLocationSpec &location_spec,
28       std::optional<llvm::StringRef> removed_prefix_opt = std::nullopt);
29 
30   static lldb::BreakpointResolverSP
31   CreateFromStructuredData(const StructuredData::Dictionary &data_dict,
32                            Status &error);
33 
34   StructuredData::ObjectSP SerializeToStructuredData() override;
35 
36   ~BreakpointResolverFileLine() override = default;
37 
38   Searcher::CallbackReturn SearchCallback(SearchFilter &filter,
39                                           SymbolContext &context,
40                                           Address *addr) override;
41 
42   lldb::SearchDepth GetDepth() override;
43 
44   void GetDescription(Stream *s) override;
45 
46   void Dump(Stream *s) const override;
47 
48   /// Methods for support type inquiry through isa, cast, and dyn_cast:
classof(const BreakpointResolverFileLine *)49   static inline bool classof(const BreakpointResolverFileLine *) {
50     return true;
51   }
classof(const BreakpointResolver * V)52   static inline bool classof(const BreakpointResolver *V) {
53     return V->getResolverID() == BreakpointResolver::FileLineResolver;
54   }
55 
56   lldb::BreakpointResolverSP
57   CopyForBreakpoint(lldb::BreakpointSP &breakpoint) override;
58 
59 protected:
60   void FilterContexts(SymbolContextList &sc_list);
61   void DeduceSourceMapping(const SymbolContextList &sc_list);
62 
63   friend class Breakpoint;
64   SourceLocationSpec m_location_spec;
65   bool m_skip_prologue;
66   // Any previously removed file path prefix by reverse source mapping.
67   // This is used to auto deduce source map if needed.
68   std::optional<llvm::StringRef> m_removed_prefix_opt;
69 
70 private:
71   BreakpointResolverFileLine(const BreakpointResolverFileLine &) = delete;
72   const BreakpointResolverFileLine &
73   operator=(const BreakpointResolverFileLine &) = delete;
74 };
75 
76 } // namespace lldb_private
77 
78 #endif // LLDB_BREAKPOINT_BREAKPOINTRESOLVERFILELINE_H
79