summaryrefslogtreecommitdiff
path: root/tools/debugserver/source
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
parent76e0736e7fcfeb179779e49c05604464b1ccd704 (diff)
Notes
Diffstat (limited to 'tools/debugserver/source')
-rw-r--r--tools/debugserver/source/CMakeLists.txt112
-rw-r--r--tools/debugserver/source/DNB.cpp6
-rw-r--r--tools/debugserver/source/DNBDataRef.cpp12
-rw-r--r--tools/debugserver/source/DNBRegisterInfo.cpp4
-rw-r--r--tools/debugserver/source/JSON.cpp3
-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
-rw-r--r--tools/debugserver/source/RNBRemote.cpp76
-rw-r--r--tools/debugserver/source/RNBServices.cpp2
-rw-r--r--tools/debugserver/source/RNBSocket.cpp5
-rw-r--r--tools/debugserver/source/debugserver.cpp6
17 files changed, 271 insertions, 137 deletions
diff --git a/tools/debugserver/source/CMakeLists.txt b/tools/debugserver/source/CMakeLists.txt
index bdca1602f4a89..d99880cd97f3f 100644
--- a/tools/debugserver/source/CMakeLists.txt
+++ b/tools/debugserver/source/CMakeLists.txt
@@ -1,4 +1,5 @@
include(CheckCXXCompilerFlag)
+include(CheckLibraryExists)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
include_directories(${LLDB_SOURCE_DIR}/source)
include_directories(MacOSX/DarwinLog)
@@ -26,6 +27,8 @@ if (CXX_SUPPORTS_NO_EXTENDED_OFFSETOF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extended-offsetof")
endif ()
+check_library_exists(compression compression_encode_buffer "" HAVE_LIBCOMPRESSION)
+
add_subdirectory(MacOSX)
set(generated_mach_interfaces
@@ -94,32 +97,108 @@ add_library(lldbDebugserverCommon ${lldbDebugserverCommonSources})
if (APPLE)
if(IOS)
- find_library(COCOA_LIBRARY UIKit)
- target_link_libraries(lldbDebugserverCommon INTERFACE ${COCOA_LIBRARY} ${CORE_FOUNDATION_LIBRARY} ${FOUNDATION_LIBRARY})
+ find_library(BACKBOARD_LIBRARY BackBoardServices
+ PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+ find_library(FRONTBOARD_LIBRARY FrontBoardServices
+ PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+ find_library(SPRINGBOARD_LIBRARY SpringBoardServices
+ PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+ find_library(MOBILESERVICES_LIBRARY MobileCoreServices
+ PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+ find_library(LOCKDOWN_LIBRARY lockdown)
+
+ if(NOT BACKBOARD_LIBRARY)
+ set(SKIP_DEBUGSERVER True)
+ endif()
else()
find_library(COCOA_LIBRARY Cocoa)
- target_link_libraries(lldbDebugserverCommon INTERFACE ${COCOA_LIBRARY})
endif()
endif()
-target_link_libraries(lldbDebugserverCommon
+if(HAVE_LIBCOMPRESSION)
+ set(LIBCOMPRESSION compression)
+endif()
+
+if(NOT SKIP_DEBUGSERVER)
+ target_link_libraries(lldbDebugserverCommon
+ INTERFACE ${COCOA_LIBRARY}
+ ${CORE_FOUNDATION_LIBRARY}
+ ${FOUNDATION_LIBRARY}
+ ${BACKBOARD_LIBRARY}
+ ${FRONTBOARD_LIBRARY}
+ ${SPRINGBOARD_LIBRARY}
+ ${MOBILESERVICES_LIBRARY}
+ ${LOCKDOWN_LIBRARY}
+ lldbDebugserverArchSupport
+ lldbDebugserverDarwin_DarwinLog
+ ${LIBCOMPRESSION})
+ if(HAVE_LIBCOMPRESSION)
+ set_property(TARGET lldbDebugserverCommon APPEND PROPERTY
+ COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION)
+ endif()
+ set(LLVM_OPTIONAL_SOURCES ${lldbDebugserverCommonSources})
+ add_lldb_tool(debugserver INCLUDE_IN_FRAMEWORK
+ debugserver.cpp
+
+ LINK_LIBS
+ lldbDebugserverCommon
+ )
+ if(IOS)
+ set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
+ WITH_LOCKDOWN
+ WITH_FBS
+ WITH_BKS
+ )
+ set_property(TARGET debugserver APPEND PROPERTY COMPILE_DEFINITIONS
+ WITH_LOCKDOWN
+ WITH_FBS
+ WITH_BKS
+ )
+ set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_FLAGS
+ -F${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks
+ )
+ endif()
+endif()
+
+if(IOS)
+ add_library(lldbDebugserverCommon_NonUI ${lldbDebugserverCommonSources})
+ target_link_libraries(lldbDebugserverCommon_NonUI
INTERFACE ${COCOA_LIBRARY}
${CORE_FOUNDATION_LIBRARY}
${FOUNDATION_LIBRARY}
lldbDebugserverArchSupport
- lldbDebugserverDarwin_DarwinLog)
+ lldbDebugserverDarwin_DarwinLog
+ ${LIBCOMPRESSION})
+ if(HAVE_LIBCOMPRESSION)
+ set_property(TARGET lldbDebugserverCommon_NonUI APPEND PROPERTY
+ COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION)
+ endif()
-set(LLVM_OPTIONAL_SOURCES ${lldbDebugserverCommonSources})
-add_lldb_tool(debugserver INCLUDE_IN_FRAMEWORK
- debugserver.cpp
+ add_lldb_tool(debugserver-nonui
+ debugserver.cpp
- LINK_LIBS
- lldbDebugserverCommon
- )
+ LINK_LIBS
+ lldbDebugserverCommon_NonUI
+ )
+endif()
+
+set(entitlements_xml ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-macosx-entitlements.plist)
+if(IOS)
+ set(entitlements_xml ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-entitlements.plist)
+endif()
set(LLDB_CODESIGN_IDENTITY "lldb_codesign"
CACHE STRING "Identity used for code signing. Set to empty string to skip the signing step.")
+set(LLDB_USE_ENTITLEMENTS_Default On)
+if("${LLDB_CODESIGN_IDENTITY}" STREQUAL "lldb_codesign")
+ set(LLDB_USE_ENTITLEMENTS_Default Off)
+endif()
+option(LLDB_USE_ENTITLEMENTS "Use entitlements when codesigning (Defaults Off when using lldb_codesign identity, otherwise On)" ${LLDB_USE_ENTITLEMENTS_Default})
+
if (NOT ("${LLDB_CODESIGN_IDENTITY}" STREQUAL ""))
+ if(LLDB_USE_ENTITLEMENTS)
+ set(entitlements_flags --entitlements ${entitlements_xml})
+ endif()
execute_process(
COMMAND xcrun -f codesign_allocate
OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -129,9 +208,20 @@ if (NOT ("${LLDB_CODESIGN_IDENTITY}" STREQUAL ""))
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E env CODESIGN_ALLOCATE=${CODESIGN_ALLOCATE}
codesign --force --sign ${LLDB_CODESIGN_IDENTITY}
+ ${entitlements_flags}
$<TARGET_FILE:debugserver>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
+ if(IOS)
+ add_custom_command(TARGET debugserver-nonui
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E env CODESIGN_ALLOCATE=${CODESIGN_ALLOCATE}
+ codesign --force --sign ${LLDB_CODESIGN_IDENTITY}
+ ${entitlements_flags}
+ $<TARGET_FILE:debugserver>
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
+ )
+ endif()
endif()
diff --git a/tools/debugserver/source/DNB.cpp b/tools/debugserver/source/DNB.cpp
index 9c6c44d18df1a..1168f1fc0a1e6 100644
--- a/tools/debugserver/source/DNB.cpp
+++ b/tools/debugserver/source/DNB.cpp
@@ -368,7 +368,7 @@ nub_process_t DNBProcessLaunch(
if (launch_err.Fail()) {
const char *launch_err_str = launch_err.AsString();
if (launch_err_str) {
- strncpy(err_str, launch_err_str, err_len - 1);
+ strlcpy(err_str, launch_err_str, err_len - 1);
err_str[err_len - 1] =
'\0'; // Make sure the error string is terminated
}
@@ -1698,7 +1698,7 @@ nub_bool_t DNBResolveExecutablePath(const char *path, char *resolved_path,
if (realpath(path, max_path)) {
// Found the path relatively...
- ::strncpy(resolved_path, max_path, resolved_path_size);
+ ::strlcpy(resolved_path, max_path, resolved_path_size);
return strlen(resolved_path) + 1 < resolved_path_size;
} else {
// Not a relative path, check the PATH environment variable if the
@@ -1722,7 +1722,7 @@ nub_bool_t DNBResolveExecutablePath(const char *path, char *resolved_path,
result += path;
struct stat s;
if (stat(result.c_str(), &s) == 0) {
- ::strncpy(resolved_path, result.c_str(), resolved_path_size);
+ ::strlcpy(resolved_path, result.c_str(), resolved_path_size);
return result.size() + 1 < resolved_path_size;
}
}
diff --git a/tools/debugserver/source/DNBDataRef.cpp b/tools/debugserver/source/DNBDataRef.cpp
index d7dce1ab73389..8c12b0afac691 100644
--- a/tools/debugserver/source/DNBDataRef.cpp
+++ b/tools/debugserver/source/DNBDataRef.cpp
@@ -60,7 +60,7 @@ uint16_t DNBDataRef::Get16(offset_t *offset_ptr) const {
uint16_t val = 0;
if (ValidOffsetForDataOfSize(*offset_ptr, sizeof(val))) {
const uint8_t *p = m_start + *offset_ptr;
- val = *(uint16_t *)p;
+ memcpy(&val, p, sizeof(uint16_t));
if (m_swap)
val = OSSwapInt16(val);
@@ -78,7 +78,7 @@ uint32_t DNBDataRef::Get32(offset_t *offset_ptr) const {
uint32_t val = 0;
if (ValidOffsetForDataOfSize(*offset_ptr, sizeof(val))) {
const uint8_t *p = m_start + *offset_ptr;
- val = *(uint32_t *)p;
+ memcpy(&val, p, sizeof(uint32_t));
if (m_swap)
val = OSSwapInt32(val);
@@ -95,7 +95,7 @@ uint64_t DNBDataRef::Get64(offset_t *offset_ptr) const {
uint64_t val = 0;
if (ValidOffsetForDataOfSize(*offset_ptr, sizeof(val))) {
const uint8_t *p = m_start + *offset_ptr;
- val = *(uint64_t *)p;
+ memcpy(&val, p, sizeof(uint64_t));
if (m_swap)
val = OSSwapInt64(val);
@@ -123,7 +123,7 @@ uint32_t DNBDataRef::GetMax32(offset_t *offset_ptr, uint32_t byte_size) const {
return Get32(offset_ptr);
break;
default:
- assert(!"GetMax32 unhandled case!");
+ assert(false && "GetMax32 unhandled case!");
break;
}
return 0;
@@ -150,7 +150,7 @@ uint64_t DNBDataRef::GetMax64(offset_t *offset_ptr, uint32_t size) const {
return Get64(offset_ptr);
break;
default:
- assert(!"GetMax64 unhandled case!");
+ assert(false && "GetMax64 unhandled case!");
break;
}
return 0;
@@ -174,7 +174,7 @@ const char *DNBDataRef::GetCStr(offset_t *offset_ptr,
uint32_t fixed_length) const {
const char *s = NULL;
if (m_start < m_end) {
- s = (char *)m_start + *offset_ptr;
+ s = (const char *)m_start + *offset_ptr;
// Advance the offset
if (fixed_length)
diff --git a/tools/debugserver/source/DNBRegisterInfo.cpp b/tools/debugserver/source/DNBRegisterInfo.cpp
index fadcc5ddb06e7..b85b393781831 100644
--- a/tools/debugserver/source/DNBRegisterInfo.cpp
+++ b/tools/debugserver/source/DNBRegisterInfo.cpp
@@ -35,7 +35,7 @@ bool DNBRegisterValueClass::IsValid() const {
do { \
if (pos < end) { \
if (i > 0) { \
- strncpy(pos, ", ", end - pos); \
+ strlcpy(pos, ", ", end - pos); \
pos += 2; \
} \
} \
@@ -69,7 +69,7 @@ void DNBRegisterValueClass::Dump(const char *pre, const char *post) const {
value.v_uint64[1]);
break;
default:
- strncpy(str, "0x", 3);
+ strlcpy(str, "0x", 3);
pos = str + 2;
for (uint32_t i = 0; i < info.size; ++i) {
if (pos < end)
diff --git a/tools/debugserver/source/JSON.cpp b/tools/debugserver/source/JSON.cpp
index c914f2498f099..439918b6fcc4d 100644
--- a/tools/debugserver/source/JSON.cpp
+++ b/tools/debugserver/source/JSON.cpp
@@ -58,7 +58,6 @@ uint64_t JSONNumber::GetAsUnsigned() const {
case DataType::Double:
return (uint64_t)m_data.m_double;
}
- assert("Unhandled data type");
}
int64_t JSONNumber::GetAsSigned() const {
@@ -70,7 +69,6 @@ int64_t JSONNumber::GetAsSigned() const {
case DataType::Double:
return (int64_t)m_data.m_double;
}
- assert("Unhandled data type");
}
double JSONNumber::GetAsDouble() const {
@@ -82,7 +80,6 @@ double JSONNumber::GetAsDouble() const {
case DataType::Double:
return m_data.m_double;
}
- assert("Unhandled data type");
}
void JSONNumber::Write(std::ostream &s) {
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);
diff --git a/tools/debugserver/source/RNBRemote.cpp b/tools/debugserver/source/RNBRemote.cpp
index cf6b4b6269141..0a2eef3feacd9 100644
--- a/tools/debugserver/source/RNBRemote.cpp
+++ b/tools/debugserver/source/RNBRemote.cpp
@@ -710,29 +710,29 @@ std::string RNBRemote::CompressString(const std::string &orig) {
size_t compressed_size = 0;
#if defined(HAVE_LIBCOMPRESSION)
- if (compression_decode_buffer &&
- compression_type == compression_types::lz4) {
+ if (compression_type == compression_types::lz4) {
compressed_size = compression_encode_buffer(
- encoded_data.data(), encoded_data_buf_size, (uint8_t *)orig.c_str(),
- orig.size(), nullptr, COMPRESSION_LZ4_RAW);
+ encoded_data.data(), encoded_data_buf_size,
+ (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ COMPRESSION_LZ4_RAW);
}
- if (compression_decode_buffer &&
- compression_type == compression_types::zlib_deflate) {
+ if (compression_type == compression_types::zlib_deflate) {
compressed_size = compression_encode_buffer(
- encoded_data.data(), encoded_data_buf_size, (uint8_t *)orig.c_str(),
- orig.size(), nullptr, COMPRESSION_ZLIB);
+ encoded_data.data(), encoded_data_buf_size,
+ (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ COMPRESSION_ZLIB);
}
- if (compression_decode_buffer &&
- compression_type == compression_types::lzma) {
+ if (compression_type == compression_types::lzma) {
compressed_size = compression_encode_buffer(
- encoded_data.data(), encoded_data_buf_size, (uint8_t *)orig.c_str(),
- orig.size(), nullptr, COMPRESSION_LZMA);
+ encoded_data.data(), encoded_data_buf_size,
+ (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ COMPRESSION_LZMA);
}
- if (compression_decode_buffer &&
- compression_type == compression_types::lzfse) {
+ if (compression_type == compression_types::lzfse) {
compressed_size = compression_encode_buffer(
- encoded_data.data(), encoded_data_buf_size, (uint8_t *)orig.c_str(),
- orig.size(), nullptr, COMPRESSION_LZFSE);
+ encoded_data.data(), encoded_data_buf_size,
+ (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ COMPRESSION_LZFSE);
}
#endif
@@ -2247,7 +2247,7 @@ rnb_err_t set_logging(const char *p) {
continue;
}
char *fn = (char *) alloca (c - p + 1);
- strncpy (fn, p, c - p);
+ strlcpy (fn, p, c - p);
fn[c - p] = '\0';
// A file name of "asl" is special and is another way to indicate
@@ -2862,7 +2862,7 @@ rnb_err_t RNBRemote::SendStopReplyPacketForThread(nub_thread_t tid) {
else {
// the thread name contains special chars, send as hex bytes
ostrm << std::hex << "hexname:";
- uint8_t *u_thread_name = (uint8_t *)thread_name;
+ const uint8_t *u_thread_name = (const uint8_t *)thread_name;
for (size_t i = 0; i < thread_name_len; i++)
ostrm << RAWHEX8(u_thread_name[i]);
ostrm << ';';
@@ -3049,7 +3049,7 @@ rnb_err_t RNBRemote::HandlePacket_last_signal(const char *unused) {
// If we have an empty exit packet, lets fill one in to be safe.
if (!pid_exited_packet[0]) {
- strncpy(pid_exited_packet, "W00", sizeof(pid_exited_packet) - 1);
+ strlcpy(pid_exited_packet, "W00", sizeof(pid_exited_packet) - 1);
pid_exited_packet[sizeof(pid_exited_packet) - 1] = '\0';
}
@@ -3621,7 +3621,7 @@ rnb_err_t RNBRemote::HandlePacket_qSupported(const char *p) {
#if defined(HAVE_LIBCOMPRESSION)
// libcompression is weak linked so test if compression_decode_buffer() is
// available
- if (enable_compression && compression_decode_buffer != NULL) {
+ if (enable_compression) {
strcat(buf, ";SupportedCompressions=lzfse,zlib-deflate,lz4,lzma;"
"DefaultCompressionMinSize=");
char numbuf[16];
@@ -3667,7 +3667,7 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) {
return RNBRemote::HandlePacket_s("s");
} else if (strstr(p, "vCont") == p) {
DNBThreadResumeActions thread_actions;
- char *c = (char *)(p += strlen("vCont"));
+ char *c = const_cast<char *>(p += strlen("vCont"));
char *c_end = c + strlen(c);
if (*c == '?')
return SendPacket("vCont;c;C;s;S");
@@ -4307,24 +4307,22 @@ rnb_err_t RNBRemote::HandlePacket_QEnableCompression(const char *p) {
}
#if defined(HAVE_LIBCOMPRESSION)
- if (compression_decode_buffer != NULL) {
- if (strstr(p, "type:zlib-deflate;") != nullptr) {
- EnableCompressionNextSendPacket(compression_types::zlib_deflate);
- m_compression_minsize = new_compression_minsize;
- return SendPacket("OK");
- } else if (strstr(p, "type:lz4;") != nullptr) {
- EnableCompressionNextSendPacket(compression_types::lz4);
- m_compression_minsize = new_compression_minsize;
- return SendPacket("OK");
- } else if (strstr(p, "type:lzma;") != nullptr) {
- EnableCompressionNextSendPacket(compression_types::lzma);
- m_compression_minsize = new_compression_minsize;
- return SendPacket("OK");
- } else if (strstr(p, "type:lzfse;") != nullptr) {
- EnableCompressionNextSendPacket(compression_types::lzfse);
- m_compression_minsize = new_compression_minsize;
- return SendPacket("OK");
- }
+ if (strstr(p, "type:zlib-deflate;") != nullptr) {
+ EnableCompressionNextSendPacket(compression_types::zlib_deflate);
+ m_compression_minsize = new_compression_minsize;
+ return SendPacket("OK");
+ } else if (strstr(p, "type:lz4;") != nullptr) {
+ EnableCompressionNextSendPacket(compression_types::lz4);
+ m_compression_minsize = new_compression_minsize;
+ return SendPacket("OK");
+ } else if (strstr(p, "type:lzma;") != nullptr) {
+ EnableCompressionNextSendPacket(compression_types::lzma);
+ m_compression_minsize = new_compression_minsize;
+ return SendPacket("OK");
+ } else if (strstr(p, "type:lzfse;") != nullptr) {
+ EnableCompressionNextSendPacket(compression_types::lzfse);
+ m_compression_minsize = new_compression_minsize;
+ return SendPacket("OK");
}
#endif
diff --git a/tools/debugserver/source/RNBServices.cpp b/tools/debugserver/source/RNBServices.cpp
index d0b7e099d2383..9f90f349f3afb 100644
--- a/tools/debugserver/source/RNBServices.cpp
+++ b/tools/debugserver/source/RNBServices.cpp
@@ -220,7 +220,7 @@ int ListApplications(std::string &plist, bool opt_runningApps,
CFIndex size = ::CFDataGetLength(plistData.get());
const UInt8 *bytes = ::CFDataGetBytePtr(plistData.get());
if (bytes != NULL && size > 0) {
- plist.assign((char *)bytes, size);
+ plist.assign((const char *)bytes, size);
return 0; // Success
} else {
DNBLogError("empty application property list.");
diff --git a/tools/debugserver/source/RNBSocket.cpp b/tools/debugserver/source/RNBSocket.cpp
index f1db5e419ff25..88136c210acc0 100644
--- a/tools/debugserver/source/RNBSocket.cpp
+++ b/tools/debugserver/source/RNBSocket.cpp
@@ -373,9 +373,10 @@ rnb_err_t RNBSocket::Write(const void *buffer, size_t length) {
DNBLogThreadedIf(
LOG_RNB_PACKETS, "putpkt: %*s", (int)length,
- (char *)
+ (const char *)
buffer); // All data is string based in debugserver, so this is safe
- DNBLogThreadedIf(LOG_RNB_COMM, "sent: %*s", (int)length, (char *)buffer);
+ DNBLogThreadedIf(LOG_RNB_COMM, "sent: %*s", (int)length,
+ (const char *)buffer);
return rnb_success;
}
diff --git a/tools/debugserver/source/debugserver.cpp b/tools/debugserver/source/debugserver.cpp
index 318e72e971a5e..8291f8d32b51a 100644
--- a/tools/debugserver/source/debugserver.cpp
+++ b/tools/debugserver/source/debugserver.cpp
@@ -232,7 +232,7 @@ RNBRunLoopMode RNBRunLoopLaunchInferior(RNBRemote *remote,
// were given and hope for the best
if (!DNBResolveExecutablePath(inferior_argv[0], resolved_path,
sizeof(resolved_path)))
- ::strncpy(resolved_path, inferior_argv[0], sizeof(resolved_path));
+ ::strlcpy(resolved_path, inferior_argv[0], sizeof(resolved_path));
char launch_err_str[PATH_MAX];
launch_err_str[0] = '\0';
@@ -676,7 +676,7 @@ static void PortWasBoundCallbackUnixSocket(const void *baton, in_port_t port) {
}
saddr_un.sun_family = AF_UNIX;
- ::strncpy(saddr_un.sun_path, unix_socket_name,
+ ::strlcpy(saddr_un.sun_path, unix_socket_name,
sizeof(saddr_un.sun_path) - 1);
saddr_un.sun_path[sizeof(saddr_un.sun_path) - 1] = '\0';
saddr_un.sun_len = SUN_LEN(&saddr_un);
@@ -1366,7 +1366,7 @@ int main(int argc, char *argv[]) {
DNBLogDebug("host = '%s' port = %i", host.c_str(), port);
} else if (argv[0][0] == '/') {
port = INT32_MAX;
- strncpy(str, argv[0], sizeof(str));
+ strlcpy(str, argv[0], sizeof(str));
} else {
show_usage_and_exit(2);
}