summaryrefslogtreecommitdiff
path: root/tools/debugserver/source/MacOSX
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:36 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:12:36 +0000
commitef5d0b5e97ec8e6fa395d377b09aa7755e345b4f (patch)
tree27916256fdeeb57d10d2f3d6948be5d71a703215 /tools/debugserver/source/MacOSX
parent76e0736e7fcfeb179779e49c05604464b1ccd704 (diff)
Notes
Diffstat (limited to 'tools/debugserver/source/MacOSX')
-rw-r--r--tools/debugserver/source/MacOSX/MachException.cpp21
-rw-r--r--tools/debugserver/source/MacOSX/MachException.h9
-rw-r--r--tools/debugserver/source/MacOSX/MachProcess.mm112
-rw-r--r--tools/debugserver/source/MacOSX/MachTask.mm2
-rw-r--r--tools/debugserver/source/MacOSX/MachThread.cpp10
-rw-r--r--tools/debugserver/source/MacOSX/OsLogger.cpp4
-rw-r--r--tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp12
-rw-r--r--tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp12
8 files changed, 115 insertions, 67 deletions
diff --git a/tools/debugserver/source/MacOSX/MachException.cpp b/tools/debugserver/source/MacOSX/MachException.cpp
index 5f085867db2cd..cc309e47d86bf 100644
--- a/tools/debugserver/source/MacOSX/MachException.cpp
+++ b/tools/debugserver/source/MacOSX/MachException.cpp
@@ -47,13 +47,13 @@ extern "C" kern_return_t catch_mach_exception_raise_state_identity(
extern "C" boolean_t mach_exc_server(mach_msg_header_t *InHeadP,
mach_msg_header_t *OutHeadP);
-// Any access to the g_message variable should be done by locking the
-// g_message_mutex first, using the g_message variable, then unlocking
-// the g_message_mutex. See MachException::Message::CatchExceptionRaise()
-// for sample code.
-
+// Note: g_message points to the storage allocated to catch the data from
+// catching the current exception raise. It's populated when we catch a raised
+// exception which can't immediately be replied to.
+//
+// If it becomes possible to catch exceptions from multiple threads
+// simultaneously, accesses to g_message would need to be mutually exclusive.
static MachException::Data *g_message = NULL;
-// static pthread_mutex_t g_message_mutex = PTHREAD_MUTEX_INITIALIZER;
extern "C" kern_return_t catch_mach_exception_raise_state(
mach_port_t exc_port, exception_type_t exc_type,
@@ -113,8 +113,7 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port,
g_message->task_port = task_port;
g_message->thread_port = thread_port;
g_message->exc_type = exc_type;
- for (mach_msg_type_number_t i=0; i<exc_data_count; ++i)
- g_message->exc_data.push_back(exc_data[i]);
+ g_message->AppendExceptionData(exc_data, exc_data_count);
return KERN_SUCCESS;
} else if (!MachTask::IsValid(g_message->task_port)) {
// Our original exception port isn't valid anymore check for a SIGTRAP
@@ -126,8 +125,7 @@ catch_mach_exception_raise(mach_port_t exc_port, mach_port_t thread_port,
g_message->task_port = task_port;
g_message->thread_port = thread_port;
g_message->exc_type = exc_type;
- for (mach_msg_type_number_t i=0; i<exc_data_count; ++i)
- g_message->exc_data.push_back(exc_data[i]);
+ g_message->AppendExceptionData(exc_data, exc_data_count);
return KERN_SUCCESS;
}
}
@@ -272,9 +270,6 @@ kern_return_t MachException::Message::Receive(mach_port_t port,
bool MachException::Message::CatchExceptionRaise(task_t task) {
bool success = false;
- // locker will keep a mutex locked until it goes out of scope
- // PThreadMutex::Locker locker(&g_message_mutex);
- // DNBLogThreaded("calling mach_exc_server");
state.task_port = task;
g_message = &state;
// The exc_server function is the MIG generated server handling function
diff --git a/tools/debugserver/source/MacOSX/MachException.h b/tools/debugserver/source/MacOSX/MachException.h
index a45a41e01f42f..e1af12def10a7 100644
--- a/tools/debugserver/source/MacOSX/MachException.h
+++ b/tools/debugserver/source/MacOSX/MachException.h
@@ -71,6 +71,15 @@ public:
return (exc_type == EXC_BREAKPOINT ||
((exc_type == EXC_SOFTWARE) && exc_data[0] == 1));
}
+ void AppendExceptionData(mach_exception_data_t Data,
+ mach_msg_type_number_t Count) {
+ mach_exception_data_type_t Buf;
+ for (mach_msg_type_number_t i = 0; i < Count; ++i) {
+ // Perform an unaligned copy.
+ memcpy(&Buf, Data + i, sizeof(mach_exception_data_type_t));
+ exc_data.push_back(Buf);
+ }
+ }
void Dump() const;
void DumpStopReason() const;
bool GetStopInfo(struct DNBThreadStopInfo *stop_info) const;
diff --git a/tools/debugserver/source/MacOSX/MachProcess.mm b/tools/debugserver/source/MacOSX/MachProcess.mm
index a93f724849b82..d4dff223bde0a 100644
--- a/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -112,7 +112,9 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
if (!cstr)
cstr = "<Unknown Bundle ID>";
- DNBLog("About to launch process for bundle ID: %s", cstr);
+ NSString *description = [options description];
+ DNBLog("About to launch process for bundle ID: %s - options:\n%s", cstr,
+ [description UTF8String]);
[system_service
openApplication:bundleIDNSStr
options:options
@@ -188,6 +190,28 @@ static bool CallBoardSystemServiceOpenApplication(NSString *bundleIDNSStr,
}
#endif
+#if defined(WITH_BKS) || defined(WITH_FBS)
+static void SplitEventData(const char *data, std::vector<std::string> &elements)
+{
+ elements.clear();
+ if (!data)
+ return;
+
+ const char *start = data;
+
+ while (*start != '\0') {
+ const char *token = strchr(start, ':');
+ if (!token) {
+ elements.push_back(std::string(start));
+ return;
+ }
+ if (token != start)
+ elements.push_back(std::string(start, token - start));
+ start = ++token;
+ }
+}
+#endif
+
#ifdef WITH_BKS
#import <Foundation/Foundation.h>
extern "C" {
@@ -222,21 +246,31 @@ static void SetBKSError(NSInteger error_code, DNBError &error) {
static bool BKSAddEventDataToOptions(NSMutableDictionary *options,
const char *event_data,
DNBError &option_error) {
- if (strcmp(event_data, "BackgroundContentFetching") == 0) {
- DNBLog("Setting ActivateForEvent key in options dictionary.");
- NSDictionary *event_details = [NSDictionary dictionary];
- NSDictionary *event_dictionary = [NSDictionary
- dictionaryWithObject:event_details
- forKey:
- BKSActivateForEventOptionTypeBackgroundContentFetching];
- [options setObject:event_dictionary
- forKey:BKSOpenApplicationOptionKeyActivateForEvent];
- return true;
- } else {
- DNBLogError("Unrecognized event type: %s. Ignoring.", event_data);
- option_error.SetErrorString("Unrecognized event data.");
- return false;
+ std::vector<std::string> values;
+ SplitEventData(event_data, values);
+ bool found_one = false;
+ for (std::string value : values)
+ {
+ if (value.compare("BackgroundContentFetching") == 0) {
+ DNBLog("Setting ActivateForEvent key in options dictionary.");
+ NSDictionary *event_details = [NSDictionary dictionary];
+ NSDictionary *event_dictionary = [NSDictionary
+ dictionaryWithObject:event_details
+ forKey:
+ BKSActivateForEventOptionTypeBackgroundContentFetching];
+ [options setObject:event_dictionary
+ forKey:BKSOpenApplicationOptionKeyActivateForEvent];
+ found_one = true;
+ } else if (value.compare("ActivateSuspended") == 0) {
+ DNBLog("Setting ActivateSuspended key in options dictionary.");
+ [options setObject:@YES forKey: BKSOpenApplicationOptionKeyActivateSuspended];
+ found_one = true;
+ } else {
+ DNBLogError("Unrecognized event type: %s. Ignoring.", value.c_str());
+ option_error.SetErrorString("Unrecognized event data");
+ }
}
+ return found_one;
}
static NSMutableDictionary *BKSCreateOptionsDictionary(
@@ -322,21 +356,31 @@ static void SetFBSError(NSInteger error_code, DNBError &error) {
static bool FBSAddEventDataToOptions(NSMutableDictionary *options,
const char *event_data,
DNBError &option_error) {
- if (strcmp(event_data, "BackgroundContentFetching") == 0) {
- DNBLog("Setting ActivateForEvent key in options dictionary.");
- NSDictionary *event_details = [NSDictionary dictionary];
- NSDictionary *event_dictionary = [NSDictionary
- dictionaryWithObject:event_details
- forKey:
- FBSActivateForEventOptionTypeBackgroundContentFetching];
- [options setObject:event_dictionary
- forKey:FBSOpenApplicationOptionKeyActivateForEvent];
- return true;
- } else {
- DNBLogError("Unrecognized event type: %s. Ignoring.", event_data);
- option_error.SetErrorString("Unrecognized event data.");
- return false;
+ std::vector<std::string> values;
+ SplitEventData(event_data, values);
+ bool found_one = false;
+ for (std::string value : values)
+ {
+ if (value.compare("BackgroundContentFetching") == 0) {
+ DNBLog("Setting ActivateForEvent key in options dictionary.");
+ NSDictionary *event_details = [NSDictionary dictionary];
+ NSDictionary *event_dictionary = [NSDictionary
+ dictionaryWithObject:event_details
+ forKey:
+ FBSActivateForEventOptionTypeBackgroundContentFetching];
+ [options setObject:event_dictionary
+ forKey:FBSOpenApplicationOptionKeyActivateForEvent];
+ found_one = true;
+ } else if (value.compare("ActivateSuspended") == 0) {
+ DNBLog("Setting ActivateSuspended key in options dictionary.");
+ [options setObject:@YES forKey: FBSOpenApplicationOptionKeyActivateSuspended];
+ found_one = true;
+ } else {
+ DNBLogError("Unrecognized event type: %s. Ignoring.", value.c_str());
+ option_error.SetErrorString("Unrecognized event data.");
+ }
}
+ return found_one;
}
static NSMutableDictionary *
@@ -3105,7 +3149,8 @@ pid_t MachProcess::PosixSpawnChildForPTraceDebugging(
::chdir(working_directory);
err.SetError(::posix_spawnp(&pid, path, &file_actions, &attr,
- (char *const *)argv, (char *const *)envp),
+ const_cast<char *const *>(argv),
+ const_cast<char *const *>(envp)),
DNBError::POSIX);
if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))
err.LogThreaded("::posix_spawnp ( pid => %i, path = '%s', file_actions = "
@@ -3117,8 +3162,9 @@ pid_t MachProcess::PosixSpawnChildForPTraceDebugging(
if (working_directory)
::chdir(working_directory);
- err.SetError(::posix_spawnp(&pid, path, NULL, &attr, (char *const *)argv,
- (char *const *)envp),
+ err.SetError(::posix_spawnp(&pid, path, NULL, &attr,
+ const_cast<char *const *>(argv),
+ const_cast<char *const *>(envp)),
DNBError::POSIX);
if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS))
err.LogThreaded("::posix_spawnp ( pid => %i, path = '%s', file_actions = "
@@ -3215,7 +3261,7 @@ pid_t MachProcess::ForkChildForPTraceDebugging(const char *path,
::sleep(1);
// Turn this process into
- ::execv(path, (char *const *)argv);
+ ::execv(path, const_cast<char *const *>(argv));
}
// Exit with error code. Child process should have taken
// over in above exec call and if the exec fails it will
diff --git a/tools/debugserver/source/MacOSX/MachTask.mm b/tools/debugserver/source/MacOSX/MachTask.mm
index bd7047ecdff77..1d177bd53cb70 100644
--- a/tools/debugserver/source/MacOSX/MachTask.mm
+++ b/tools/debugserver/source/MacOSX/MachTask.mm
@@ -188,7 +188,7 @@ nub_size_t MachTask::WriteMemory(nub_addr_t addr, nub_size_t size,
(uint64_t)addr, (uint64_t)size, buf, (uint64_t)n);
if (DNBLogCheckLogBit(LOG_MEMORY_DATA_LONG) ||
(DNBLogCheckLogBit(LOG_MEMORY_DATA_SHORT) && size <= 8)) {
- DNBDataRef data((uint8_t *)buf, n, false);
+ DNBDataRef data((const uint8_t *)buf, n, false);
data.Dump(0, static_cast<DNBDataRef::offset_t>(n), addr,
DNBDataRef::TypeUInt8, 16);
}
diff --git a/tools/debugserver/source/MacOSX/MachThread.cpp b/tools/debugserver/source/MacOSX/MachThread.cpp
index 5686e42e4a497..fc97825786a02 100644
--- a/tools/debugserver/source/MacOSX/MachThread.cpp
+++ b/tools/debugserver/source/MacOSX/MachThread.cpp
@@ -164,15 +164,15 @@ const char *MachThread::GetBasicInfoAsString() const {
// size_t run_state_str_size = sizeof(run_state_str);
// switch (basicInfo.run_state)
// {
- // case TH_STATE_RUNNING: strncpy(run_state_str, "running",
+ // case TH_STATE_RUNNING: strlcpy(run_state_str, "running",
// run_state_str_size); break;
- // case TH_STATE_STOPPED: strncpy(run_state_str, "stopped",
+ // case TH_STATE_STOPPED: strlcpy(run_state_str, "stopped",
// run_state_str_size); break;
- // case TH_STATE_WAITING: strncpy(run_state_str, "waiting",
+ // case TH_STATE_WAITING: strlcpy(run_state_str, "waiting",
// run_state_str_size); break;
- // case TH_STATE_UNINTERRUPTIBLE: strncpy(run_state_str,
+ // case TH_STATE_UNINTERRUPTIBLE: strlcpy(run_state_str,
// "uninterruptible", run_state_str_size); break;
- // case TH_STATE_HALTED: strncpy(run_state_str, "halted",
+ // case TH_STATE_HALTED: strlcpy(run_state_str, "halted",
// run_state_str_size); break;
// default: snprintf(run_state_str,
// run_state_str_size, "%d", basicInfo.run_state); break; // ???
diff --git a/tools/debugserver/source/MacOSX/OsLogger.cpp b/tools/debugserver/source/MacOSX/OsLogger.cpp
index 6cc04a8a7c839..40aeec73f0aa2 100644
--- a/tools/debugserver/source/MacOSX/OsLogger.cpp
+++ b/tools/debugserver/source/MacOSX/OsLogger.cpp
@@ -56,9 +56,7 @@ void DarwinLogCallback(void *baton, uint32_t flags, const char *format,
}
}
-DNBCallbackLog OsLogger::GetLogFunction() {
- return _os_log_impl ? DarwinLogCallback : nullptr;
-}
+DNBCallbackLog OsLogger::GetLogFunction() { return DarwinLogCallback; }
#else
diff --git a/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp b/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
index 6cc5ae6c36c4b..e0e8e27a1c2da 100644
--- a/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
+++ b/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
@@ -1086,7 +1086,7 @@ const DNBRegisterInfo DNBArchImplI386::g_fpu_registers_no_avx[] = {
{e_regSetFPU, fpu_fsw, "fstat", NULL, Uint, Hex, FPU_SIZE_UINT(fsw),
FPU_OFFSET(fsw), INVALID_NUB_REGNUM, INVALID_NUB_REGNUM,
INVALID_NUB_REGNUM, INVALID_NUB_REGNUM, NULL, NULL},
- {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, FPU_SIZE_UINT(ftw),
+ {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, 2 /* sizeof __fpu_ftw + sizeof __fpu_rsrv1 */,
FPU_OFFSET(ftw), INVALID_NUB_REGNUM, INVALID_NUB_REGNUM,
INVALID_NUB_REGNUM, INVALID_NUB_REGNUM, NULL, NULL},
{e_regSetFPU, fpu_fop, "fop", NULL, Uint, Hex, FPU_SIZE_UINT(fop),
@@ -1177,7 +1177,7 @@ const DNBRegisterInfo DNBArchImplI386::g_fpu_registers_avx[] = {
{e_regSetFPU, fpu_fsw, "fstat", NULL, Uint, Hex, FPU_SIZE_UINT(fsw),
AVX_OFFSET(fsw), INVALID_NUB_REGNUM, INVALID_NUB_REGNUM,
INVALID_NUB_REGNUM, INVALID_NUB_REGNUM, NULL, NULL},
- {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, FPU_SIZE_UINT(ftw),
+ {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, 2 /* sizeof __fpu_ftw + sizeof __fpu_rsrv1 */,
AVX_OFFSET(ftw), INVALID_NUB_REGNUM, INVALID_NUB_REGNUM,
INVALID_NUB_REGNUM, INVALID_NUB_REGNUM, NULL, NULL},
{e_regSetFPU, fpu_fop, "fop", NULL, Uint, Hex, FPU_SIZE_UINT(fop),
@@ -1414,7 +1414,7 @@ bool DNBArchImplI386::GetRegisterValue(uint32_t set, uint32_t reg,
*((uint16_t *)(&m_state.context.fpu.no_avx.__fpu_fsw));
return true;
case fpu_ftw:
- value->value.uint8 = m_state.context.fpu.no_avx.__fpu_ftw;
+ memcpy (&value->value.uint16, &m_state.context.fpu.no_avx.__fpu_ftw, 2);
return true;
case fpu_fop:
value->value.uint16 = m_state.context.fpu.no_avx.__fpu_fop;
@@ -1607,7 +1607,7 @@ bool DNBArchImplI386::SetRegisterValue(uint32_t set, uint32_t reg,
success = true;
break;
case fpu_ftw:
- m_state.context.fpu.no_avx.__fpu_ftw = value->value.uint8;
+ memcpy (&m_state.context.fpu.no_avx.__fpu_ftw, &value->value.uint16, 2);
success = true;
break;
case fpu_fop:
@@ -1886,7 +1886,7 @@ nub_size_t DNBArchImplI386::SetRegisterContext(const void *buf,
if (size > buf_len)
size = buf_len;
- uint8_t *p = (uint8_t *)buf;
+ const uint8_t *p = (const uint8_t *)buf;
// Copy the GPR registers
memcpy(&m_state.context.gpr, p, sizeof(GPR));
p += sizeof(GPR);
@@ -1927,7 +1927,7 @@ nub_size_t DNBArchImplI386::SetRegisterContext(const void *buf,
p += sizeof(EXC);
// make sure we end up with exactly what we think we should have
- size_t bytes_written = p - (uint8_t *)buf;
+ size_t bytes_written = p - (const uint8_t *)buf;
UNUSED_IF_ASSERT_DISABLED(bytes_written);
assert(bytes_written == size);
kern_return_t kret;
diff --git a/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp b/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
index 416b21f29958a..86843fd97c065 100644
--- a/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
+++ b/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
@@ -1380,7 +1380,7 @@ const DNBRegisterInfo DNBArchImplX86_64::g_fpu_registers_no_avx[] = {
FPU_OFFSET(fcw), -1U, -1U, -1U, -1U, NULL, NULL},
{e_regSetFPU, fpu_fsw, "fstat", NULL, Uint, Hex, FPU_SIZE_UINT(fsw),
FPU_OFFSET(fsw), -1U, -1U, -1U, -1U, NULL, NULL},
- {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, FPU_SIZE_UINT(ftw),
+ {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, 2 /* sizeof __fpu_ftw + sizeof __fpu_rsrv1 */,
FPU_OFFSET(ftw), -1U, -1U, -1U, -1U, NULL, NULL},
{e_regSetFPU, fpu_fop, "fop", NULL, Uint, Hex, FPU_SIZE_UINT(fop),
FPU_OFFSET(fop), -1U, -1U, -1U, -1U, NULL, NULL},
@@ -1495,7 +1495,7 @@ const DNBRegisterInfo DNBArchImplX86_64::g_fpu_registers_avx[] = {
AVX_OFFSET(fcw), -1U, -1U, -1U, -1U, NULL, NULL},
{e_regSetFPU, fpu_fsw, "fstat", NULL, Uint, Hex, FPU_SIZE_UINT(fsw),
AVX_OFFSET(fsw), -1U, -1U, -1U, -1U, NULL, NULL},
- {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, FPU_SIZE_UINT(ftw),
+ {e_regSetFPU, fpu_ftw, "ftag", NULL, Uint, Hex, 2 /* sizeof __fpu_ftw + sizeof __fpu_rsrv1 */,
AVX_OFFSET(ftw), -1U, -1U, -1U, -1U, NULL, NULL},
{e_regSetFPU, fpu_fop, "fop", NULL, Uint, Hex, FPU_SIZE_UINT(fop),
AVX_OFFSET(fop), -1U, -1U, -1U, -1U, NULL, NULL},
@@ -1776,7 +1776,7 @@ bool DNBArchImplX86_64::GetRegisterValue(uint32_t set, uint32_t reg,
*((uint16_t *)(&m_state.context.fpu.no_avx.__fpu_fsw));
return true;
case fpu_ftw:
- value->value.uint8 = m_state.context.fpu.no_avx.__fpu_ftw;
+ memcpy (&value->value.uint16, &m_state.context.fpu.no_avx.__fpu_ftw, 2);
return true;
case fpu_fop:
value->value.uint16 = m_state.context.fpu.no_avx.__fpu_fop;
@@ -1932,7 +1932,7 @@ bool DNBArchImplX86_64::SetRegisterValue(uint32_t set, uint32_t reg,
success = true;
break;
case fpu_ftw:
- m_state.context.fpu.no_avx.__fpu_ftw = value->value.uint8;
+ memcpy (&m_state.context.fpu.no_avx.__fpu_ftw, &value->value.uint8, 2);
success = true;
break;
case fpu_fop:
@@ -2164,7 +2164,7 @@ nub_size_t DNBArchImplX86_64::SetRegisterContext(const void *buf,
if (size > buf_len)
size = static_cast<uint32_t>(buf_len);
- uint8_t *p = (uint8_t *)buf;
+ const uint8_t *p = (const uint8_t *)buf;
// Copy the GPR registers
memcpy(&m_state.context.gpr, p, sizeof(GPR));
p += sizeof(GPR);
@@ -2205,7 +2205,7 @@ nub_size_t DNBArchImplX86_64::SetRegisterContext(const void *buf,
p += sizeof(EXC);
// make sure we end up with exactly what we think we should have
- size_t bytes_written = p - (uint8_t *)buf;
+ size_t bytes_written = p - (const uint8_t *)buf;
UNUSED_IF_ASSERT_DISABLED(bytes_written);
assert(bytes_written == size);