use crate::{lldb_addr_t, sys, DescriptionLevel, SBError, SBStream};
use std::fmt;
pub struct SBWatchpoint {
pub raw: sys::SBWatchpointRef,
}
impl SBWatchpoint {
pub(crate) fn wrap(raw: sys::SBWatchpointRef) -> SBWatchpoint {
SBWatchpoint { raw }
}
pub(crate) fn maybe_wrap(raw: sys::SBWatchpointRef) -> Option<SBWatchpoint> {
if unsafe { sys::SBWatchpointIsValid(raw) } {
Some(SBWatchpoint { raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBWatchpointIsValid(self.raw) }
}
#[allow(missing_docs)]
pub fn error(&self) -> Option<SBError> {
SBError::maybe_wrap(unsafe { sys::SBWatchpointGetError(self.raw) })
}
#[allow(missing_docs)]
pub fn id(&self) -> i32 {
unsafe { sys::SBWatchpointGetID(self.raw) }
}
#[allow(missing_docs)]
pub fn hardware_index(&self) -> Option<i32> {
let idx = unsafe { sys::SBWatchpointGetHardwareIndex(self.raw) };
if idx == -1 {
None
} else {
Some(idx)
}
}
#[allow(missing_docs)]
pub fn watch_address(&self) -> lldb_addr_t {
unsafe { sys::SBWatchpointGetWatchAddress(self.raw) }
}
#[allow(missing_docs)]
pub fn watch_size(&self) -> usize {
unsafe { sys::SBWatchpointGetWatchSize(self.raw) }
}
#[allow(missing_docs)]
pub fn is_enabled(&self) -> bool {
unsafe { sys::SBWatchpointIsEnabled(self.raw) }
}
#[allow(missing_docs)]
pub fn set_enabled(&self, enabled: bool) {
unsafe { sys::SBWatchpointSetEnabled(self.raw, enabled) }
}
#[allow(missing_docs)]
pub fn hit_count(&self) -> u32 {
unsafe { sys::SBWatchpointGetHitCount(self.raw) }
}
#[allow(missing_docs)]
pub fn ignore_count(&self) -> u32 {
unsafe { sys::SBWatchpointGetIgnoreCount(self.raw) }
}
#[allow(missing_docs)]
pub fn set_ignore_count(&self, count: u32) {
unsafe { sys::SBWatchpointSetIgnoreCount(self.raw, count) }
}
}
impl Clone for SBWatchpoint {
fn clone(&self) -> SBWatchpoint {
SBWatchpoint {
raw: unsafe { sys::CloneSBWatchpoint(self.raw) },
}
}
}
impl fmt::Debug for SBWatchpoint {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let stream = SBStream::new();
unsafe { sys::SBWatchpointGetDescription(self.raw, stream.raw, DescriptionLevel::Brief) };
write!(fmt, "SBWatchpoint {{ {} }}", stream.data())
}
}
impl Drop for SBWatchpoint {
fn drop(&mut self) {
unsafe { sys::DisposeSBWatchpoint(self.raw) };
}
}
unsafe impl Send for SBWatchpoint {}
unsafe impl Sync for SBWatchpoint {}
#[cfg(feature = "graphql")]
#[juniper::graphql_object]
impl SBWatchpoint {
fn id() -> i32 {
self.id()
}
fn hardware_index() -> Option<i32> {
self.hardware_index()
}
fn watch_address() -> i32 {
self.watch_address() as i32
}
fn watch_size() -> i32 {
self.watch_size() as i32
}
fn is_enabled() -> bool {
self.is_enabled()
}
fn hit_count() -> i32 {
self.hit_count() as i32
}
fn ignore_count() -> i32 {
self.ignore_count() as i32
}
}