DebugServer2
Loading...
Searching...
No Matches
BreakpointManager.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/Target/ProcessDecl.h"
14#include "DebugServer2/Utils/Enums.h"
15
16#include <functional>
17
18namespace ds2 {
19
21public:
22 enum class Lifetime : unsigned int {
23 None = 0,
24 Permanent = (1 << 0),
25 TemporaryOneShot = (1 << 1),
26 TemporaryUntilHit = (1 << 2),
27 };
28
29 enum Mode {
30 kModeExec = (1 << 0),
31 kModeRead = (1 << 1),
32 kModeWrite = (1 << 2),
33 };
34
35public:
36 struct Site {
37 protected:
38 friend class BreakpointManager;
39 int32_t refs;
40
41 public:
42 Address address;
43 Lifetime lifetime;
44 Mode mode;
45 size_t size;
46
47 public:
48 bool operator==(Site const &other) const {
49 return (address == other.address) && (lifetime == other.lifetime) &&
50 (mode == other.mode) && (size == other.size);
51 }
52 };
53
54 // Address->Site map
55 typedef std::map<uint64_t, Site> SiteMap;
56
57protected:
58 SiteMap _sites;
59
60protected:
61 Target::ProcessBase *_process;
62
63protected:
65
66public:
67 virtual ~BreakpointManager();
68
69public:
70 virtual void clear();
71
72public:
73 virtual ErrorCode add(Address const &address, Lifetime lifetime, size_t size,
74 Mode mode);
75 virtual ErrorCode remove(Address const &address);
76
77public:
78 virtual bool has(Address const &address) const;
79
80public:
81 virtual void enumerate(std::function<void(Site const &)> const &cb) const;
82
83protected:
84 virtual ErrorCode isValid(Address const &address, size_t size,
85 Mode mode) const;
86 virtual size_t chooseBreakpointSize(Address const &address) const = 0;
87
88protected:
90
91protected:
92 virtual bool hit(Address const &address, Site &site);
93
94public:
95 // Returns the hardware index of the breakpoint, if applicable.
96 // If not hit, returns a negative integer
97 virtual int hit(Target::Thread *thread, Site &site) = 0;
98
99public:
100 virtual void enable(Target::Thread *thread = nullptr);
101 virtual void disable(Target::Thread *thread = nullptr);
102
103protected:
104 virtual ErrorCode enableLocation(Site const &site,
105 Target::Thread *thread = nullptr) = 0;
106 virtual ErrorCode disableLocation(Site const &site,
107 Target::Thread *thread = nullptr) = 0;
108 virtual bool enabled(Target::Thread *thread = nullptr) const = 0;
109
110public:
111 virtual bool fillStopInfo(Target::Thread *thread, StopInfo &stopInfo) = 0;
112};
113} // namespace ds2
114ENABLE_BITMASK_OPERATORS(ds2::BreakpointManager::Lifetime);
Definition Types.h:95
Definition BreakpointManager.h:20
Definition ProcessBase.h:25
Definition BreakpointManager.h:36
Definition Types.h:131