summaryrefslogtreecommitdiff
path: root/tools/debugserver/source
diff options
context:
space:
mode:
Diffstat (limited to 'tools/debugserver/source')
-rw-r--r--tools/debugserver/source/CMakeLists.txt196
-rw-r--r--tools/debugserver/source/DNBRegisterInfo.cpp1
-rw-r--r--tools/debugserver/source/JSONGenerator.h6
-rw-r--r--tools/debugserver/source/MacOSX/Genealogy.cpp3
-rw-r--r--tools/debugserver/source/MacOSX/MachException.cpp55
-rw-r--r--tools/debugserver/source/MacOSX/MachProcess.mm16
-rw-r--r--tools/debugserver/source/MacOSX/MachTask.h4
-rw-r--r--tools/debugserver/source/MacOSX/MachThread.cpp4
-rw-r--r--tools/debugserver/source/MacOSX/MachVMRegion.cpp5
-rw-r--r--tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp7
-rw-r--r--tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp7
-rw-r--r--tools/debugserver/source/PThreadMutex.cpp4
-rw-r--r--tools/debugserver/source/RNBRemote.cpp141
-rw-r--r--tools/debugserver/source/RNBServices.cpp6
-rw-r--r--tools/debugserver/source/StdStringExtractor.cpp4
-rw-r--r--tools/debugserver/source/StdStringExtractor.h4
-rw-r--r--tools/debugserver/source/TTYState.h2
-rw-r--r--tools/debugserver/source/debugserver-entitlements.plist2
-rw-r--r--tools/debugserver/source/debugserver.cpp4
-rw-r--r--tools/debugserver/source/libdebugserver.cpp2
20 files changed, 251 insertions, 222 deletions
diff --git a/tools/debugserver/source/CMakeLists.txt b/tools/debugserver/source/CMakeLists.txt
index ec136039d349..860a0289d22c 100644
--- a/tools/debugserver/source/CMakeLists.txt
+++ b/tools/debugserver/source/CMakeLists.txt
@@ -5,7 +5,6 @@ include_directories(${LLDB_SOURCE_DIR}/source)
include_directories(MacOSX/DarwinLog)
include_directories(MacOSX)
-#include_directories(${CMAKE_CURRENT_BINARY_DIR}/MacOSX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_SOURCE_DIR}/../resources/lldb-debugserver-Info.plist")
@@ -94,32 +93,121 @@ set(lldbDebugserverCommonSources
add_library(lldbDebugserverCommon ${lldbDebugserverCommonSources})
+# LLDB-specific identity, currently used for code signing debugserver.
+set(LLDB_CODESIGN_IDENTITY "" CACHE STRING
+ "Override code sign identity for debugserver and for use in tests; falls back to LLVM_CODESIGNING_IDENTITY if set or lldb_codesign otherwise (Darwin only)")
-set(LLDB_CODESIGN_IDENTITY "lldb_codesign"
- CACHE STRING "Identity used for code signing. Set to empty string to skip the signing step.")
-
-if(NOT LLDB_CODESIGN_IDENTITY STREQUAL "")
- set(DEBUGSERVER_PATH ${LLVM_RUNTIME_OUTPUT_INTDIR}/debugserver${CMAKE_EXECUTABLE_SUFFIX} CACHE PATH "Path to debugserver.")
- set(SKIP_DEBUGSERVER OFF CACHE BOOL "Skip building the in-tree debug server")
+# Determine which identity to use and store it in the separate cache entry.
+# We will query it later for LLDB_TEST_COMMON_ARGS.
+if(LLDB_CODESIGN_IDENTITY)
+ set(LLDB_CODESIGN_IDENTITY_USED ${LLDB_CODESIGN_IDENTITY} CACHE INTERNAL "" FORCE)
+elseif(LLVM_CODESIGNING_IDENTITY)
+ set(LLDB_CODESIGN_IDENTITY_USED ${LLVM_CODESIGNING_IDENTITY} CACHE INTERNAL "" FORCE)
else()
+ set(LLDB_CODESIGN_IDENTITY_USED lldb_codesign CACHE INTERNAL "" FORCE)
+endif()
+
+# Override locally, so the identity is used for targets created in this scope.
+set(LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY_USED})
+
+option(LLDB_NO_DEBUGSERVER "Disable the debugserver target" OFF)
+option(LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver instead of building it from source (Darwin only)." OFF)
+
+# Incompatible options
+if(LLDB_NO_DEBUGSERVER AND LLDB_USE_SYSTEM_DEBUGSERVER)
+ message(FATAL_ERROR "Inconsistent options: LLDB_NO_DEBUGSERVER and LLDB_USE_SYSTEM_DEBUGSERVER")
+endif()
+
+# Try to locate the system debugserver.
+# Subsequent feasibility checks depend on it.
+if(APPLE AND CMAKE_HOST_APPLE)
execute_process(
COMMAND xcode-select -p
- OUTPUT_VARIABLE XCODE_DEV_DIR)
- string(STRIP ${XCODE_DEV_DIR} XCODE_DEV_DIR)
- if(EXISTS "${XCODE_DEV_DIR}/../SharedFrameworks/LLDB.framework/")
- set(DEBUGSERVER_PATH
- "${XCODE_DEV_DIR}/../SharedFrameworks/LLDB.framework/Resources/debugserver" CACHE PATH "Path to debugserver.")
- elseif(EXISTS "${XCODE_DEV_DIR}/Library/PrivateFrameworks/LLDB.framework/")
- set(DEBUGSERVER_PATH
- "${XCODE_DEV_DIR}/Library/PrivateFrameworks/LLDB.framework/Resources/debugserver" CACHE PATH "Path to debugserver.")
+ OUTPUT_VARIABLE xcode_dev_dir)
+ string(STRIP ${xcode_dev_dir} xcode_dev_dir)
+
+ set(debugserver_rel_path "LLDB.framework/Resources/debugserver")
+ set(debugserver_shared "${xcode_dev_dir}/../SharedFrameworks/${debugserver_rel_path}")
+ set(debugserver_private "${xcode_dev_dir}/Library/PrivateFrameworks/${debugserver_rel_path}")
+
+ if(EXISTS ${debugserver_shared})
+ set(system_debugserver ${debugserver_shared})
+ elseif(EXISTS ${debugserver_private})
+ set(system_debugserver ${debugserver_private})
+ endif()
+endif()
+
+# Handle unavailability
+if(LLDB_USE_SYSTEM_DEBUGSERVER)
+ if(system_debugserver)
+ set(use_system_debugserver ON)
+ elseif(APPLE AND CMAKE_HOST_APPLE)
+ # Binary not found on system. Keep cached variable, to try again on reconfigure.
+ message(SEND_ERROR
+ "LLDB_USE_SYSTEM_DEBUGSERVER option set, but no debugserver found in:\
+ ${debugserver_shared}\
+ ${debugserver_private}")
else()
- message(SEND_ERROR "Cannot find debugserver on system.")
+ # Non-Apple target platform or non-Darwin host. Reset invalid cached variable.
+ message(WARNING "Reverting invalid option LLDB_USE_SYSTEM_DEBUGSERVER (Darwin only)")
+ set(LLDB_USE_SYSTEM_DEBUGSERVER OFF CACHE BOOL "" FORCE)
endif()
- set(SKIP_DEBUGSERVER ON CACHE BOOL "Skip building the in-tree debug server")
+elseif(NOT LLDB_NO_DEBUGSERVER)
+ # Default case: on Darwin we need the right code signing ID.
+ # See lldb/docs/code-signing.txt for details.
+ if(CMAKE_HOST_APPLE AND NOT LLVM_CODESIGNING_IDENTITY STREQUAL "lldb_codesign")
+ set(problem "Cannot code sign debugserver with LLVM_CODESIGNING_IDENTITY '${LLVM_CODESIGNING_IDENTITY}'.")
+ set(advice "Pass -DLLDB_CODESIGN_IDENTITY=lldb_codesign to override the LLVM value for debugserver.")
+ if(system_debugserver)
+ set(effect "Will fall back to system's debugserver.")
+ set(use_system_debugserver ON)
+ else()
+ set(effect "debugserver will not be available.")
+ endif()
+ message(WARNING "${problem} ${effect} ${advice}")
+ else()
+ set(build_and_sign_debugserver ON)
+ endif()
+endif()
+
+# TODO: We don't use the $<TARGET_FILE:debugserver> generator expression here,
+# because the value of DEBUGSERVER_PATH is used to build LLDB_DOTEST_ARGS,
+# which is used for configuring lldb-dotest.in, which does not have a generator
+# step at the moment.
+set(default_debugserver_path "${LLVM_RUNTIME_OUTPUT_INTDIR}/debugserver${CMAKE_EXECUTABLE_SUFFIX}")
+
+# Remember where debugserver binary goes and whether or not we have to test it.
+set(DEBUGSERVER_PATH "" CACHE FILEPATH "Path to debugserver")
+set(SKIP_TEST_DEBUGSERVER OFF CACHE BOOL "Building the in-tree debugserver was skipped")
+
+# Reset values in all cases in order to correctly support reconfigurations.
+if(use_system_debugserver)
+ add_custom_target(debugserver
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ ${system_debugserver} ${LLVM_RUNTIME_OUTPUT_INTDIR}
+ COMMENT "Copying the system debugserver to LLDB's binaries directory.")
+
+ # Don't test debugserver itself.
+ # Tests that require debugserver will use the copy.
+ set(DEBUGSERVER_PATH ${default_debugserver_path} CACHE FILEPATH "" FORCE)
+ set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
+
+ message(STATUS "Copy system debugserver from: ${system_debugserver}")
+elseif(build_and_sign_debugserver)
+ # Build, sign and test debugserver (below)
+ set(DEBUGSERVER_PATH ${default_debugserver_path} CACHE FILEPATH "" FORCE)
+ set(SKIP_TEST_DEBUGSERVER OFF CACHE BOOL "" FORCE)
+
+ message(STATUS "lldb debugserver: ${DEBUGSERVER_PATH}")
+else()
+ # No tests for debugserver, no tests that require it.
+ set(DEBUGSERVER_PATH "" CACHE FILEPATH "" FORCE)
+ set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
+
+ message(STATUS "lldb debugserver will not be available.")
endif()
-message(STATUS "Path to the lldb debugserver: ${DEBUGSERVER_PATH}")
-if (APPLE)
+if(APPLE)
if(IOS)
find_library(BACKBOARD_LIBRARY BackBoardServices
PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
@@ -132,7 +220,7 @@ if (APPLE)
find_library(LOCKDOWN_LIBRARY lockdown)
if(NOT BACKBOARD_LIBRARY)
- set(SKIP_DEBUGSERVER ON CACHE BOOL "Skip building the in-tree debug server" FORCE)
+ set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
endif()
else()
find_library(COCOA_LIBRARY Cocoa)
@@ -143,7 +231,16 @@ if(HAVE_LIBCOMPRESSION)
set(LIBCOMPRESSION compression)
endif()
-if(NOT SKIP_DEBUGSERVER)
+if(LLDB_USE_ENTITLEMENTS)
+ if(IOS)
+ set(entitlements ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-entitlements.plist)
+ else()
+ # Same entitlements file as used for lldb-server
+ set(entitlements ${LLDB_SOURCE_DIR}/resources/debugserver-macosx-entitlements.plist)
+ endif()
+endif()
+
+if(build_and_sign_debugserver)
target_link_libraries(lldbDebugserverCommon
INTERFACE ${COCOA_LIBRARY}
${CORE_FOUNDATION_LIBRARY}
@@ -161,11 +258,14 @@ if(NOT SKIP_DEBUGSERVER)
COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION)
endif()
set(LLVM_OPTIONAL_SOURCES ${lldbDebugserverCommonSources})
- add_lldb_tool(debugserver INCLUDE_IN_SUITE
+ add_lldb_tool(debugserver
debugserver.cpp
LINK_LIBS
lldbDebugserverCommon
+
+ ENTITLEMENTS
+ ${entitlements}
)
if(IOS)
set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
@@ -203,56 +303,8 @@ if(IOS)
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)
-else()
- set(entitlements_xml ${CMAKE_CURRENT_SOURCE_DIR}/../../../resources/debugserver-macosx-entitlements.plist)
-endif()
-
-set(LLDB_USE_ENTITLEMENTS_Default On)
-option(LLDB_USE_ENTITLEMENTS "Use entitlements when codesigning (Defaults Off when using lldb_codesign identity, otherwise On)" ${LLDB_USE_ENTITLEMENTS_Default})
-if (SKIP_DEBUGSERVER)
- if (CMAKE_HOST_APPLE)
- # If we haven't built a signed debugserver, copy the one from the system.
- add_custom_target(debugserver
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEBUGSERVER_PATH} ${CMAKE_BINARY_DIR}/bin
- VERBATIM
- COMMENT "Copying the system debugserver to LLDB's binaries directory.")
- endif()
-else()
- if(LLDB_USE_ENTITLEMENTS)
- set(entitlements_flags --entitlements ${entitlements_xml})
- endif()
- execute_process(
- COMMAND xcrun -f codesign_allocate
- OUTPUT_STRIP_TRAILING_WHITESPACE
- OUTPUT_VARIABLE CODESIGN_ALLOCATE
- )
- add_custom_command(TARGET debugserver
- 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
+ ENTITLEMENTS
+ ${entitlements}
)
- endif()
endif()
-
-
-
-
diff --git a/tools/debugserver/source/DNBRegisterInfo.cpp b/tools/debugserver/source/DNBRegisterInfo.cpp
index b85b39378183..d0f6063fbce0 100644
--- a/tools/debugserver/source/DNBRegisterInfo.cpp
+++ b/tools/debugserver/source/DNBRegisterInfo.cpp
@@ -156,6 +156,7 @@ void DNBRegisterValueClass::Dump(const char *pre, const char *post) const {
DNBLogError(
"unsupported vector format %d, defaulting to hex bytes.",
info.format);
+ [[clang::fallthrough]];
case VectorOfUInt8:
snprintf(str, sizeof(str), "%s", "uint8 { ");
pos = str + strlen(str);
diff --git a/tools/debugserver/source/JSONGenerator.h b/tools/debugserver/source/JSONGenerator.h
index 7af6ae60c5f7..0ac5e0bb768c 100644
--- a/tools/debugserver/source/JSONGenerator.h
+++ b/tools/debugserver/source/JSONGenerator.h
@@ -10,8 +10,6 @@
#ifndef __JSONGenerator_h_
#define __JSONGenerator_h_
-// C Includes
-// C++ Includes
#include <iomanip>
#include <sstream>
@@ -184,7 +182,7 @@ public:
void SetValue(bool value) { m_value = value; }
void Dump(std::ostream &s) const override {
- if (m_value == true)
+ if (m_value)
s << "true";
else
s << "false";
@@ -264,7 +262,7 @@ public:
s << "{";
for (collection::const_iterator iter = m_dict.begin();
iter != m_dict.end(); ++iter) {
- if (have_printed_one_elem == false) {
+ if (!have_printed_one_elem) {
have_printed_one_elem = true;
} else {
s << ",";
diff --git a/tools/debugserver/source/MacOSX/Genealogy.cpp b/tools/debugserver/source/MacOSX/Genealogy.cpp
index 22ff52abaa47..1473a53fcbea 100644
--- a/tools/debugserver/source/MacOSX/Genealogy.cpp
+++ b/tools/debugserver/source/MacOSX/Genealogy.cpp
@@ -74,8 +74,7 @@ Genealogy::GetGenealogyInfoForThread(pid_t pid, nub_thread_t tid,
// (else we'll need to hit the timeout for every thread we're asked about.)
// We'll try again at the next public stop.
- if (m_thread_activities.size() == 0 &&
- m_diagnosticd_call_timed_out == false) {
+ if (m_thread_activities.size() == 0 && !m_diagnosticd_call_timed_out) {
GetActivities(pid, thread_list, task);
}
std::map<nub_thread_t, ThreadActivitySP>::const_iterator search;
diff --git a/tools/debugserver/source/MacOSX/MachException.cpp b/tools/debugserver/source/MacOSX/MachException.cpp
index da2b2fe92980..01e5892d487d 100644
--- a/tools/debugserver/source/MacOSX/MachException.cpp
+++ b/tools/debugserver/source/MacOSX/MachException.cpp
@@ -386,24 +386,29 @@ void MachException::Data::Dump() const {
}
}
-#define PREV_EXC_MASK_ALL \
- (EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC | \
- EXC_MASK_EMULATION | EXC_MASK_SOFTWARE | EXC_MASK_BREAKPOINT | \
- EXC_MASK_SYSCALL | EXC_MASK_MACH_SYSCALL | EXC_MASK_RPC_ALERT | \
- EXC_MASK_MACHINE)
-
-// Don't listen for EXC_RESOURCE, it should really get handled by the system
-// handler.
-
-#ifndef EXC_RESOURCE
-#define EXC_RESOURCE 11
-#endif
-
-#ifndef EXC_MASK_RESOURCE
-#define EXC_MASK_RESOURCE (1 << EXC_RESOURCE)
-#endif
-
-#define LLDB_EXC_MASK (EXC_MASK_ALL & ~EXC_MASK_RESOURCE)
+// The EXC_MASK_ALL value hard-coded here so that lldb can be built
+// on a new OS with an older deployment target . The new OS may have
+// an addition to its EXC_MASK_ALL that the old OS will not recognize -
+// <mach/exception_types.h> doesn't vary the value based on the deployment
+// target. So we need a known set of masks that can be assumed to be
+// valid when running on an older OS. We'll fall back to trying
+// PREV_EXC_MASK_ALL if the EXC_MASK_ALL value lldb was compiled with is
+// not recognized.
+
+#define PREV_EXC_MASK_ALL (EXC_MASK_BAD_ACCESS | \
+ EXC_MASK_BAD_INSTRUCTION | \
+ EXC_MASK_ARITHMETIC | \
+ EXC_MASK_EMULATION | \
+ EXC_MASK_SOFTWARE | \
+ EXC_MASK_BREAKPOINT | \
+ EXC_MASK_SYSCALL | \
+ EXC_MASK_MACH_SYSCALL | \
+ EXC_MASK_RPC_ALERT | \
+ EXC_MASK_RESOURCE | \
+ EXC_MASK_GUARD | \
+ EXC_MASK_MACHINE)
+
+#define LLDB_EXC_MASK EXC_MASK_ALL
kern_return_t MachException::PortInfo::Save(task_t task) {
DNBLogThreadedIf(LOG_EXCEPTIONS | LOG_VERBOSE,
@@ -485,9 +490,21 @@ const char *MachException::Name(exception_type_t exc_type) {
return "EXC_MACH_SYSCALL";
case EXC_RPC_ALERT:
return "EXC_RPC_ALERT";
-#ifdef EXC_CRASH
case EXC_CRASH:
return "EXC_CRASH";
+ case EXC_RESOURCE:
+ return "EXC_RESOURCE";
+#ifdef EXC_GUARD
+ case EXC_GUARD:
+ return "EXC_GUARD";
+#endif
+#ifdef EXC_CORPSE_NOTIFY
+ case EXC_CORPSE_NOTIFY:
+ return "EXC_CORPSE_NOTIFY";
+#endif
+#ifdef EXC_CORPSE_VARIANT_BIT
+ case EXC_CORPSE_VARIANT_BIT:
+ return "EXC_CORPSE_VARIANT_BIT";
#endif
default:
break;
diff --git a/tools/debugserver/source/MacOSX/MachProcess.mm b/tools/debugserver/source/MacOSX/MachProcess.mm
index 4ddc5f8b10dc..a3b905d05150 100644
--- a/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -783,8 +783,8 @@ JSONGenerator::ObjectSP MachProcess::FormatDynamicLibrariesIntoJSON(
uuid_unparse_upper(image_infos[i].macho_info.uuid, uuidstr);
image_info_dict_sp->AddStringItem("uuid", uuidstr);
- if (image_infos[i].macho_info.min_version_os_name.empty() == false &&
- image_infos[i].macho_info.min_version_os_version.empty() == false) {
+ if (!image_infos[i].macho_info.min_version_os_name.empty() &&
+ !image_infos[i].macho_info.min_version_os_version.empty()) {
image_info_dict_sp->AddStringItem(
"min_version_os_name", image_infos[i].macho_info.min_version_os_name);
image_info_dict_sp->AddStringItem(
@@ -803,6 +803,8 @@ JSONGenerator::ObjectSP MachProcess::FormatDynamicLibrariesIntoJSON(
(uint32_t)image_infos[i].macho_info.mach_header.cpusubtype);
mach_header_dict_sp->AddIntegerItem(
"filetype", image_infos[i].macho_info.mach_header.filetype);
+ mach_header_dict_sp->AddIntegerItem ("flags",
+ image_infos[i].macho_info.mach_header.flags);
// DynamicLoaderMacOSX doesn't currently need these fields, so
// don't send them.
@@ -810,8 +812,6 @@ JSONGenerator::ObjectSP MachProcess::FormatDynamicLibrariesIntoJSON(
// image_infos[i].macho_info.mach_header.ncmds);
// mach_header_dict_sp->AddIntegerItem ("sizeofcmds",
// image_infos[i].macho_info.mach_header.sizeofcmds);
- // mach_header_dict_sp->AddIntegerItem ("flags",
- // image_infos[i].macho_info.mach_header.flags);
image_info_dict_sp->AddItem("mach_header", mach_header_dict_sp);
JSONGenerator::ArraySP segments_sp(new JSONGenerator::Array());
@@ -1602,7 +1602,7 @@ nub_size_t MachProcess::WriteMemory(nub_addr_t addr, nub_size_t size,
void MachProcess::ReplyToAllExceptions() {
PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex);
- if (m_exception_messages.empty() == false) {
+ if (!m_exception_messages.empty()) {
MachException::Message::iterator pos;
MachException::Message::iterator begin = m_exception_messages.begin();
MachException::Message::iterator end = m_exception_messages.end();
@@ -1774,7 +1774,7 @@ bool MachProcess::DisableBreakpoint(nub_addr_t addr, bool remove) {
if (bp->IsHardware()) {
bool hw_disable_result = m_thread_list.DisableHardwareBreakpoint(bp);
- if (hw_disable_result == true) {
+ if (hw_disable_result) {
bp->SetEnabled(false);
// Let the thread list know that a breakpoint has been modified
if (remove) {
@@ -1909,7 +1909,7 @@ bool MachProcess::DisableWatchpoint(nub_addr_t addr, bool remove) {
if (wp->IsHardware()) {
bool hw_disable_result = m_thread_list.DisableHardwareWatchpoint(wp);
- if (hw_disable_result == true) {
+ if (hw_disable_result) {
wp->SetEnabled(false);
if (remove)
m_watchpoints.Remove(addr);
@@ -2179,7 +2179,7 @@ task_t MachProcess::ExceptionMessageBundleComplete() {
m_thread_list.Dump();
bool step_more = false;
- if (m_thread_list.ShouldStop(step_more) && auto_resume == false) {
+ if (m_thread_list.ShouldStop(step_more) && !auto_resume) {
// Wait for the eEventProcessRunningStateChanged event to be reset
// before changing state to stopped to avoid race condition with
// very fast start/stops
diff --git a/tools/debugserver/source/MacOSX/MachTask.h b/tools/debugserver/source/MacOSX/MachTask.h
index 1e0e2af9a92b..1fe74ddec56c 100644
--- a/tools/debugserver/source/MacOSX/MachTask.h
+++ b/tools/debugserver/source/MacOSX/MachTask.h
@@ -18,14 +18,10 @@
#ifndef __MachTask_h__
#define __MachTask_h__
-// C Includes
#include <mach/mach.h>
#include <sys/socket.h>
-// C++ Includes
#include <map>
#include <string>
-// Other libraries and framework includes
-// Project includes
#include "DNBDefs.h"
#include "MachException.h"
#include "MachVMMemory.h"
diff --git a/tools/debugserver/source/MacOSX/MachThread.cpp b/tools/debugserver/source/MacOSX/MachThread.cpp
index fc97825786a0..062e1c3d9edf 100644
--- a/tools/debugserver/source/MacOSX/MachThread.cpp
+++ b/tools/debugserver/source/MacOSX/MachThread.cpp
@@ -83,7 +83,7 @@ bool MachThread::SetSuspendCountBeforeResume(bool others_stopped) {
DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )",
__FUNCTION__);
DNBError err;
- if (MachPortNumberIsValid(m_mach_port_number) == false)
+ if (!MachPortNumberIsValid(m_mach_port_number))
return false;
integer_t times_to_resume;
@@ -121,7 +121,7 @@ bool MachThread::RestoreSuspendCountAfterStop() {
DNBLogThreadedIf(LOG_THREAD | LOG_VERBOSE, "MachThread::%s ( )",
__FUNCTION__);
DNBError err;
- if (MachPortNumberIsValid(m_mach_port_number) == false)
+ if (!MachPortNumberIsValid(m_mach_port_number))
return false;
if (m_suspend_count > 0) {
diff --git a/tools/debugserver/source/MacOSX/MachVMRegion.cpp b/tools/debugserver/source/MacOSX/MachVMRegion.cpp
index c011c133ac38..172fc7867b57 100644
--- a/tools/debugserver/source/MacOSX/MachVMRegion.cpp
+++ b/tools/debugserver/source/MacOSX/MachVMRegion.cpp
@@ -166,10 +166,7 @@ bool MachVMRegion::GetRegionForAddress(nub_addr_t addr) {
// doesn't mean that "addr" is in the range. The data in this object will
// be valid though, so you could see where the next region begins. So we
// return false, yet leave "m_err" with a successfull return code.
- if ((addr < m_start) || (addr >= (m_start + m_size)))
- return false;
-
- return true;
+ return !((addr < m_start) || (addr >= (m_start + m_size)));
}
uint32_t MachVMRegion::GetDNBPermissions() const {
diff --git a/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp b/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
index adcd65002191..ba37a328ecf3 100644
--- a/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
+++ b/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
@@ -889,10 +889,7 @@ bool DNBArchImplI386::RollbackTransForHWP() {
LOG_WATCHPOINTS,
"DNBArchImplI386::RollbackTransForHWP() SetDBGState() => 0x%8.8x.", kret);
- if (kret == KERN_SUCCESS)
- return true;
- else
- return false;
+ return kret == KERN_SUCCESS;
}
bool DNBArchImplI386::FinishTransForHWP() {
m_2pc_trans_state = Trans_Done;
@@ -918,7 +915,7 @@ uint32_t DNBArchImplI386::EnableHardwareWatchpoint(nub_addr_t addr,
return INVALID_NUB_HW_INDEX;
// We must watch for either read or write
- if (read == false && write == false)
+ if (!read && !write)
return INVALID_NUB_HW_INDEX;
// Read the debug state
diff --git a/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp b/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
index f0a3d2b001b2..2f8ed32fa5d0 100644
--- a/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
+++ b/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
@@ -844,10 +844,7 @@ bool DNBArchImplX86_64::RollbackTransForHWP() {
"DNBArchImplX86_64::RollbackTransForHWP() SetDBGState() => 0x%8.8x.",
kret);
- if (kret == KERN_SUCCESS)
- return true;
- else
- return false;
+ return kret == KERN_SUCCESS;
}
bool DNBArchImplX86_64::FinishTransForHWP() {
m_2pc_trans_state = Trans_Done;
@@ -873,7 +870,7 @@ uint32_t DNBArchImplX86_64::EnableHardwareWatchpoint(nub_addr_t addr,
return INVALID_NUB_HW_INDEX;
// We must watch for either read or write
- if (read == false && write == false)
+ if (!read && !write)
return INVALID_NUB_HW_INDEX;
// Read the debug state
diff --git a/tools/debugserver/source/PThreadMutex.cpp b/tools/debugserver/source/PThreadMutex.cpp
index 32db862f6b42..0e9132e380bf 100644
--- a/tools/debugserver/source/PThreadMutex.cpp
+++ b/tools/debugserver/source/PThreadMutex.cpp
@@ -13,10 +13,6 @@
#include "PThreadMutex.h"
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
#include "DNBTimer.h"
#if defined(DEBUG_PTHREAD_MUTEX_DEADLOCKS)
diff --git a/tools/debugserver/source/RNBRemote.cpp b/tools/debugserver/source/RNBRemote.cpp
index 8ba06be1d6ad..f611ec0d2199 100644
--- a/tools/debugserver/source/RNBRemote.cpp
+++ b/tools/debugserver/source/RNBRemote.cpp
@@ -42,15 +42,9 @@
#include "RNBSocket.h"
#include "StdStringExtractor.h"
-#if defined(HAVE_LIBCOMPRESSION)
#include <compression.h>
-#endif
-
-#if defined(HAVE_LIBZ)
-#include <zlib.h>
-#endif
-#include <TargetConditionals.h> // for endianness predefines
+#include <TargetConditionals.h>
#include <iomanip>
#include <sstream>
#include <unordered_set>
@@ -709,53 +703,73 @@ std::string RNBRemote::CompressString(const std::string &orig) {
std::vector<uint8_t> encoded_data(encoded_data_buf_size);
size_t compressed_size = 0;
-#if defined(HAVE_LIBCOMPRESSION)
+ // Allocate a scratch buffer for libcompression the first
+ // time we see a different compression type; reuse it in
+ // all compression_encode_buffer calls so it doesn't need
+ // to allocate / free its own scratch buffer each time.
+ // This buffer will only be freed when compression type
+ // changes; otherwise it will persist until debugserver
+ // exit.
+
+ static compression_types g_libcompress_scratchbuf_type = compression_types::none;
+ static void *g_libcompress_scratchbuf = nullptr;
+
+ if (g_libcompress_scratchbuf_type != compression_type) {
+ if (g_libcompress_scratchbuf) {
+ free (g_libcompress_scratchbuf);
+ g_libcompress_scratchbuf = nullptr;
+ }
+ size_t scratchbuf_size = 0;
+ switch (compression_type) {
+ case compression_types::lz4:
+ scratchbuf_size = compression_encode_scratch_buffer_size (COMPRESSION_LZ4_RAW);
+ break;
+ case compression_types::zlib_deflate:
+ scratchbuf_size = compression_encode_scratch_buffer_size (COMPRESSION_ZLIB);
+ break;
+ case compression_types::lzma:
+ scratchbuf_size = compression_encode_scratch_buffer_size (COMPRESSION_LZMA);
+ break;
+ case compression_types::lzfse:
+ scratchbuf_size = compression_encode_scratch_buffer_size (COMPRESSION_LZFSE);
+ break;
+ default:
+ break;
+ }
+ if (scratchbuf_size > 0) {
+ g_libcompress_scratchbuf = (void*) malloc (scratchbuf_size);
+ g_libcompress_scratchbuf_type = compression_type;
+ }
+ }
+
if (compression_type == compression_types::lz4) {
compressed_size = compression_encode_buffer(
encoded_data.data(), encoded_data_buf_size,
- (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ (const uint8_t *)orig.c_str(), orig.size(),
+ g_libcompress_scratchbuf,
COMPRESSION_LZ4_RAW);
}
if (compression_type == compression_types::zlib_deflate) {
compressed_size = compression_encode_buffer(
encoded_data.data(), encoded_data_buf_size,
- (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ (const uint8_t *)orig.c_str(), orig.size(),
+ g_libcompress_scratchbuf,
COMPRESSION_ZLIB);
}
if (compression_type == compression_types::lzma) {
compressed_size = compression_encode_buffer(
encoded_data.data(), encoded_data_buf_size,
- (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ (const uint8_t *)orig.c_str(), orig.size(),
+ g_libcompress_scratchbuf,
COMPRESSION_LZMA);
}
if (compression_type == compression_types::lzfse) {
compressed_size = compression_encode_buffer(
encoded_data.data(), encoded_data_buf_size,
- (const uint8_t *)orig.c_str(), orig.size(), nullptr,
+ (const uint8_t *)orig.c_str(), orig.size(),
+ g_libcompress_scratchbuf,
COMPRESSION_LZFSE);
}
-#endif
-
-#if defined(HAVE_LIBZ)
- if (compressed_size == 0 &&
- compression_type == compression_types::zlib_deflate) {
- z_stream stream;
- memset(&stream, 0, sizeof(z_stream));
- stream.next_in = (Bytef *)orig.c_str();
- stream.avail_in = (uInt)orig.size();
- stream.next_out = (Bytef *)encoded_data.data();
- stream.avail_out = (uInt)encoded_data_buf_size;
- stream.zalloc = Z_NULL;
- stream.zfree = Z_NULL;
- stream.opaque = Z_NULL;
- deflateInit2(&stream, 5, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
- int compress_status = deflate(&stream, Z_FINISH);
- deflateEnd(&stream);
- if (compress_status == Z_STREAM_END && stream.total_out > 0) {
- compressed_size = stream.total_out;
- }
- }
-#endif
if (compressed_size > 0) {
compressed.clear();
@@ -1811,18 +1825,18 @@ rnb_err_t RNBRemote::HandlePacket_qRcmd(const char *p) {
}
if (*c == '\0') {
std::string command = get_identifier(line);
- if (command.compare("set") == 0) {
+ if (command == "set") {
std::string variable = get_identifier(line);
std::string op = get_operator(line);
std::string value = get_value(line);
- if (variable.compare("logfile") == 0) {
+ if (variable == "logfile") {
FILE *log_file = fopen(value.c_str(), "w");
if (log_file) {
DNBLogSetLogCallback(FileLogCallback, log_file);
return SendPacket("OK");
}
return SendPacket("E71");
- } else if (variable.compare("logmask") == 0) {
+ } else if (variable == "logmask") {
char *end;
errno = 0;
uint32_t logmask =
@@ -3413,10 +3427,7 @@ static bool RNBRemoteShouldCancelCallback(void *not_used) {
RNBRemoteSP remoteSP(g_remoteSP);
if (remoteSP.get() != NULL) {
RNBRemote *remote = remoteSP.get();
- if (remote->Comm().IsConnected())
- return false;
- else
- return true;
+ return !remote->Comm().IsConnected();
}
return true;
}
@@ -3614,13 +3625,13 @@ rnb_err_t RNBRemote::HandlePacket_qSupported(const char *p) {
bool enable_compression = false;
(void)enable_compression;
-#if (defined (TARGET_OS_WATCH) && TARGET_OS_WATCH == 1) || (defined (TARGET_OS_IOS) && TARGET_OS_IOS == 1) || (defined (TARGET_OS_TV) && TARGET_OS_TV == 1)
+#if (defined (TARGET_OS_WATCH) && TARGET_OS_WATCH == 1) \
+ || (defined (TARGET_OS_IOS) && TARGET_OS_IOS == 1) \
+ || (defined (TARGET_OS_TV) && TARGET_OS_TV == 1) \
+ || (defined (TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE == 1)
enable_compression = true;
#endif
-#if defined(HAVE_LIBCOMPRESSION)
- // libcompression is weak linked so test if compression_decode_buffer() is
- // available
if (enable_compression) {
strcat(buf, ";SupportedCompressions=lzfse,zlib-deflate,lz4,lzma;"
"DefaultCompressionMinSize=");
@@ -3628,17 +3639,7 @@ rnb_err_t RNBRemote::HandlePacket_qSupported(const char *p) {
snprintf(numbuf, sizeof(numbuf), "%zu", m_compression_minsize);
numbuf[sizeof(numbuf) - 1] = '\0';
strcat(buf, numbuf);
- }
-#elif defined(HAVE_LIBZ)
- if (enable_compression) {
- strcat(buf,
- ";SupportedCompressions=zlib-deflate;DefaultCompressionMinSize=");
- char numbuf[16];
- snprintf(numbuf, sizeof(numbuf), "%zu", m_compression_minsize);
- numbuf[sizeof(numbuf) - 1] = '\0';
- strcat(buf, numbuf);
- }
-#endif
+ }
return SendPacket(buf);
}
@@ -3690,7 +3691,7 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) {
return HandlePacket_ILLFORMED(
__FILE__, __LINE__, p, "Could not parse signal in vCont packet");
// Fall through to next case...
-
+ [[clang::fallthrough]];
case 'c':
// Continue
thread_action.state = eStateRunning;
@@ -3703,7 +3704,7 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) {
return HandlePacket_ILLFORMED(
__FILE__, __LINE__, p, "Could not parse signal in vCont packet");
// Fall through to next case...
-
+ [[clang::fallthrough]];
case 's':
// Step
thread_action.state = eStateStepping;
@@ -3817,7 +3818,7 @@ rnb_err_t RNBRemote::HandlePacket_v(const char *p) {
attach_failed_due_to_sip = true;
}
- if (attach_failed_due_to_sip == false) {
+ if (!attach_failed_due_to_sip) {
int csops_flags = 0;
int retval = ::csops(pid_attaching_to, CS_OPS_STATUS, &csops_flags,
sizeof(csops_flags));
@@ -4230,7 +4231,7 @@ rnb_err_t RNBRemote::HandlePacket_GetProfileData(const char *p) {
std::string name;
std::string value;
while (packet.GetNameColonValue(name, value)) {
- if (name.compare("scan_type") == 0) {
+ if (name == "scan_type") {
std::istringstream iss(value);
uint32_t int_value = 0;
if (iss >> std::hex >> int_value) {
@@ -4260,11 +4261,11 @@ rnb_err_t RNBRemote::HandlePacket_SetEnableAsyncProfiling(const char *p) {
std::string name;
std::string value;
while (packet.GetNameColonValue(name, value)) {
- if (name.compare("enable") == 0) {
+ if (name == "enable") {
enable = strtoul(value.c_str(), NULL, 10) > 0;
- } else if (name.compare("interval_usec") == 0) {
+ } else if (name == "interval_usec") {
interval_usec = strtoul(value.c_str(), NULL, 10);
- } else if (name.compare("scan_type") == 0) {
+ } else if (name == "scan_type") {
std::istringstream iss(value);
uint32_t int_value = 0;
if (iss >> std::hex >> int_value) {
@@ -4306,7 +4307,6 @@ rnb_err_t RNBRemote::HandlePacket_QEnableCompression(const char *p) {
}
}
-#if defined(HAVE_LIBCOMPRESSION)
if (strstr(p, "type:zlib-deflate;") != nullptr) {
EnableCompressionNextSendPacket(compression_types::zlib_deflate);
m_compression_minsize = new_compression_minsize;
@@ -4324,15 +4324,6 @@ rnb_err_t RNBRemote::HandlePacket_QEnableCompression(const char *p) {
m_compression_minsize = new_compression_minsize;
return SendPacket("OK");
}
-#endif
-
-#if defined(HAVE_LIBZ)
- if (strstr(p, "type:zlib-deflate;") != nullptr) {
- EnableCompressionNextSendPacket(compression_types::zlib_deflate);
- m_compression_minsize = new_compression_minsize;
- return SendPacket("OK");
- }
-#endif
return SendPacket("E88");
}
@@ -5300,7 +5291,7 @@ RNBRemote::GetJSONThreadsInfo(bool threads_with_valid_stop_info_only) {
thread_dict_sp->AddStringItem("reason", reason_value);
- if (threads_with_valid_stop_info_only == false) {
+ if (!threads_with_valid_stop_info_only) {
const char *thread_name = DNBThreadGetName(pid, tid);
if (thread_name && thread_name[0])
thread_dict_sp->AddStringItem("name", thread_name);
@@ -5488,7 +5479,7 @@ rnb_err_t RNBRemote::HandlePacket_jThreadExtendedInfo(const char *p) {
bool need_to_print_comma = false;
- if (thread_activity_sp && timed_out == false) {
+ if (thread_activity_sp && !timed_out) {
const Genealogy::Activity *activity =
&thread_activity_sp->current_activity;
bool need_vouchers_comma_sep = false;
diff --git a/tools/debugserver/source/RNBServices.cpp b/tools/debugserver/source/RNBServices.cpp
index b2f4910f8855..89c4c27da1dd 100644
--- a/tools/debugserver/source/RNBServices.cpp
+++ b/tools/debugserver/source/RNBServices.cpp
@@ -57,9 +57,9 @@ int GetProcesses(CFMutableArrayRef plistMutableArray, bool all_users) {
const pid_t pid = proc_info.kp_proc.p_pid;
// Skip zombie processes and processes with unset status
- if (kinfo_user_matches == false || // User is acceptable
- pid == our_pid || // Skip this process
- pid == 0 || // Skip kernel (kernel pid is zero)
+ if (!kinfo_user_matches || // User is acceptable
+ pid == our_pid || // Skip this process
+ pid == 0 || // Skip kernel (kernel pid is zero)
proc_info.kp_proc.p_stat ==
SZOMB || // Zombies are bad, they like brains...
proc_info.kp_proc.p_flag & P_TRACED || // Being debugged?
diff --git a/tools/debugserver/source/StdStringExtractor.cpp b/tools/debugserver/source/StdStringExtractor.cpp
index d23f9319fa7b..3b400b2a89d2 100644
--- a/tools/debugserver/source/StdStringExtractor.cpp
+++ b/tools/debugserver/source/StdStringExtractor.cpp
@@ -9,12 +9,8 @@
#include "StdStringExtractor.h"
-// C Includes
#include <stdlib.h>
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
static inline int xdigit_to_sint(char ch) {
if (ch >= 'a' && ch <= 'f')
diff --git a/tools/debugserver/source/StdStringExtractor.h b/tools/debugserver/source/StdStringExtractor.h
index c46978b61f4f..40b57cb08fb5 100644
--- a/tools/debugserver/source/StdStringExtractor.h
+++ b/tools/debugserver/source/StdStringExtractor.h
@@ -10,13 +10,9 @@
#ifndef utility_StdStringExtractor_h_
#define utility_StdStringExtractor_h_
-// C Includes
-// C++ Includes
#include <stdint.h>
#include <string>
-// Other libraries and framework includes
-// Project includes
// Based on StringExtractor, with the added limitation that this file should not
// take a dependency on LLVM, as it is used from debugserver.
diff --git a/tools/debugserver/source/TTYState.h b/tools/debugserver/source/TTYState.h
index ab34015e1a42..88b6d3c2462e 100644
--- a/tools/debugserver/source/TTYState.h
+++ b/tools/debugserver/source/TTYState.h
@@ -56,4 +56,4 @@ protected:
TTYState m_ttystates[2];
};
-#endif \ No newline at end of file
+#endif
diff --git a/tools/debugserver/source/debugserver-entitlements.plist b/tools/debugserver/source/debugserver-entitlements.plist
index 7f1ae4615019..6d9f44536f94 100644
--- a/tools/debugserver/source/debugserver-entitlements.plist
+++ b/tools/debugserver/source/debugserver-entitlements.plist
@@ -12,8 +12,6 @@
<true/>
<key>com.apple.frontboard.debugapplications</key>
<true/>
- <key>run-unsigned-code</key>
- <true/>
<key>seatbelt-profiles</key>
<array>
<string>debugserver</string>
diff --git a/tools/debugserver/source/debugserver.cpp b/tools/debugserver/source/debugserver.cpp
index 7ae321ba431b..8afe17bce37d 100644
--- a/tools/debugserver/source/debugserver.cpp
+++ b/tools/debugserver/source/debugserver.cpp
@@ -9,19 +9,17 @@
#include <arpa/inet.h>
#include <asl.h>
-#include <crt_externs.h> // for _NSGetEnviron()
+#include <crt_externs.h>
#include <errno.h>
#include <getopt.h>
#include <netdb.h>
#include <netinet/in.h>
-#include <netinet/in.h>
#include <netinet/tcp.h>
#include <string>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/types.h>
-#include <sys/types.h>
#include <sys/un.h>
#include <vector>
diff --git a/tools/debugserver/source/libdebugserver.cpp b/tools/debugserver/source/libdebugserver.cpp
index 0d27cfd89a3d..34df67521a7c 100644
--- a/tools/debugserver/source/libdebugserver.cpp
+++ b/tools/debugserver/source/libdebugserver.cpp
@@ -176,7 +176,7 @@ RNBRunLoopMode HandleProcessStateChange(RNBRemoteSP &remote, bool initialize) {
case eStateSuspended:
case eStateCrashed:
case eStateStopped:
- if (initialize == false) {
+ if (!initialize) {
// Compare the last stop count to our current notion of a stop count
// to make sure we don't notify more than once for a given stop.
nub_size_t prev_pid_stop_count = ctx.GetProcessStopCount();