[Lldb-commits] [lldb] r349563 - Force libcompression calls to be enabled when building on Darwin
Jason Molenda via lldb-commits
lldb-commits at lists.llvm.org
Tue Dec 18 15:02:51 PST 2018
Author: jmolenda
Date: Tue Dec 18 15:02:50 2018
New Revision: 349563
URL: http://llvm.org/viewvc/llvm-project?rev=349563&view=rev
Log:
Force libcompression calls to be enabled when building on Darwin
systems. It has been available in the OS over over three years
now. If lldb doesn't link against -lcompression, it should be an
error.
Allocate a scratch buffer for libcompression to use when decoding
packets, instead of it having to allocate & free one on every call.
Fix a typeo with the size of the buffer that compression_decode_buffer()
is expanding into.
<rdar://problem/41601084>
Modified:
lldb/trunk/lldb.xcodeproj/project.pbxproj
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=349563&r1=349562&r2=349563&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Dec 18 15:02:50 2018
@@ -8712,8 +8712,7 @@
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_COVERAGE_CFLAGS = "$(LLDB_COVERAGE_CFLAGS_$(LLDB_ENABLE_COVERAGE))";
LLDB_COVERAGE_CFLAGS_1 = "-fprofile-instr-generate -fcoverage-mapping";
LLDB_COVERAGE_LDFLAGS = "$(LLDB_COVERAGE_LDFLAGS_$(LLDB_ENABLE_COVERAGE))";
@@ -8734,12 +8733,11 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
);
OTHER_LDFLAGS = (
- "$(LLDB_COMPRESSION_LDFLAGS)",
+ "-lcompression",
"$(LLDB_ZLIB_LDFLAGS)",
"$(LLDB_COVERAGE_LDFLAGS)",
);
@@ -8802,8 +8800,7 @@
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_COVERAGE_CFLAGS = "$(LLDB_COVERAGE_CFLAGS_$(LLDB_ENABLE_COVERAGE))";
LLDB_COVERAGE_CFLAGS_1 = "-fprofile-instr-generate -fcoverage-mapping";
LLDB_COVERAGE_LDFLAGS = "$(LLDB_COVERAGE_LDFLAGS_$(LLDB_ENABLE_COVERAGE))";
@@ -8824,12 +8821,11 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
);
OTHER_LDFLAGS = (
- "$(LLDB_COMPRESSION_LDFLAGS)",
+ "-lcompression",
"$(LLDB_ZLIB_LDFLAGS)",
"$(LLDB_COVERAGE_LDFLAGS)",
);
@@ -8965,7 +8961,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9007,7 +9002,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9049,7 +9043,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9091,7 +9084,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9133,7 +9125,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9177,7 +9168,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9221,7 +9211,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9265,7 +9254,6 @@
"-fno-rtti",
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_GTESTS_CFLAGS)",
"-DGTEST_HAS_RTTI=0",
);
@@ -9357,10 +9345,7 @@
"$(LLVM_BUILD_DIR)/$(LLVM_BUILD_DIR_ARCH)",
"$(inherited)",
);
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CPLUSPLUSFLAGS = (
@@ -9430,10 +9415,7 @@
"$(LLVM_BUILD_DIR)/$(LLVM_BUILD_DIR_ARCH)",
"$(inherited)",
);
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CPLUSPLUSFLAGS = (
@@ -9765,10 +9747,7 @@
"LLDB_VERSION_STRING=lldb-${CURRENT_PROJECT_VERSION}",
);
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
MACH_O_TYPE = staticlib;
@@ -9822,10 +9801,7 @@
"LLDB_VERSION_STRING=lldb-${CURRENT_PROJECT_VERSION}",
);
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
MACH_O_TYPE = staticlib;
@@ -9879,10 +9855,7 @@
"LLDB_VERSION_STRING=lldb-${CURRENT_PROJECT_VERSION}",
);
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
MACH_O_TYPE = staticlib;
@@ -9958,8 +9931,7 @@
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_COVERAGE_CFLAGS = "$(LLDB_COVERAGE_CFLAGS_$(LLDB_ENABLE_COVERAGE))";
LLDB_COVERAGE_CFLAGS_1 = "-fprofile-instr-generate -fcoverage-mapping";
LLDB_COVERAGE_LDFLAGS = "$(LLDB_COVERAGE_LDFLAGS_$(LLDB_ENABLE_COVERAGE))";
@@ -9981,13 +9953,12 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
"-DNDEBUG",
);
OTHER_LDFLAGS = (
- "$(LLDB_COMPRESSION_LDFLAGS)",
+ "-lcompression",
"$(LLDB_ZLIB_LDFLAGS)",
"$(LLDB_COVERAGE_LDFLAGS)",
);
@@ -10020,7 +9991,6 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
"-fno-rtti",
@@ -10089,10 +10059,7 @@
"$(LLVM_BUILD_DIR)/$(LLVM_BUILD_DIR_ARCH)",
"$(inherited)",
);
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CPLUSPLUSFLAGS = (
@@ -10598,7 +10565,6 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
"-fno-rtti",
@@ -10639,7 +10605,6 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
"-fno-rtti",
@@ -10713,8 +10678,7 @@
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- LLDB_COMPRESSION_CFLAGS = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_COVERAGE_CFLAGS = "$(LLDB_COVERAGE_CFLAGS_$(LLDB_ENABLE_COVERAGE))";
LLDB_COVERAGE_CFLAGS_1 = "-fprofile-instr-generate -fcoverage-mapping";
LLDB_COVERAGE_LDFLAGS = "$(LLDB_COVERAGE_LDFLAGS_$(LLDB_ENABLE_COVERAGE))";
@@ -10735,12 +10699,11 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
);
OTHER_LDFLAGS = (
- "$(LLDB_COMPRESSION_LDFLAGS)",
+ "-lcompression",
"$(LLDB_ZLIB_LDFLAGS)",
"$(LLDB_COVERAGE_LDFLAGS)",
);
@@ -10797,7 +10760,6 @@
OTHER_CFLAGS = (
"-Wparentheses",
"$(LLDB_ZLIB_CFLAGS)",
- "$(LLDB_COMPRESSION_CFLAGS)",
"$(LLDB_COVERAGE_CFLAGS)",
"-Wimplicit-fallthrough",
"-fno-rtti",
@@ -10848,10 +10810,7 @@
"$(LLVM_BUILD_DIR)/$(LLVM_BUILD_DIR_ARCH)",
"$(inherited)",
);
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
OTHER_CPLUSPLUSFLAGS = (
@@ -10934,10 +10893,7 @@
"LLDB_VERSION_STRING=lldb-${CURRENT_PROJECT_VERSION}",
);
HEADER_SEARCH_PATHS = /usr/include/libxml2;
- LLDB_COMPRESSION_CFLAGS = "";
- "LLDB_COMPRESSION_CFLAGS[sdk=macosx10.11]" = "-DHAVE_LIBCOMPRESSION=1";
- LLDB_COMPRESSION_LDFLAGS = "";
- "LLDB_COMPRESSION_LDFLAGS[sdk=macosx10.11]" = "-weak-lcompression";
+ LLDB_COMPRESSION_LDFLAGS = "-lcompression";
LLDB_ZLIB_CFLAGS = "-DHAVE_LIBZ=1";
LLDB_ZLIB_LDFLAGS = "-lz";
MACH_O_TYPE = staticlib;
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=349563&r1=349562&r2=349563&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Tue Dec 18 15:02:50 2018
@@ -42,7 +42,8 @@
#define DEBUGSERVER_BASENAME "lldb-server"
#endif
-#if defined(HAVE_LIBCOMPRESSION)
+#if defined(__APPLE__)
+#define HAVE_LIBCOMPRESSION
#include <compression.h>
#endif
@@ -67,7 +68,9 @@ GDBRemoteCommunication::GDBRemoteCommuni
#endif
m_echo_number(0), m_supports_qEcho(eLazyBoolCalculate), m_history(512),
m_send_acks(true), m_compression_type(CompressionType::None),
- m_listen_url() {
+ m_listen_url(), m_decompression_scratch_type(CompressionType::None),
+ m_decompression_scratch(nullptr)
+{
}
//----------------------------------------------------------------------
@@ -532,7 +535,7 @@ bool GDBRemoteCommunication::DecompressP
size_t decompressed_bytes = 0;
if (decompressed_bufsize != ULONG_MAX) {
- decompressed_buffer = (uint8_t *)malloc(decompressed_bufsize + 1);
+ decompressed_buffer = (uint8_t *)malloc(decompressed_bufsize);
if (decompressed_buffer == nullptr) {
m_bytes.erase(0, size_of_first_packet);
return false;
@@ -540,11 +543,10 @@ bool GDBRemoteCommunication::DecompressP
}
#if defined(HAVE_LIBCOMPRESSION)
- // libcompression is weak linked so check that compression_decode_buffer() is
- // available
if (m_compression_type == CompressionType::ZlibDeflate ||
m_compression_type == CompressionType::LZFSE ||
- m_compression_type == CompressionType::LZ4) {
+ m_compression_type == CompressionType::LZ4 ||
+ m_compression_type == CompressionType::LZMA) {
compression_algorithm compression_type;
if (m_compression_type == CompressionType::LZFSE)
compression_type = COMPRESSION_LZFSE;
@@ -555,16 +557,33 @@ bool GDBRemoteCommunication::DecompressP
else if (m_compression_type == CompressionType::LZMA)
compression_type = COMPRESSION_LZMA;
- // If we have the expected size of the decompressed payload, we can
- // allocate the right-sized buffer and do it. If we don't have that
- // information, we'll need to try decoding into a big buffer and if the
- // buffer wasn't big enough, increase it and try again.
+ if (m_decompression_scratch_type != m_compression_type) {
+ if (m_decompression_scratch) {
+ free (m_decompression_scratch);
+ m_decompression_scratch = nullptr;
+ }
+ size_t scratchbuf_size = 0;
+ if (m_compression_type == CompressionType::LZFSE)
+ scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE);
+ else if (m_compression_type == CompressionType::LZ4)
+ scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZ4_RAW);
+ else if (m_compression_type == CompressionType::ZlibDeflate)
+ scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_ZLIB);
+ else if (m_compression_type == CompressionType::LZMA)
+ scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZMA);
+ else if (m_compression_type == CompressionType::LZFSE)
+ scratchbuf_size = compression_decode_scratch_buffer_size (COMPRESSION_LZFSE);
+ if (scratchbuf_size > 0) {
+ m_decompression_scratch = (void*) malloc (scratchbuf_size);
+ m_decompression_scratch_type = m_compression_type;
+ }
+ }
if (decompressed_bufsize != ULONG_MAX && decompressed_buffer != nullptr) {
decompressed_bytes = compression_decode_buffer(
- decompressed_buffer, decompressed_bufsize + 10,
- (uint8_t *)unescaped_content.data(), unescaped_content.size(), NULL,
- compression_type);
+ decompressed_buffer, decompressed_bufsize,
+ (uint8_t *)unescaped_content.data(), unescaped_content.size(),
+ m_decompression_scratch, compression_type);
}
}
#endif
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h?rev=349563&r1=349562&r2=349563&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Tue Dec 18 15:02:50 2018
@@ -218,6 +218,9 @@ private:
HostThread m_listen_thread;
std::string m_listen_url;
+ CompressionType m_decompression_scratch_type;
+ void *m_decompression_scratch;
+
DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunication);
};
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=349563&r1=349562&r2=349563&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Tue Dec 18 15:02:50 2018
@@ -37,7 +37,8 @@
#include "llvm/ADT/StringSwitch.h"
-#if defined(HAVE_LIBCOMPRESSION)
+#if defined(__APPLE__)
+#define HAVE_LIBCOMPRESSION
#include <compression.h>
#endif
More information about the lldb-commits
mailing list