Un-conditionalize use of libcompression. debugserver only builds

on Darwin systems and libcompression has been in the OS for over
three years. 

Remove use of / linking to zlib.  We'll always have libcompression
available now.

Create a scratch buffer via compression_encode_scratch_buffer_size()
and use it in calls to compression_encode_buffer() to avoid 
compression_encode_buffer having to malloc & free a scratch buffer
on each call.  

Tested by forcing compression to be enabled on macos native (normally
only enabled on iOS et al devices), running the testsuite.

<rdar://problem/41601084>

llvm-svn: 349553
This commit is contained in:
Jason Molenda 2018-12-18 22:21:48 +00:00
parent f86db5ce9e
commit 681f6c2f55
2 changed files with 54 additions and 151 deletions

View File

@ -710,12 +710,9 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_OS_LOG_CFLAGS = "-DLLDB_USE_OS_LOG=$(LLDB_USE_OS_LOG)";
LLDB_USE_OS_LOG = 0;
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "";
STRIP_INSTALLED_PRODUCT = NO;
@ -749,13 +746,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_OS_LOG_CFLAGS = "-DLLDB_USE_OS_LOG=$(LLDB_USE_OS_LOG)";
LLDB_USE_OS_LOG = 0;
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "";
STRIPFLAGS = "-x";
@ -790,12 +784,9 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_OS_LOG_CFLAGS = "-DLLDB_USE_OS_LOG=$(LLDB_USE_OS_LOG)";
LLDB_USE_OS_LOG = 1;
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = "";
STRIPFLAGS = "-x";
STRIP_STYLE = debugging;
@ -828,20 +819,15 @@
HEADER_SEARCH_PATHS = /System/Library/Frameworks/System.framework/PrivateHeaders;
INSTALL_PATH = /usr/bin;
"INSTALL_PATH[sdk=iphoneos*]" = /Developer/usr/bin/;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ENERGY_CFLAGS)",
"-DDT_VARIANT_$(DT_VARIANT)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*]" = (
@ -851,8 +837,6 @@
"-DWITH_BKS",
"-DOS_OBJECT_USE_OBJC=0",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"-isystem",
"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
@ -871,7 +855,6 @@
MobileCoreServices,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -880,7 +863,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = debugserver;
@ -916,20 +898,15 @@
GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER_DEBUG;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INSTALL_PATH = /usr/bin;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = (
"-Wparentheses",
"-DDT_VARIANT_$(DT_VARIANT)",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
@ -939,8 +916,6 @@
"-DWITH_FBS",
"-DOS_OBJECT_USE_OBJC=0",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"-isystem",
"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
@ -959,7 +934,6 @@
MobileCoreServices,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -967,7 +941,6 @@
__info_plist,
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
@ -1003,20 +976,15 @@
GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER_RELEASE;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INSTALL_PATH = /usr/bin;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*.internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = (
"-Wparentheses",
"-DDT_VARIANT_$(DT_VARIANT)",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
@ -1026,8 +994,6 @@
"-DWITH_BKS",
"-DOS_OBJECT_USE_OBJC=0",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"-isystem",
"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
@ -1046,7 +1012,6 @@
MobileCoreServices,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -1055,7 +1020,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = debugserver;
@ -1107,21 +1071,16 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INSTALL_PATH = /usr/local/bin;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*.internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = (
"-Wparentheses",
"-DDT_VARIANT_$(DT_VARIANT)",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
@ -1130,7 +1089,6 @@
"-DDEBUGSERVER_PROGRAM_SYMBOL=debugserver_nonui",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
);
"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
OTHER_LDFLAGS = "";
@ -1191,8 +1149,6 @@
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
OTHER_CFLAGS = (
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
"-Wparentheses",
@ -1215,7 +1171,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = "debugserver-nonui";
@ -1251,7 +1206,6 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = /System/Library/Frameworks/System.framework/PrivateHeaders;
INSTALL_PATH = /usr/local/bin;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
@ -1259,8 +1213,6 @@
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
OTHER_CFLAGS = (
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"-DDEBUGSERVER_PROGRAM_SYMBOL=debugserver_nonui",
"$(LLDB_OS_LOG_CFLAGS)",
);
@ -1269,7 +1221,6 @@
"-DOS_OBJECT_USE_OBJC=0",
"-DDEBUGSERVER_PROGRAM_SYMBOL=debugserver_nonui",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CPLUSPLUSFLAGS[sdk=iphoneos*][arch=*]" = "$(OTHER_CFLAGS)";
@ -1279,7 +1230,6 @@
Foundation,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -1288,7 +1238,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = "debugserver-nonui";
@ -1391,7 +1340,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_OS_LOG_CFLAGS = "-DLLDB_USE_OS_LOG=$(LLDB_USE_OS_LOG)";
LLDB_USE_OS_LOG = 0;
@ -1426,20 +1374,15 @@
GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER_DEBUG;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INSTALL_PATH = /usr/bin;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*.internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = (
"-Wparentheses",
"-DDT_VARIANT_$(DT_VARIANT)",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
@ -1449,8 +1392,6 @@
"-DWITH_BKS",
"-DOS_OBJECT_USE_OBJC=0",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"-isystem",
"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
@ -1468,7 +1409,6 @@
MobileCoreServices,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -1477,7 +1417,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = debugserver;
@ -1516,7 +1455,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_OS_LOG_CFLAGS = "-DLLDB_USE_OS_LOG=$(LLDB_USE_OS_LOG)";
LLDB_USE_OS_LOG = 0;
@ -1551,19 +1489,14 @@
GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER_DEBUG;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INSTALL_PATH = /usr/bin;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*.internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
@ -1573,8 +1506,6 @@
"-DWITH_BKS",
"-DOS_OBJECT_USE_OBJC=0",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"-isystem",
"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
@ -1592,7 +1523,6 @@
MobileCoreServices,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -1601,7 +1531,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = debugserver;
@ -1716,7 +1645,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_OS_LOG_CFLAGS = "-DLLDB_USE_OS_LOG=$(LLDB_USE_OS_LOG)";
LLDB_USE_OS_LOG = 0;
@ -1751,20 +1679,15 @@
GCC_PREPROCESSOR_DEFINITIONS = LLDB_DEBUGSERVER_DEBUG;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
INSTALL_PATH = /usr/bin;
LLDB_COMPRESSION_CFLAGS = "";
LLDB_COMPRESSION_LDFLAGS = "";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*.internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = (
"-Wparentheses",
"-DDT_VARIANT_$(DT_VARIANT)",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
@ -1774,8 +1697,6 @@
"-DWITH_FBS",
"-DOS_OBJECT_USE_OBJC=0",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"-isystem",
"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
@ -1794,7 +1715,6 @@
MobileCoreServices,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -1803,7 +1723,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = debugserver;
@ -1841,7 +1760,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_OS_LOG_CFLAGS = "-DLLDB_USE_OS_LOG=$(LLDB_USE_OS_LOG)";
LLDB_USE_OS_LOG = 0;
@ -1877,20 +1795,15 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = /System/Library/Frameworks/System.framework/PrivateHeaders;
INSTALL_PATH = /usr/bin;
LLDB_COMPRESSION_CFLAGS = "";
LLDB_COMPRESSION_LDFLAGS = "";
LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_DEBUGSERVER = 1;
LLDB_ENERGY_CFLAGS = "";
"LLDB_ENERGY_CFLAGS[sdk=*.internal]" = "-DLLDB_ENERGY";
LLDB_ENERGY_LDFLAGS = "-lpmenergy -lpmsample";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CFLAGS = (
"-Wparentheses",
"-DDT_VARIANT_$(DT_VARIANT)",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
);
"OTHER_CFLAGS[sdk=iphoneos*][arch=*]" = (
@ -1900,8 +1813,6 @@
"-DWITH_BKS",
"-DOS_OBJECT_USE_OBJC=0",
"$(LLDB_ENERGY_CFLAGS)",
"$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_ZLIB_CFLAGS)",
"$(LLDB_OS_LOG_CFLAGS)",
"-isystem",
"$(SDKROOT)/System/Library/Frameworks/System.framework/PrivateHeaders",
@ -1919,7 +1830,6 @@
MobileCoreServices,
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-sectcreate",
@ -1928,7 +1838,6 @@
"$(PROJECT_DIR)/resources/lldb-debugserver-Info.plist",
"$(LLDB_ENERGY_LDFLAGS)",
"$(LLDB_COMPRESSION_LDFLAGS)",
"$(LLDB_ZLIB_LDFLAGS)",
);
OTHER_MIGFLAGS = "-I$(DERIVED_FILE_DIR)";
PRODUCT_NAME = debugserver;

View File

@ -42,13 +42,7 @@
#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>
#include <iomanip>
@ -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();
@ -3611,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=");
@ -3625,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);
}
@ -4303,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;
@ -4321,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");
}