Refactor HAVE_LIBCOMPRESSION and related code in GDBRemoteCommunication
authorRaphael Isemann <teemperor@gmail.com>
Fri, 25 Jan 2019 08:21:47 +0000 (08:21 +0000)
committerRaphael Isemann <teemperor@gmail.com>
Fri, 25 Jan 2019 08:21:47 +0000 (08:21 +0000)
Summary:
The field `m_decompression_scratch_type` is only used when `HAVE_LIBCOMPRESSION` is
defined, which caused a warning which I fixed in rLLDB350675 by just marking the variable as always used.

This patch fixes this in a better way by only defining the variable (and the related `m_decompression_scratch`
variable) when `HAVE_LIBCOMPRESSION` is defined. This also required changing the way we handle
`HAVE_LIBCOMPRESSION` works, as this was previously always defined on macOS within the source file
but not in the header. Now it's always defined from within our config header when CMake defines it or when
we are on macOS.

The field initialization was moved to the header to prevent that we have `#ifdef` within our initializer list.

Reviewers: #lldb, jasonmolenda, sgraenitz, labath

Reviewed By: labath

Subscribers: labath, beanz, mgorny, lldb-commits, dblaikie

Differential Revision: https://reviews.llvm.org/D57011

llvm-svn: 352175

lldb/include/lldb/Host/Config.h
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h

index 9a7320f7229e3b88b9a9399c2248be861576541f..a16d739892be08f4be393b18abf8682634d235db 100644 (file)
@@ -25,6 +25,8 @@
 
 #define HAVE_SIGACTION 1
 
+#define HAVE_LIBCOMPRESSION 1
+
 #else
 
 #error This file is only used by the Xcode build.
index a617e7c80d3b41fa3506cb3d1f0a30efa7908a9a..8133ee567f16c3581a029b6336edd94f98961e7c 100644 (file)
@@ -41,8 +41,7 @@
 #define DEBUGSERVER_BASENAME "lldb-server"
 #endif
 
-#if defined(__APPLE__)
-#define HAVE_LIBCOMPRESSION
+#if defined(HAVE_LIBCOMPRESSION)
 #include <compression.h>
 #endif
 
@@ -67,10 +66,7 @@ GDBRemoteCommunication::GDBRemoteCommunication(const char *comm_name,
 #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_decompression_scratch_type(CompressionType::None),
-      m_decompression_scratch(nullptr) {
-  // Unused unless HAVE_LIBCOMPRESSION is defined.
-  (void)m_decompression_scratch_type;
+      m_listen_url() {
 }
 
 //----------------------------------------------------------------------
@@ -81,8 +77,10 @@ GDBRemoteCommunication::~GDBRemoteCommunication() {
     Disconnect();
   }
 
+#if defined(HAVE_LIBCOMPRESSION)
   if (m_decompression_scratch)
     free (m_decompression_scratch);
+#endif
 
   // Stop the communications read thread which is used to parse all incoming
   // packets.  This function will block until the read thread returns.
index 094cc94b0c1dd64bf761b0e4b5e7807efbdf55b7..4ef222406143cbd0afa125245d1a005dc1572ab5 100644 (file)
@@ -18,6 +18,7 @@
 #include <vector>
 
 #include "lldb/Core/Communication.h"
+#include "lldb/Host/Config.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Utility/Args.h"
 #include "lldb/Utility/Listener.h"
@@ -217,8 +218,10 @@ private:
   HostThread m_listen_thread;
   std::string m_listen_url;
 
-  CompressionType m_decompression_scratch_type;
-  void *m_decompression_scratch;
+#if defined(HAVE_LIBCOMPRESSION)
+  CompressionType m_decompression_scratch_type = CompressionType::None;
+  void *m_decompression_scratch = nullptr;
+#endif
 
   DISALLOW_COPY_AND_ASSIGN(GDBRemoteCommunication);
 };