1use crate::{lldb_addr_t, sys, DescriptionLevel, SBError, SBStream};
8use std::fmt;
9
10pub struct SBWatchpoint {
31 pub raw: sys::SBWatchpointRef,
33}
34
35impl SBWatchpoint {
36 pub(crate) fn wrap(raw: sys::SBWatchpointRef) -> SBWatchpoint {
38 SBWatchpoint { raw }
39 }
40
41 pub(crate) fn maybe_wrap(raw: sys::SBWatchpointRef) -> Option<SBWatchpoint> {
43 if unsafe { sys::SBWatchpointIsValid(raw) } {
44 Some(SBWatchpoint { raw })
45 } else {
46 None
47 }
48 }
49
50 pub fn is_valid(&self) -> bool {
52 unsafe { sys::SBWatchpointIsValid(self.raw) }
53 }
54
55 #[allow(missing_docs)]
56 pub fn error(&self) -> Option<SBError> {
57 SBError::maybe_wrap(unsafe { sys::SBWatchpointGetError(self.raw) })
58 }
59
60 #[allow(missing_docs)]
61 pub fn id(&self) -> i32 {
62 unsafe { sys::SBWatchpointGetID(self.raw) }
63 }
64
65 #[allow(missing_docs)]
66 pub fn hardware_index(&self) -> Option<i32> {
67 let idx = unsafe { sys::SBWatchpointGetHardwareIndex(self.raw) };
68 if idx == -1 {
69 None
70 } else {
71 Some(idx)
72 }
73 }
74
75 #[allow(missing_docs)]
76 pub fn watch_address(&self) -> lldb_addr_t {
77 unsafe { sys::SBWatchpointGetWatchAddress(self.raw) }
78 }
79
80 #[allow(missing_docs)]
81 pub fn watch_size(&self) -> usize {
82 unsafe { sys::SBWatchpointGetWatchSize(self.raw) }
83 }
84
85 #[allow(missing_docs)]
86 pub fn is_enabled(&self) -> bool {
87 unsafe { sys::SBWatchpointIsEnabled(self.raw) }
88 }
89
90 #[allow(missing_docs)]
91 pub fn set_enabled(&self, enabled: bool) {
92 unsafe { sys::SBWatchpointSetEnabled(self.raw, enabled) }
93 }
94
95 #[allow(missing_docs)]
96 pub fn hit_count(&self) -> u32 {
97 unsafe { sys::SBWatchpointGetHitCount(self.raw) }
98 }
99
100 #[allow(missing_docs)]
101 pub fn ignore_count(&self) -> u32 {
102 unsafe { sys::SBWatchpointGetIgnoreCount(self.raw) }
103 }
104
105 #[allow(missing_docs)]
106 pub fn set_ignore_count(&self, count: u32) {
107 unsafe { sys::SBWatchpointSetIgnoreCount(self.raw, count) }
108 }
109}
110
111impl Clone for SBWatchpoint {
112 fn clone(&self) -> SBWatchpoint {
113 SBWatchpoint {
114 raw: unsafe { sys::CloneSBWatchpoint(self.raw) },
115 }
116 }
117}
118
119impl fmt::Debug for SBWatchpoint {
120 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
121 let stream = SBStream::new();
122 unsafe { sys::SBWatchpointGetDescription(self.raw, stream.raw, DescriptionLevel::Brief) };
123 write!(fmt, "SBWatchpoint {{ {} }}", stream.data())
124 }
125}
126
127impl Drop for SBWatchpoint {
128 fn drop(&mut self) {
129 unsafe { sys::DisposeSBWatchpoint(self.raw) };
130 }
131}
132
133unsafe impl Send for SBWatchpoint {}
134unsafe impl Sync for SBWatchpoint {}
135
136#[cfg(feature = "graphql")]
137#[juniper::graphql_object]
138impl SBWatchpoint {
139 fn id() -> i32 {
140 self.id()
141 }
142
143 fn hardware_index() -> Option<i32> {
144 self.hardware_index()
145 }
146
147 fn watch_address() -> i32 {
149 self.watch_address() as i32
150 }
151
152 fn watch_size() -> i32 {
154 self.watch_size() as i32
155 }
156
157 fn is_enabled() -> bool {
158 self.is_enabled()
159 }
160
161 fn hit_count() -> i32 {
163 self.hit_count() as i32
164 }
165
166 fn ignore_count() -> i32 {
168 self.ignore_count() as i32
169 }
170}