本文整理汇总了C++中DNBError类的典型用法代码示例。如果您正苦于以下问题:C++ DNBError类的具体用法?C++ DNBError怎么用?C++ DNBError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DNBError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TaskPort
//----------------------------------------------------------------------
// MachTask::Resume
//----------------------------------------------------------------------
kern_return_t
MachTask::Resume()
{
struct task_basic_info task_info;
task_t task = TaskPort();
if (task == TASK_NULL)
return KERN_INVALID_ARGUMENT;
DNBError err;
err = BasicInfo(task, &task_info);
if (err.Success())
{
// task_resume isn't counted like task_suspend calls are, are, so if the
// task is not suspended, don't try and resume it since it is already
// running
if (task_info.suspend_count > 0)
{
err = ::task_resume (task);
if (DNBLogCheckLogBit(LOG_TASK) || err.Fail())
err.LogThreaded("::task_resume ( target_task = 0x%4.4x )", task);
}
}
return err.Error();
}
示例2: send
rnb_err_t
RNBSocket::Write (const void *buffer, size_t length)
{
if (m_fd == -1)
return rnb_err;
DNBError err;
int bytessent = send (m_fd, buffer, length, 0);
if (bytessent < 0)
err.SetError(errno, DNBError::POSIX);
if (err.Fail() || DNBLogCheckLogBit(LOG_RNB_COMM))
err.LogThreaded("::send ( socket = %i, buffer = %p, length = %zu, flags = 0 ) => %i", m_fd, buffer, length, bytessent);
if (bytessent < 0)
return rnb_err;
if (bytessent != length)
return rnb_err;
DNBLogThreadedIf(LOG_RNB_PACKETS, "putpkt: %*s", (int)length, (char *)buffer); // All data is string based in debugserver, so this is safe
DNBLogThreadedIf(LOG_RNB_COMM, "sent: %*s", (int)length, (char *)buffer);
return rnb_success;
}
示例3: DNBLogCheckLogBit
//----------------------------------------------------------------------
// MachTask::BasicInfo
//----------------------------------------------------------------------
kern_return_t
MachTask::BasicInfo(task_t task, struct task_basic_info *info)
{
if (info == NULL)
return KERN_INVALID_ARGUMENT;
DNBError err;
mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
err = ::task_info (task, TASK_BASIC_INFO, (task_info_t)info, &count);
const bool log_process = DNBLogCheckLogBit(LOG_TASK);
if (log_process || err.Fail())
err.LogThreaded("::task_info ( target_task = 0x%4.4x, flavor = TASK_BASIC_INFO, task_info_out => %p, task_info_outCnt => %u )", task, info, count);
if (DNBLogCheckLogBit(LOG_TASK) && DNBLogCheckLogBit(LOG_VERBOSE) && err.Success())
{
float user = (float)info->user_time.seconds + (float)info->user_time.microseconds / 1000000.0f;
float system = (float)info->user_time.seconds + (float)info->user_time.microseconds / 1000000.0f;
DNBLogThreaded ("task_basic_info = { suspend_count = %i, virtual_size = 0x%8.8llx, resident_size = 0x%8.8llx, user_time = %f, system_time = %f }",
info->suspend_count,
(uint64_t)info->virtual_size,
(uint64_t)info->resident_size,
user,
system);
}
return err.Error();
}
示例4: RestoreExceptionPortInfo
kern_return_t
MachTask::ShutDownExcecptionThread()
{
DNBError err;
err = RestoreExceptionPortInfo();
// NULL our our exception port and let our exception thread exit
mach_port_t exception_port = m_exception_port;
m_exception_port = NULL;
err.SetError(::pthread_cancel(m_exception_thread), DNBError::POSIX);
if (DNBLogCheckLogBit(LOG_TASK) || err.Fail())
err.LogThreaded("::pthread_cancel ( thread = %p )", m_exception_thread);
err.SetError(::pthread_join(m_exception_thread, NULL), DNBError::POSIX);
if (DNBLogCheckLogBit(LOG_TASK) || err.Fail())
err.LogThreaded("::pthread_join ( thread = %p, value_ptr = NULL)", m_exception_thread);
// Deallocate our exception port that we used to track our child process
mach_port_t task_self = mach_task_self ();
err = ::mach_port_deallocate (task_self, exception_port);
if (DNBLogCheckLogBit(LOG_TASK) || err.Fail())
err.LogThreaded("::mach_port_deallocate ( task = 0x%4.4x, name = 0x%4.4x )", task_self, exception_port);
exception_port = NULL;
return err.Error();
}
示例5: sizeof
kern_return_t
MachException::PortInfo::Save (task_t task)
{
count = (sizeof (ports) / sizeof (ports[0]));
DNBLogThreadedIf(LOG_EXCEPTIONS | LOG_VERBOSE, "MachException::PortInfo::Save ( task = 0x%4.4x )", task);
DNBError err;
err = ::task_get_exception_ports (task, EXC_MASK_ALL, masks, &count, ports, behaviors, flavors);
if (DNBLogCheckLogBit(LOG_EXCEPTIONS) || err.Fail())
err.LogThreaded("::task_get_exception_ports ( task = 0x%4.4x, mask = 0x%x, maskCnt => %u, ports, behaviors, flavors )", task, EXC_MASK_ALL, count);
if (err.Fail())
count = 0;
return err.Error();
}
示例6: DNBLogCheckLogBit
kern_return_t
MachException::Message::Receive(mach_port_t port, mach_msg_option_t options, mach_msg_timeout_t timeout, mach_port_t notify_port)
{
DNBError err;
const bool log_exceptions = DNBLogCheckLogBit(LOG_EXCEPTIONS);
mach_msg_timeout_t mach_msg_timeout = options & MACH_RCV_TIMEOUT ? timeout : 0;
if (log_exceptions && ((options & MACH_RCV_TIMEOUT) == 0))
{
// Dump this log message if we have no timeout in case it never returns
DNBLogThreaded("::mach_msg ( msg->{bits = %#x, size = %u remote_port = %#x, local_port = %#x, reserved = 0x%x, id = 0x%x}, option = %#x, send_size = %u, rcv_size = %u, rcv_name = %#x, timeout = %u, notify = %#x)",
exc_msg.hdr.msgh_bits,
exc_msg.hdr.msgh_size,
exc_msg.hdr.msgh_remote_port,
exc_msg.hdr.msgh_local_port,
exc_msg.hdr.msgh_reserved,
exc_msg.hdr.msgh_id,
options,
0,
sizeof (exc_msg.data),
port,
mach_msg_timeout,
notify_port);
}
err = ::mach_msg (&exc_msg.hdr,
options, // options
0, // Send size
sizeof (exc_msg.data), // Receive size
port, // exception port to watch for exception on
mach_msg_timeout, // timeout in msec (obeyed only if MACH_RCV_TIMEOUT is ORed into the options parameter)
notify_port);
// Dump any errors we get
if (log_exceptions)
{
err.LogThreaded("::mach_msg ( msg->{bits = %#x, size = %u remote_port = %#x, local_port = %#x, reserved = 0x%x, id = 0x%x}, option = %#x, send_size = %u, rcv_size = %u, rcv_name = %#x, timeout = %u, notify = %#x)",
exc_msg.hdr.msgh_bits,
exc_msg.hdr.msgh_size,
exc_msg.hdr.msgh_remote_port,
exc_msg.hdr.msgh_local_port,
exc_msg.hdr.msgh_reserved,
exc_msg.hdr.msgh_id,
options,
0,
sizeof (exc_msg.data),
port,
mach_msg_timeout,
notify_port);
}
return err.Error();
}
示例7: DNBLogThreadedIf
bool
MachThread::SetSuspendCountBeforeResume(bool others_stopped)
{
DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
DNBError err;
if (ThreadIDIsValid(m_tid) == false)
return false;
size_t times_to_resume;
if (others_stopped)
{
if (GetBasicInfo())
{
times_to_resume = m_basic_info.suspend_count;
m_suspend_count = - (times_to_resume - m_suspend_count);
}
else
times_to_resume = 0;
}
else
{
times_to_resume = m_suspend_count;
m_suspend_count = 0;
}
if (times_to_resume > 0)
{
while (times_to_resume > 0)
{
err = ::thread_resume (m_tid);
if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
err.LogThreaded("::thread_resume (%4.4x)", m_tid);
if (err.Success())
--times_to_resume;
else
{
if (GetBasicInfo())
times_to_resume = m_basic_info.suspend_count;
else
times_to_resume = 0;
}
}
}
return true;
}
示例8: DNBLogThreadedIf
bool
MachThread::RestoreSuspendCount()
{
DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
DNBError err;
if (ThreadIDIsValid(m_tid) == false)
return false;
else if (m_suspendCount > m_basicInfo.suspend_count)
{
while (m_suspendCount > m_basicInfo.suspend_count)
{
err = ::thread_resume (m_tid);
if (err.Success())
--m_suspendCount;
if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
err.LogThreaded("::thread_resume (%4.4x)", m_tid);
}
}
else if (m_suspendCount < m_basicInfo.suspend_count)
{
while (m_suspendCount < m_basicInfo.suspend_count)
{
err = ::thread_suspend (m_tid);
if (err.Success())
--m_suspendCount;
if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
}
}
return m_suspendCount == m_basicInfo.suspend_count;
}
示例9: DNBLogThreadedIf
bool
MachThread::RestoreSuspendCount()
{
DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )", __FUNCTION__);
DNBError err;
if (ThreadIDIsValid(m_tid) == false)
return false;
if (m_suspendCount > 0)
{
while (m_suspendCount > 0)
{
err = ::thread_resume (m_tid);
if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
err.LogThreaded("::thread_resume (%4.4x)", m_tid);
if (err.Success())
--m_suspendCount;
else
{
if (GetBasicInfo())
m_suspendCount = m_basicInfo.suspend_count;
else
m_suspendCount = 0;
return false; // ???
}
}
}
// We don't currently really support resuming a thread that was externally
// suspended. If/when we do, we will need to make the code below work and
// m_suspendCount will need to become signed instead of unsigned.
// else if (m_suspendCount < 0)
// {
// while (m_suspendCount < 0)
// {
// err = ::thread_suspend (m_tid);
// if (err.Success())
// ++m_suspendCount;
// if (DNBLogCheckLogBit(LOG_THREAD) || err.Fail())
// err.LogThreaded("::thread_suspend (%4.4x)", m_tid);
// }
// }
return true;
}
示例10: read
rnb_err_t
RNBSocket::Read (std::string &p)
{
char buf[1024];
p.clear();
// Note that BUF is on the stack so we must be careful to keep any
// writes to BUF from overflowing or we'll have security issues.
if (m_fd == -1)
return rnb_err;
//DNBLogThreadedIf(LOG_RNB_COMM, "%8u RNBSocket::%s calling read()", (uint32_t)m_timer.ElapsedMicroSeconds(true), __FUNCTION__);
DNBError err;
int bytesread = read (m_fd, buf, sizeof (buf));
if (bytesread <= 0)
err.SetError(errno, DNBError::POSIX);
else
p.append(buf, bytesread);
if (err.Fail() || DNBLogCheckLogBit(LOG_RNB_COMM))
err.LogThreaded("::read ( %i, %p, %zu ) => %i", m_fd, buf, sizeof (buf), bytesread);
// Our port went away - we have to mark this so IsConnected will return the truth.
if (bytesread == 0)
{
m_fd = -1;
return rnb_not_connected;
}
else if (bytesread == -1)
{
m_fd = -1;
return rnb_err;
}
// Strip spaces from the end of the buffer
while (!p.empty() && isspace (p[p.size() - 1]))
p.erase (p.size () - 1);
// Most data in the debugserver packets valid printable characters...
DNBLogThreadedIf(LOG_RNB_COMM, "read: %s", p.c_str());
return rnb_success;
}
示例11: DNBLogThreadedIf
bool
MachTask::StartExceptionThread(DNBError &err)
{
DNBLogThreadedIf(LOG_EXCEPTIONS, "MachTask::%s ( )", __FUNCTION__);
task_t task = TaskPortForProcessID(err);
if (MachTask::IsValid(task))
{
// Got the mach port for the current process
mach_port_t task_self = mach_task_self ();
// Allocate an exception port that we will use to track our child process
err = ::mach_port_allocate (task_self, MACH_PORT_RIGHT_RECEIVE, &m_exception_port);
if (err.Fail())
return false;
// Add the ability to send messages on the new exception port
err = ::mach_port_insert_right (task_self, m_exception_port, m_exception_port, MACH_MSG_TYPE_MAKE_SEND);
if (err.Fail())
return false;
// Save the original state of the exception ports for our child process
SaveExceptionPortInfo();
// We weren't able to save the info for our exception ports, we must stop...
if (m_exc_port_info.mask == 0)
{
err.SetErrorString("failed to get exception port info");
return false;
}
// Set the ability to get all exceptions on this port
err = ::task_set_exception_ports (task, m_exc_port_info.mask, m_exception_port, EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE);
if (DNBLogCheckLogBit(LOG_EXCEPTIONS) || err.Fail())
{
err.LogThreaded("::task_set_exception_ports ( task = 0x%4.4x, exception_mask = 0x%8.8x, new_port = 0x%4.4x, behavior = 0x%8.8x, new_flavor = 0x%8.8x )",
task,
m_exc_port_info.mask,
m_exception_port,
(EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES),
THREAD_STATE_NONE);
}
if (err.Fail())
return false;
// Create the exception thread
err = ::pthread_create (&m_exception_thread, NULL, MachTask::ExceptionThread, this);
return err.Success();
}
else
{
DNBLogError("MachTask::%s (): task invalid, exception thread start failed.", __FUNCTION__);
}
return false;
}
示例12: sizeof
nub_addr_t
MachTask::GetDYLDAllImageInfosAddress (DNBError& err)
{
struct hack_task_dyld_info dyld_info;
mach_msg_type_number_t count = TASK_DYLD_INFO_COUNT;
// Make sure that COUNT isn't bigger than our hacked up struct hack_task_dyld_info.
// If it is, then make COUNT smaller to match.
if (count > (sizeof(struct hack_task_dyld_info) / sizeof(natural_t)))
count = (sizeof(struct hack_task_dyld_info) / sizeof(natural_t));
task_t task = TaskPortForProcessID (err);
if (err.Success())
{
err = ::task_info (task, TASK_DYLD_INFO, (task_info_t)&dyld_info, &count);
if (err.Success())
{
// We now have the address of the all image infos structure
return dyld_info.all_image_info_addr;
}
}
return INVALID_NUB_ADDRESS;
}
示例13: DNBLogThreadedIf
bool
MachTask::StartExceptionThread(DNBError &err)
{
DNBLogThreadedIf(LOG_EXCEPTIONS, "MachTask::%s ( )", __FUNCTION__);
task_t task = TaskPortForProcessID(err);
if (MachTask::IsValid(task))
{
// Got the mach port for the current process
mach_port_t task_self = mach_task_self ();
// Allocate an exception port that we will use to track our child process
err = ::mach_port_allocate (task_self, MACH_PORT_RIGHT_RECEIVE, &m_exception_port);
if (err.Fail())
return false;
// Add the ability to send messages on the new exception port
err = ::mach_port_insert_right (task_self, m_exception_port, m_exception_port, MACH_MSG_TYPE_MAKE_SEND);
if (err.Fail())
return false;
// Save the original state of the exception ports for our child process
SaveExceptionPortInfo();
// Set the ability to get all exceptions on this port
err = ::task_set_exception_ports (task, EXC_MASK_ALL, m_exception_port, EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, THREAD_STATE_NONE);
if (err.Fail())
return false;
// Create the exception thread
err = ::pthread_create (&m_exception_thread, NULL, MachTask::ExceptionThread, this);
return err.Success();
}
else
{
DNBLogError("MachTask::%s (): task invalid, exception thread start failed.", __FUNCTION__);
}
return false;
}
示例14: open
rnb_err_t
RNBSocket::OpenFile (const char *path)
{
DNBError err;
m_fd = open (path, O_RDWR);
if (m_fd == -1)
{
err.SetError(errno, DNBError::POSIX);
err.LogThreaded ("can't open file '%s'", path);
return rnb_not_connected;
}
else
{
struct termios stdin_termios;
if (::tcgetattr (m_fd, &stdin_termios) == 0)
{
stdin_termios.c_lflag &= ~ECHO; // Turn off echoing
stdin_termios.c_lflag &= ~ICANON; // Get one char at a time
::tcsetattr (m_fd, TCSANOW, &stdin_termios);
}
}
return rnb_success;
}
示例15: DNBLogThreadedIf
kern_return_t
MachException::PortInfo::Restore (task_t task)
{
DNBLogThreadedIf(LOG_EXCEPTIONS | LOG_VERBOSE, "MachException::PortInfo::Restore( task = 0x%4.4x )", task);
uint32_t i = 0;
DNBError err;
if (count > 0)
{
for (i = 0; i < count; i++)
{
err = ::task_set_exception_ports (task, masks[i], ports[i], behaviors[i], flavors[i]);
if (DNBLogCheckLogBit(LOG_EXCEPTIONS) || err.Fail())
{
err.LogThreaded("::task_set_exception_ports ( task = 0x%4.4x, exception_mask = 0x%8.8x, new_port = 0x%4.4x, behavior = 0x%8.8x, new_flavor = 0x%8.8x )", task, masks[i], ports[i], behaviors[i], flavors[i]);
// Bail if we encounter any errors
}
if (err.Fail())
break;
}
}
count = 0;
return err.Error();
}