]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: untangle `CURLDEBUG` and `DEBUGBUILD` macros
authorViktor Szakats <commit@vsz.me>
Mon, 20 May 2024 12:21:05 +0000 (14:21 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 28 May 2024 06:12:00 +0000 (08:12 +0200)
`CURLDEBUG` is meant to enable memory tracking, but in a bunch of cases,
it was protecting debug features that were supposed to be guarded with
`DEBUGBUILD`.

Replace these uses with `DEBUGBUILD`.

This leaves `CURLDEBUG` uses solely for its intended  purpose: to enable
the memory tracking debug feature.

Also:
- autotools: rely on `DEBUGBUILD` to enable `checksrc`.
  Instead of `CURLDEBUG`, which worked in most cases because debug
  builds enable `CURLDEBUG` by default, but it's not accurate.
- include `lib/easyif.h` instead of keeping a copy of a declaration.
- add CI test jobs for the build issues discovered.

Ref: https://github.com/curl/curl/pull/13694#issuecomment-2120311894
Closes #13718

24 files changed:
.github/workflows/windows.yml
CMake/CurlSymbolHiding.cmake
appveyor.yml
configure.ac
include/curl/Makefile.am
lib/Makefile.am
lib/cfilters.c
lib/conncache.h
lib/doh.c
lib/easy.c
lib/easyif.h
lib/http.c
lib/mqtt.c
lib/rand.c
lib/request.c
lib/url.c
lib/urldata.h
src/Makefile.am
src/tool_cfgable.h
src/tool_getparam.c
src/tool_operate.c
tests/Makefile.am
tests/libtest/Makefile.am
tests/server/Makefile.am

index 2ad79f34a90fcb7d42499af0a57eab960b8cad70..038ddd9eadb3ad96b815eecaec4e63d7e644f713 100644 (file)
@@ -165,7 +165,7 @@ jobs:
           - { build: 'autotools', sys: 'msys'   , env: 'x86_64'      , tflags: '!19                !1233', config: '--enable-debug --disable-threaded-resolver --disable-proxy' }
           - { build: 'autotools', sys: 'msys'   , env: 'x86_64'      , tflags: '!19 !504 !704 !705 !1233', config: '--enable-debug --disable-threaded-resolver' }
           - { build: 'autotools', sys: 'msys'   , env: 'x86_64'      , tflags: '!19 !504 !704 !705 !1233', config: '' }
-          - { build: 'autotools', sys: 'mingw64', env: 'x86_64'      , tflags: 'skiprun'                 , config: '--enable-debug --disable-threaded-resolver --enable-static=no' }
+          - { build: 'autotools', sys: 'mingw64', env: 'x86_64'      , tflags: 'skiprun'                 , config: '--enable-debug --disable-threaded-resolver --disable-curldebug --enable-static=no' }
           # FIXME: WebSockets test results ignored due to frequent failures on native Windows:
           - { build: 'cmake'    , sys: 'mingw64', env: 'x86_64'      , tflags: '!TFTP ~2301 ~2302'       , config: '-DENABLE_DEBUG=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON', type: 'Debug' }
           - { build: 'cmake'    , sys: 'mingw64', env: 'x86_64'      , tflags: 'skiprun'                 , config: '-DENABLE_DEBUG=OFF -DBUILD_SHARED_LIBS=ON -DCURL_USE_SCHANNEL=ON -DENABLE_UNICODE=ON -DENABLE_CURLDEBUG=ON', type: 'Release' }
index 8289b492468fb4c6d6d4fccd2bde83f0d91c1122..07f4fc0b6d254cefcf612fa2fdbf994b7cd71764 100644 (file)
@@ -26,9 +26,10 @@ include(CheckCSourceCompiles)
 option(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide all symbols that aren't officially external)." ON)
 mark_as_advanced(CURL_HIDDEN_SYMBOLS)
 
-if(WIN32 AND ENABLE_CURLDEBUG)
-  # We need to export internal debug functions (e.g. curl_dbg_*), so disable
-  # symbol hiding for debug builds.
+if(WIN32 AND (ENABLE_DEBUG OR ENABLE_CURLDEBUG))
+  # We need to export internal debug functions,
+  # e.g. curl_easy_perform_ev() or curl_dbg_*(),
+  # so disable symbol hiding for debug builds and for memory tracking.
   set(CURL_HIDDEN_SYMBOLS OFF)
 endif()
 
index 7c4e3b4cbe2d1a59ca1dfdee9c682b84dd2b2beb..381d672869869e7906371c3f49c0375e65078425 100644 (file)
@@ -100,6 +100,17 @@ environment:
       SCHANNEL: 'ON'
       ENABLE_UNICODE: 'ON'
       HTTP_ONLY: 'OFF'
+    - job_name: 'CMake, VS2022, Release, x64, Schannel, Shared, Unicode, DEBUGBULID, no-CURLDEBUG, Build-only'
+      APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022'
+      BUILD_SYSTEM: CMake
+      PRJ_GEN: 'Visual Studio 17 2022'
+      TARGET: '-A x64'
+      PRJ_CFG: Release
+      SCHANNEL: 'ON'
+      ENABLE_UNICODE: 'ON'
+      HTTP_ONLY: 'OFF'
+      SHARED: 'ON'
+      CURLDEBUG: 'OFF'
     - job_name: 'CMake, VS2022, Debug, x64, no SSL, Static, Build-only'
       APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2022'
       BUILD_SYSTEM: CMake
index 646c255b99e955409b3980b0bdd0b2c9bde2ffd3..85f0ab599b69a237b9b405aac45128d13575684a 100644 (file)
@@ -44,6 +44,7 @@ AM_MAINTAINER_MODE
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 CURL_CHECK_OPTION_DEBUG
+AM_CONDITIONAL(DEBUGBUILD, test x$want_debug = xyes)
 CURL_CHECK_OPTION_OPTIMIZE
 CURL_CHECK_OPTION_WARNINGS
 CURL_CHECK_OPTION_WERROR
@@ -549,7 +550,6 @@ CURL_CHECK_COMPILER_PROTOTYPE_MISMATCH
 CURL_CHECK_COMPILER_SYMBOL_HIDING
 
 CURL_CHECK_CURLDEBUG
-AM_CONDITIONAL(CURLDEBUG, test x$want_curldebug = xyes)
 
 supports_unittests=yes
 # cross-compilation of unit tests static library/programs fails when
index a655aff1c8a2a76cf9ce25022add37591542ab08..8864d60e1f2abcb40fe2a4a9549b51392a7a27b0 100644 (file)
@@ -35,7 +35,7 @@ CS_ = $(CS_0)
 checksrc:
        $(CHECKSRC)@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(top_srcdir)/include/curl $(pkginclude_HEADERS)
 
-if CURLDEBUG
+if DEBUGBUILD
 # for debug builds, we scan the sources on all regular make invokes
 all-local: checksrc
 endif
index 96afc59ac101b638c3b4c5cd6a1278bf942f3a4e..413fcd4d55426d1d5e1a279b2f6aef6928b2b157 100644 (file)
@@ -126,7 +126,7 @@ checksrc:
        -W$(srcdir)/curl_config.h $(srcdir)/*.[ch] $(srcdir)/vauth/*.[ch]   \
        $(srcdir)/vtls/*.[ch] $(srcdir)/vquic/*.[ch] $(srcdir)/vssh/*.[ch])
 
-if CURLDEBUG
+if DEBUGBUILD
 # for debug builds, we scan the sources on all regular make invokes
 all-local: checksrc
 endif
index 87b9ba4d43e007c304845f46825b6e7c774d3921..a1e405bc5e88bb07ce7ac5259aa51b2c3bfbbd21 100644 (file)
@@ -718,7 +718,7 @@ CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex,
   DEBUGASSERT(data);
   DEBUGASSERT(data->conn);
   conn = data->conn;
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
   {
     /* Allow debug builds to override this logic to force short sends
     */
index e68512394847c8ba9dee945015b7d10ee2f30143..295057e42f44639656f16fb68bd36b9cac3eeb15 100644 (file)
@@ -50,7 +50,7 @@ struct conncache {
 #define BUNDLE_UNKNOWN     0  /* initial value */
 #define BUNDLE_MULTIPLEX   2
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
 /* the debug versions of these macros make extra certain that the lock is
    never doubly locked or unlocked */
 #define CONNCACHE_LOCK(x)                                               \
index 03317ae27e8908548ce1e400e00948ae368e3e82..fda28a091614f4c7e24e4fe02166ed99a3c47269 100644 (file)
--- a/lib/doh.c
+++ b/lib/doh.c
@@ -191,7 +191,7 @@ doh_write_cb(const void *contents, size_t size, size_t nmemb, void *userp)
   return realsize;
 }
 
-#if defined(USE_HTTPSRR) && defined(CURLDEBUG)
+#if defined(USE_HTTPSRR) && defined(DEBUGBUILD)
 static void local_print_buf(struct Curl_easy *data,
                             const char *prefix,
                             unsigned char *buf, size_t len)
@@ -285,7 +285,7 @@ static CURLcode dohprobe(struct Curl_easy *data,
     ERROR_CHECK_SETOPT(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
     ERROR_CHECK_SETOPT(CURLOPT_PIPEWAIT, 1L);
 #endif
-#ifndef CURLDEBUG
+#ifndef DEBUGBUILD
     /* enforce HTTPS if not debug */
     ERROR_CHECK_SETOPT(CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
 #else
@@ -870,7 +870,7 @@ static void showdoh(struct Curl_easy *data,
   }
 #ifdef USE_HTTPSRR
   for(i = 0; i < d->numhttps_rrs; i++) {
-# ifdef CURLDEBUG
+# ifdef DEBUGBUILD
     local_print_buf(data, "DoH HTTPS",
                     d->https_rrs[i].val, d->https_rrs[i].len);
 # else
@@ -1143,7 +1143,7 @@ err:
   return CURLE_BAD_CONTENT_ENCODING;
 }
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
 static CURLcode test_alpn_escapes(void)
 {
   /* we'll use an example from draft-ietf-dnsop-svcb, figure 10 */
@@ -1176,7 +1176,7 @@ static CURLcode Curl_doh_decode_httpsrr(unsigned char *rrval, size_t len,
   struct Curl_https_rrinfo *lhrr = NULL;
   char *dnsname = NULL;
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
   /* a few tests of escaping, shouldn't be here but ok for now */
   if(test_alpn_escapes() != CURLE_OK)
     return CURLE_OUT_OF_MEMORY;
@@ -1244,7 +1244,7 @@ err:
   return CURLE_OUT_OF_MEMORY;
 }
 
-# ifdef CURLDEBUG
+# ifdef DEBUGBUILD
 static void local_print_httpsrr(struct Curl_easy *data,
                                 struct Curl_https_rrinfo *hrr)
 {
@@ -1382,7 +1382,7 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
         return result;
       }
       infof(data, "Some HTTPS RR to process");
-# ifdef CURLDEBUG
+# ifdef DEBUGBUILD
       local_print_httpsrr(data, hrr);
 # endif
       (*dnsp)->hinfo = hrr;
index a04dbedd87a89f4be0aa00a2592efebf2fb371a4..ba8cb2ed582ba3bf7bb37097e5a40b5a106d3994 100644 (file)
@@ -374,7 +374,7 @@ struct Curl_easy *curl_easy_init(void)
   return data;
 }
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
 
 struct socketmonitor {
   struct socketmonitor *next; /* the next node in the list or NULL */
@@ -655,7 +655,7 @@ static CURLcode easy_events(struct Curl_multi *multi)
 
   return wait_or_timeout(multi, &evs);
 }
-#else /* CURLDEBUG */
+#else /* DEBUGBUILD */
 /* when not built with debug, this function doesn't exist */
 #define easy_events(x) CURLE_NOT_BUILT_IN
 #endif
@@ -788,7 +788,7 @@ CURLcode curl_easy_perform(struct Curl_easy *data)
   return easy_perform(data, FALSE);
 }
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
 /*
  * curl_easy_perform_ev() is the external interface that performs a blocking
  * transfer using the event-based API internally.
index 6ce3483c643bc3b19a7210843c80b928bc75ab3b..d77bb98f920f337a4245c6ae0bed6d4dd2540b8d 100644 (file)
@@ -34,7 +34,7 @@ CURLcode Curl_senddata(struct Curl_easy *data, const void *buffer,
 CURLcode Curl_connect_only_attach(struct Curl_easy *data);
 #endif
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
 CURL_EXTERN CURLcode curl_easy_perform_ev(struct Curl_easy *easy);
 #endif
 
index 0adfc63386299fa4b566f6b32f7f865752bcd140..514e9aebea17e57fb735c48fd5a3c4fc80839da3 100644 (file)
@@ -2849,7 +2849,7 @@ CURLcode Curl_http_header(struct Curl_easy *data,
 #ifndef CURL_DISABLE_ALTSVC
     v = (data->asi &&
          ((data->conn->handler->flags & PROTOPT_SSL) ||
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
           /* allow debug builds to circumvent the HTTPS restriction */
           getenv("CURL_ALTSVC_HTTP")
 #else
@@ -3116,7 +3116,7 @@ CURLcode Curl_http_header(struct Curl_easy *data,
     /* If enabled, the header is incoming and this is over HTTPS */
     v = (data->hsts &&
          ((conn->handler->flags & PROTOPT_SSL) ||
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
            /* allow debug builds to circumvent the HTTPS restriction */
            getenv("CURL_HSTS_HTTP")
 #else
index 4ca24eb41c4905948ce1c06b965aa16d997c120c..17a8d2a3d7525c28149662734c76e35a79b9bea7 100644 (file)
@@ -585,7 +585,7 @@ static size_t mqtt_decode_len(unsigned char *buf,
   return len;
 }
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
 static const char *statenames[]={
   "MQTT_FIRST",
   "MQTT_REMAINING_LENGTH",
@@ -606,7 +606,7 @@ static void mqstate(struct Curl_easy *data,
 {
   struct connectdata *conn = data->conn;
   struct mqtt_conn *mqtt = &conn->proto.mqtt;
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
   infof(data, "%s (from %s) (next is %s)",
         statenames[state],
         statenames[mqtt->state],
index c62b1a40323f5fc8005d0089b2397ef74dcbcb3a..65e05e57ab55bf4971f22911e5942dcdf5876132 100644 (file)
@@ -105,7 +105,7 @@ static CURLcode randit(struct Curl_easy *data, unsigned int *rnd)
   static unsigned int randseed;
   static bool seeded = FALSE;
 
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
   char *force_entropy = getenv("CURL_ENTROPY");
   if(force_entropy) {
     if(!seeded) {
index 26741fa6cb5550d605c75cca188a1c6484bf6859..794bdb7245a5330cf34b5644f1a70fae3653782a 100644 (file)
@@ -187,7 +187,7 @@ static CURLcode xfer_send(struct Curl_easy *data,
   CURLcode result = CURLE_OK;
 
   *pnwritten = 0;
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
   {
     /* Allow debug builds to override this logic to force short initial
        sends
index 2814d31ad90b7bc6a27fba549e87a2ad28819e7a..7287d2d893c04aa9544e9b50cae01e55e2703698 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3028,7 +3028,7 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data,
 #ifndef CURL_DISABLE_ALTSVC
   if(data->asi && !host && (port == -1) &&
      ((conn->handler->protocol == CURLPROTO_HTTPS) ||
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
       /* allow debug builds to circumvent the HTTPS restriction */
       getenv("CURL_ALTSVC_HTTP")
 #else
index 8b1bd65d614de555897c9d8327f52e3f720d05e6..48844d2707ed0a71aa46cc4dd26958cb30307fac 100644 (file)
@@ -1375,7 +1375,7 @@ struct UrlState {
   unsigned char select_bits; /* != 0 -> bitmask of socket events for this
                                  transfer overriding anything the socket may
                                  report */
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
   BIT(conncache_lock);
 #endif
   /* when curl_easy_perform() is called, the multi handle is "owned" by
index 3bf57d36cecfd0304dfda3d55d055e372ba661dc..fe53644e39e9fb643115453b1ba56b9d64965f91 100644 (file)
@@ -145,7 +145,7 @@ checksrc:
        $(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \
        -W$(srcdir)/tool_hugehelp.c $(srcdir)/*.[ch])
 
-if CURLDEBUG
+if DEBUGBUILD
 # for debug builds, we scan the sources on all regular make invokes
 all-local: checksrc
 endif
index 74d0c45f2ed12160efa145aa220c7f26d019697f..5d99d605f3c7c336c4642daf0011349ea63bf949 100644 (file)
@@ -323,7 +323,7 @@ struct GlobalConfig {
   bool styled_output;             /* enable fancy output style detection */
   long ms_per_transfer;           /* start next transfer after (at least) this
                                      many milliseconds */
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
   bool test_event_based;
 #endif
   bool parallel;
index 508e56797a573f5e4a103a73a7eb1af2dcf0a0ea..e3eb12fa0b0b8b809d28fb9ea7ec9ce892455a42 100644 (file)
@@ -1825,7 +1825,7 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
       config->sasl_ir = toggle;
       break;
     case C_TEST_EVENT: /* --test-event */
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
       global->test_event_based = toggle;
 #else
       warnf(global, "--test-event is ignored unless a debug build");
index 535712d1236c0586ec7ba7626aa30645b01b9540..b5e7d4ccff43a2cfce5d5e12d455431827885817 100644 (file)
 #include "tool_progress.h"
 #include "tool_ipfs.h"
 #include "dynbuf.h"
+#ifdef DEBUGBUILD
+#include "easyif.h"  /* for libcurl's debug-only curl_easy_perform_ev() */
+#endif
 
 #include "memdebug.h" /* keep this as LAST include */
 
-#ifdef CURLDEBUG
-/* libcurl's debug builds provide an extra function */
-CURLcode curl_easy_perform_ev(CURL *easy);
-#endif
-
 #ifndef O_BINARY
 /* since O_BINARY as used in bitmasks, setting it to zero makes it usable in
    source code but yet it doesn't ruin anything */
@@ -1315,7 +1313,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         my_setopt(curl, CURLOPT_SEEKFUNCTION, tool_seek_cb);
 
         {
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
           char *env = getenv("CURL_BUFFERSIZE");
           if(env) {
             long size = strtol(env, NULL, 10);
@@ -1647,7 +1645,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
            *  must do the same thing as classic:
            *    --cert <filename>:<password> --cert-type p12
            *  but is designed to test blob */
-#if defined(CURLDEBUG) || defined(DEBUGBUILD)
+#ifdef DEBUGBUILD
           if(config->cert && (strlen(config->cert) > 8) &&
              (memcmp(config->cert, "loadmem=",8) == 0)) {
             FILE *fInCert = fopen(config->cert + 8, "rb");
@@ -1690,7 +1688,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
                         config->proxy_cert_type);
 
 
-#if defined(CURLDEBUG) || defined(DEBUGBUILD)
+#ifdef DEBUGBUILD
           if(config->key && (strlen(config->key) > 8) &&
              (memcmp(config->key, "loadmem=",8) == 0)) {
             FILE *fInCert = fopen(config->key + 8, "rb");
@@ -2484,7 +2482,7 @@ static CURLcode serial_transfers(struct GlobalConfig *global,
         break;
     }
     start = tvnow();
-#ifdef CURLDEBUG
+#ifdef DEBUGBUILD
     if(global->test_event_based)
       result = curl_easy_perform_ev(per->curl);
     else
index 7e6697f977e494441a5b18a5cec5cc802f8cd61d..726d37b52c1506fb456d2274d4fa6ec901e933a1 100644 (file)
@@ -162,7 +162,7 @@ checksrc:
        (cd server && $(MAKE) checksrc)
        (cd http && $(MAKE) checksrc)
 
-if CURLDEBUG
+if DEBUGBUILD
 # for debug builds, we scan the sources on all regular make invokes
 all-local: checksrc
 endif
index 8ae972a248ddc6a027f1f3e52c49125a78e27aac..eed916eebb4b7f2fe134295050e1f2a58fed073d 100644 (file)
@@ -134,7 +134,7 @@ CS_ = $(CS_0)
 checksrc:
        $(CHECKSRC)@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) $(srcdir)/*.[ch]
 
-if CURLDEBUG
+if DEBUGBUILD
 # for debug builds, we scan the sources on all regular make invokes
 all-local: checksrc
 endif
index b08942263c4864cc342e528a98daf40aa7796cae..dda121377a286451057139d129879fc4a009d1f9 100644 (file)
@@ -59,7 +59,7 @@ CS_ = $(CS_0)
 checksrc:
        $(CHECKSRC)@PERL@ $(top_srcdir)/scripts/checksrc.pl $(srcdir)/*.[ch]
 
-if CURLDEBUG
+if DEBUGBUILD
 # for debug builds, we scan the sources on all regular make invokes
 all-local: checksrc
 endif