use crate::{
lldb_addr_t, sys, SBBreakpointLocation, SBStream, SBStringList, SBStructuredData, SBTarget,
};
use std::ffi::CString;
use std::fmt;
pub struct SBBreakpoint {
pub raw: sys::SBBreakpointRef,
}
impl SBBreakpoint {
pub(crate) fn wrap(raw: sys::SBBreakpointRef) -> SBBreakpoint {
SBBreakpoint { raw }
}
pub(crate) fn maybe_wrap(raw: sys::SBBreakpointRef) -> Option<SBBreakpoint> {
if unsafe { sys::SBBreakpointIsValid(raw) } {
Some(SBBreakpoint { raw })
} else {
None
}
}
pub fn is_valid(&self) -> bool {
unsafe { sys::SBBreakpointIsValid(self.raw) }
}
#[allow(missing_docs)]
pub fn id(&self) -> i32 {
unsafe { sys::SBBreakpointGetID(self.raw) }
}
#[allow(missing_docs)]
pub fn is_enabled(&self) -> bool {
unsafe { sys::SBBreakpointIsEnabled(self.raw) }
}
#[allow(missing_docs)]
pub fn set_enabled(&self, enabled: bool) {
unsafe { sys::SBBreakpointSetEnabled(self.raw, enabled) }
}
#[allow(missing_docs)]
pub fn is_oneshot(&self) -> bool {
unsafe { sys::SBBreakpointIsOneShot(self.raw) }
}
#[allow(missing_docs)]
pub fn set_oneshot(&self, oneshot: bool) {
unsafe { sys::SBBreakpointSetOneShot(self.raw, oneshot) }
}
#[allow(missing_docs)]
pub fn is_internal(&self) -> bool {
unsafe { sys::SBBreakpointIsInternal(self.raw) }
}
#[allow(missing_docs)]
pub fn hit_count(&self) -> u32 {
unsafe { sys::SBBreakpointGetHitCount(self.raw) }
}
#[allow(missing_docs)]
pub fn ignore_count(&self) -> u32 {
unsafe { sys::SBBreakpointGetIgnoreCount(self.raw) }
}
#[allow(missing_docs)]
pub fn set_ignore_count(&self, count: u32) {
unsafe { sys::SBBreakpointSetIgnoreCount(self.raw, count) }
}
#[allow(missing_docs)]
pub fn add_name(&self, name: &str) -> bool {
let name = CString::new(name).unwrap();
unsafe { sys::SBBreakpointAddName(self.raw, name.as_ptr()) }
}
#[allow(missing_docs)]
pub fn remove_name(&self, name: &str) {
let name = CString::new(name).unwrap();
unsafe { sys::SBBreakpointRemoveName(self.raw, name.as_ptr()) };
}
#[allow(missing_docs)]
pub fn matches_name(&self, name: &str) -> bool {
let name = CString::new(name).unwrap();
unsafe { sys::SBBreakpointMatchesName(self.raw, name.as_ptr()) }
}
#[allow(missing_docs)]
pub fn names(&self) -> SBStringList {
let names = SBStringList::new();
unsafe { sys::SBBreakpointGetNames(self.raw, names.raw) };
names
}
#[allow(missing_docs)]
pub fn clear_all_breakpoint_sites(&self) {
unsafe { sys::SBBreakpointClearAllBreakpointSites(self.raw) };
}
#[allow(missing_docs)]
pub fn target(&self) -> Option<SBTarget> {
SBTarget::maybe_wrap(unsafe { sys::SBBreakpointGetTarget(self.raw) })
}
#[allow(missing_docs)]
pub fn find_location_by_address(&self, address: lldb_addr_t) -> Option<SBBreakpointLocation> {
SBBreakpointLocation::maybe_wrap(unsafe {
sys::SBBreakpointFindLocationByAddress(self.raw, address)
})
}
#[allow(missing_docs)]
pub fn find_location_id_by_address(&self, address: lldb_addr_t) -> i32 {
unsafe { sys::SBBreakpointFindLocationIDByAddress(self.raw, address) }
}
#[allow(missing_docs)]
pub fn find_location_by_id(&self, id: i32) -> Option<SBBreakpointLocation> {
SBBreakpointLocation::maybe_wrap(unsafe { sys::SBBreakpointFindLocationByID(self.raw, id) })
}
#[allow(missing_docs)]
pub fn locations(&self) -> SBBreakpointLocationIter {
SBBreakpointLocationIter {
breakpoint: self,
idx: 0,
}
}
#[allow(missing_docs)]
pub fn is_hardware(&self) -> bool {
unsafe { sys::SBBreakpointIsHardware(self.raw) }
}
#[allow(missing_docs)]
pub fn serialize_to_structured_data(&self) -> SBStructuredData {
SBStructuredData::wrap(unsafe { sys::SBBreakpointSerializeToStructuredData(self.raw) })
}
}
impl Clone for SBBreakpoint {
fn clone(&self) -> SBBreakpoint {
SBBreakpoint {
raw: unsafe { sys::CloneSBBreakpoint(self.raw) },
}
}
}
impl fmt::Debug for SBBreakpoint {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let stream = SBStream::new();
unsafe { sys::SBBreakpointGetDescription(self.raw, stream.raw) };
write!(fmt, "SBBreakpoint {{ {} }}", stream.data())
}
}
impl Drop for SBBreakpoint {
fn drop(&mut self) {
unsafe { sys::DisposeSBBreakpoint(self.raw) };
}
}
unsafe impl Send for SBBreakpoint {}
unsafe impl Sync for SBBreakpoint {}
pub struct SBBreakpointLocationIter<'d> {
breakpoint: &'d SBBreakpoint,
idx: usize,
}
impl<'d> Iterator for SBBreakpointLocationIter<'d> {
type Item = SBBreakpointLocation;
fn next(&mut self) -> Option<SBBreakpointLocation> {
if self.idx < unsafe { sys::SBBreakpointGetNumLocations(self.breakpoint.raw) } {
let r = SBBreakpointLocation::maybe_wrap(unsafe {
sys::SBBreakpointGetLocationAtIndex(self.breakpoint.raw, self.idx as u32)
});
self.idx += 1;
r
} else {
None
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
let sz = unsafe { sys::SBBreakpointGetNumLocations(self.breakpoint.raw) };
(sz - self.idx, Some(sz))
}
}
impl<'d> ExactSizeIterator for SBBreakpointLocationIter<'d> {}
#[cfg(feature = "graphql")]
#[graphql_object]
impl SBBreakpoint {
fn id() -> i32 {
self.id()
}
fn is_enabled() -> bool {
self.is_enabled()
}
fn is_oneshot() -> bool {
self.is_oneshot()
}
fn is_internal() -> bool {
self.is_internal()
}
fn ignore_count() -> i32 {
self.ignore_count() as i32
}
fn hit_count() -> i32 {
self.hit_count() as i32
}
fn locations() -> Vec<SBBreakpointLocation> {
self.locations().collect()
}
}