From bda701da5c0a1c44b7b3422a7ab967260ed39c91 Mon Sep 17 00:00:00 2001 From: Walt Karas Date: Thu, 24 Aug 2023 14:04:53 +0000 Subject: [PATCH 1/2] Use Dbg() for debug output in both core and plugins. Eliminate TSDbg(), TSIsDbgCtlSet(), TSDbgCtlCreate(), TSDbgCtlDestroy(). Eliminate TSDbgCtlUniqPtr type. --- .../plugins/c-api/cache_scan/cache_scan.cc | 14 +- include/ts/DbgCtl.h | 120 ++++++++++++++++++ include/ts/Makefile.am | 1 + include/ts/apidefs.h.in | 5 - include/ts/ts.h | 49 +------ include/tscore/DbgCtl.h | 62 --------- include/tscore/Diags.h | 49 ++----- include/tscore/DiagsTypes.h | 7 - include/tscore/Trie.h | 4 +- include/tscpp/api/Cleanup.h | 11 -- iocore/cache/Cache.cc | 14 +- iocore/cache/CacheDir.cc | 2 +- iocore/cache/CacheHosting.cc | 4 +- iocore/cache/CacheRead.cc | 8 +- iocore/cache/CacheWrite.cc | 2 +- iocore/dns/DNS.cc | 4 +- iocore/dns/P_DNSProcessor.h | 2 +- iocore/dns/SplitDNS.cc | 4 +- iocore/net/SSLDiags.cc | 10 +- iocore/net/SSLUtils.cc | 4 +- iocore/net/TLSSessionResumptionSupport.cc | 2 +- .../webp_transform/ImageTransform.cc | 24 ++-- src/traffic_server/InkAPI.cc | 27 ---- src/tscore/DbgCtl.cc | 58 +++++---- src/tscore/Diags.cc | 10 +- .../pluginTest/TSVConnFd/TSVConnFd.cc | 32 +++-- .../polite_hook_wait/polite_hook_wait.cc | 13 +- .../gold_tests/pluginTest/tsapi/test_tsapi.cc | 15 +-- 28 files changed, 248 insertions(+), 309 deletions(-) create mode 100644 include/ts/DbgCtl.h delete mode 100644 include/tscore/DbgCtl.h diff --git a/example/plugins/c-api/cache_scan/cache_scan.cc b/example/plugins/c-api/cache_scan/cache_scan.cc index e56ccbba37a..89d94dc2b2d 100644 --- a/example/plugins/c-api/cache_scan/cache_scan.cc +++ b/example/plugins/c-api/cache_scan/cache_scan.cc @@ -36,7 +36,7 @@ #define PLUGIN_NAME "cache_scan" -static const TSDbgCtl *const dbg_ctl = TSDbgCtlCreate(PLUGIN_NAME); +static DbgCtl dbg_ctl{PLUGIN_NAME}; static TSCont global_contp; @@ -285,14 +285,14 @@ handle_io(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */) return 0; } break; case TS_EVENT_VCONN_WRITE_READY: { - TSDbg(dbg_ctl, "ndone: %" PRId64 " total_bytes: % " PRId64, TSVIONDoneGet(cstate->write_vio), cstate->total_bytes); + Dbg(dbg_ctl, "ndone: %" PRId64 " total_bytes: % " PRId64, TSVIONDoneGet(cstate->write_vio), cstate->total_bytes); cstate->write_pending = false; // the cache scan handler should call vio reenable when there is // available data return 0; } break; case TS_EVENT_VCONN_WRITE_COMPLETE: { - TSDbg(dbg_ctl, "write complete"); + Dbg(dbg_ctl, "write complete"); cstate->done = 1; cleanup(contp); } break; @@ -311,7 +311,7 @@ handle_io(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */) static int cache_intercept(TSCont contp, TSEvent event, void *edata) { - TSDbg(dbg_ctl, "cache_intercept event: %d", event); + Dbg(dbg_ctl, "cache_intercept event: %d", event); switch (event) { case TS_EVENT_NET_ACCEPT: @@ -439,7 +439,7 @@ setup_request(TSCont contp, TSHttpTxn txnp) end = start + del_url_len; cstate->key_to_delete = TSCacheKeyCreate(); - TSDbg(dbg_ctl, "deleting url: %s", start); + Dbg(dbg_ctl, "deleting url: %s", start); TSMBuffer urlBuf = TSMBufferCreate(); TSMLoc urlLoc; @@ -463,9 +463,9 @@ setup_request(TSCont contp, TSHttpTxn txnp) } TSContDataSet(scan_contp, cstate); - TSDbg(dbg_ctl, "setup cache intercept"); + Dbg(dbg_ctl, "setup cache intercept"); } else { - TSDbg(dbg_ctl, "not a cache iter request"); + Dbg(dbg_ctl, "not a cache iter request"); } Ldone: diff --git a/include/ts/DbgCtl.h b/include/ts/DbgCtl.h new file mode 100644 index 00000000000..d9cd3d64f99 --- /dev/null +++ b/include/ts/DbgCtl.h @@ -0,0 +1,120 @@ +/** @file + + DbgCtl class header file. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#pragma once + +#include +#include + +#include // For TS_PRINTFLIKE + +class DiagsConfigState; + +class DbgCtl +{ +public: + // Tag is a debug tag. Debug output associated with this control will be output when debug output + // is enabled globally, and the tag matches the configured debug tag regular expression. + // + DbgCtl(char const *tag) : _ptr{_new_reference(tag)} {} + + ~DbgCtl() { _rm_reference(); } + + bool + tag_on() const + { + return _ptr->second; + } + + char const * + tag() const + { + return _ptr->first; + } + + bool + on() const + { + auto m{_config_mode.load(std::memory_order_relaxed)}; + if (!m) { + return false; + } + if (!_ptr->second) { + return false; + } + if (m & 1) { + return true; + } + return (2 == m) && (_override_global_on()); + } + + static bool + global_on() + { + auto m{_config_mode.load(std::memory_order_relaxed)}; + if (!m) { + return false; + } + if (m & 1) { + return true; + } + return (2 == m) && (_override_global_on()); + } + + // Call this when the compiled regex to enable tags may have changed. + // + static void update(); + + // For use in DbgPrint() only. + // + static void print(char const *tag, char const *file, char const *function, int line, char const *fmt_str, ...) + TS_PRINTFLIKE(5, 6); + +private: + using _TagData = std::pair; + + _TagData const *const _ptr; + + static const _TagData *_new_reference(char const *tag); + + static void _rm_reference(); + + class _RegistryAccessor; + + static std::atomic _config_mode; + + static bool _override_global_on(); + + friend class DiagsConfigState; +}; + +// Always generates output when called. +// +#define DbgPrint(CTL, ...) (DbgCtl::print((CTL).tag(), __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)) + +#define Dbg(CTL, ...) \ + do { \ + if ((CTL).on()) { \ + DbgPrint((CTL), __VA_ARGS__); \ + } \ + } while (false) diff --git a/include/ts/Makefile.am b/include/ts/Makefile.am index f59de4e5ef4..5cfe0741b27 100644 --- a/include/ts/Makefile.am +++ b/include/ts/Makefile.am @@ -20,6 +20,7 @@ library_includedir=$(includedir)/ts library_include_HEADERS = \ apidefs.h \ + DbgCtl.h \ ts.h \ remap.h \ experimental.h \ diff --git a/include/ts/apidefs.h.in b/include/ts/apidefs.h.in index 1108da0c9d4..ee9e0e301e0 100644 --- a/include/ts/apidefs.h.in +++ b/include/ts/apidefs.h.in @@ -1114,11 +1114,6 @@ char const TS_VERSION_STRING[] = "@TS_VERSION_STRING@"; TSIOBufferWaterMark buffer_water_mark; }; - struct TSDbgCtl { - char volatile on; // Flag - char const *tag; - }; - /* -------------------------------------------------------------------------- URL schemes */ extern const char *TS_URL_SCHEME_FILE; diff --git a/include/ts/ts.h b/include/ts/ts.h index 6e300b5ff51..3191f236173 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -33,6 +33,7 @@ #include #include +#include class DiagsConfigState; @@ -2206,54 +2207,6 @@ namespace c if (diags_on_for_plugins) \ TSDebug - class TSDbgCtlDetail - { - friend bool TSIsDbgCtlSet(TSDbgCtl const *ctlp); - - static bool debug_on; - - friend class ::DiagsConfigState; - }; - - inline bool - TSIsDbgCtlSet(TSDbgCtl const *ctlp) - { - return (TSDbgCtlDetail::debug_on && ctlp->on); - } - -/** - Output a debug line if the debug output control is turned on. - - @param ctlp pointer to TSDbgCtl, returned by TSDbgCtlCreate(). - @param ... Format string and (optional) arguments. - */ -#define TSDbg(ctlp, ...) \ - do { \ - if (TSIsDbgCtlSet(ctlp)) { \ - _TSDbg(ctlp->tag, __VA_ARGS__); \ - } \ - } while (0) - - /** - Return a pointer for use with TSDbg(). For good performance, - this should be called in TSPluginInit() or TSRemapInit(), or in - static initialization in C++ (with the result stored in a - static pointer). - - @param tag Debug tag for the control. - */ - TSDbgCtl const *TSDbgCtlCreate(char const *tag); - - /** - Destroy (dereference) a debug control object previously created - with TSDbgCtlCreate(). - - @param dbg_ctl pointer to debug control object. - */ - void TSDbgCtlDestroy(TSDbgCtl const *dbg_ctl); - - void _TSDbg(const char *tag, const char *format_str, ...) TS_PRINTFLIKE(2, 3); /* Not for direct use. */ - /* -------------------------------------------------------------------------- logging api */ diff --git a/include/tscore/DbgCtl.h b/include/tscore/DbgCtl.h deleted file mode 100644 index 72f8df6e0d5..00000000000 --- a/include/tscore/DbgCtl.h +++ /dev/null @@ -1,62 +0,0 @@ -/** @file - - DbgCtl class header file. - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#pragma once - -#include - -// For use with TSDbg(). -// -class DbgCtl -{ -public: - // Tag is a debug tag. Debug output associated with this control will be output when debug output - // is enabled globally, and the tag matches the configured debug tag regular expression. - // - DbgCtl(char const *tag) : _ptr{_new_reference(tag)} {} - - ~DbgCtl() { _rm_reference(); } - - TSDbgCtl const * - ptr() const - { - return _ptr; - } - - // Call this when the compiled regex to enable tags may have changed. - // - static void update(); - -private: - TSDbgCtl const *const _ptr; - - static const TSDbgCtl *_new_reference(char const *tag); - - static void _rm_reference(); - - class _RegistryAccessor; - - friend TSDbgCtl const *tsapi::c::TSDbgCtlCreate(char const *tag); - - friend void tsapi::c::TSDbgCtlDestroy(TSDbgCtl const *dbg_ctl); -}; diff --git a/include/tscore/Diags.h b/include/tscore/Diags.h index 1bdcaf8e32c..52a13ba308b 100644 --- a/include/tscore/Diags.h +++ b/include/tscore/Diags.h @@ -33,6 +33,7 @@ #pragma once +#include #include "DiagsTypes.h" #include "SourceLocation.h" #include "LogMessage.h" @@ -163,39 +164,12 @@ diags() } \ } while (false) -inline bool -is_dbg_ctl_enabled(DbgCtl const &ctl) -{ - return unlikely(diags()->on()) && ctl.ptr()->on; -} - -// printf-line debug output. First parameter must be DbgCtl instance. Assumes debug control is enabled, and -// debug output globally enabled. -// -#define DbgPrint(CTL, ...) \ - do { \ - static const SourceLocation DbgPrintf_loc = MakeSourceLocation(); \ - static LogMessage DbgPrintf_log_message; \ - DbgPrintf_log_message.print(CTL.ptr()->tag, DL_Debug, DbgPrintf_loc, __VA_ARGS__); \ - } while (false) - -// printf-like debug output. First parameter must be an instance of DbgCtl. -// -#define Dbg(CTL, ...) \ - do { \ - if (unlikely(diags()->on()) && CTL.ptr()->on) { \ - DbgPrint(CTL, __VA_ARGS__); \ - } \ - } while (false) - // A BufferWriter version of Dbg(). -#define Dbg_bw(ctl__, fmt, ...) \ - do { \ - if (unlikely(diags()->on())) { \ - if (ctl__.ptr()->on) { \ - DbgPrint(ctl__, "%s", swoc::bwprint(ts::bw_dbg, fmt, __VA_ARGS__).c_str()); \ - } \ - } \ +#define Dbg_bw(ctl__, fmt, ...) \ + do { \ + if (ctl__.on()) { \ + DbgPrint(ctl__, "%s", swoc::bwprint(ts::bw_dbg, fmt, __VA_ARGS__).c_str()); \ + } \ } while (false) // A BufferWriter version of Debug(). @@ -203,7 +177,7 @@ is_dbg_ctl_enabled(DbgCtl const &ctl) do { \ if (unlikely(diags()->on())) { \ static DbgCtl Debug_bw_ctl(tag__); \ - if (Debug_bw_ctl.ptr()->on) { \ + if (Debug_bw_ctl.tag_on()) { \ DbgPrint(Debug_bw_ctl, "%s", swoc::bwprint(ts::bw_dbg, fmt, __VA_ARGS__).c_str()); \ } \ } \ @@ -216,7 +190,7 @@ is_dbg_ctl_enabled(DbgCtl const &ctl) do { \ if (unlikely(diags()->on())) { \ static DbgCtl Debug_ctl(TAG); \ - if (Debug_ctl.ptr()->on) { \ + if (Debug_ctl.tag_on()) { \ DbgPrint(Debug_ctl, __VA_ARGS__); \ } \ } \ @@ -227,7 +201,7 @@ is_dbg_ctl_enabled(DbgCtl const &ctl) #define SpecificDbg(FLAG, CTL, ...) \ do { \ if (unlikely(diags()->on())) { \ - if (FLAG || CTL.ptr()->on) { \ + if ((FLAG) || CTL.tag_on()) { \ DbgPrint(CTL, __VA_ARGS__); \ } \ } \ @@ -238,7 +212,7 @@ is_dbg_ctl_enabled(DbgCtl const &ctl) #define is_debug_tag_set(TAG) \ (unlikely(diags()->on()) && ([]() -> bool { \ static DbgCtl idts_ctl(TAG); \ - return idts_ctl.ptr()->on != 0; \ + return idts_ctl.tag_on() != 0; \ }())) #define SpecificDebug(FLAG, TAG, ...) \ @@ -246,7 +220,7 @@ is_dbg_ctl_enabled(DbgCtl const &ctl) { \ static DbgCtl SpecificDebug_ctl(TAG); \ if (unlikely(diags()->on())) { \ - if (FLAG || SpecificDebug_ctl.ptr()->on) { \ + if (FLAG || SpecificDebug_ctl.tag_on()) { \ DbgPrint(SpecificDebug_ctl, __VA_ARGS__); \ } \ } \ @@ -261,7 +235,6 @@ is_dbg_ctl_enabled(DbgCtl const &ctl) #else // TS_USE_DIAGS #define Diag(...) -#define Dbg(...) #define Debug(...) #define SpecificDbg(...) diff --git a/include/tscore/DiagsTypes.h b/include/tscore/DiagsTypes.h index f2fb9a2763f..60b0fe25ab4 100644 --- a/include/tscore/DiagsTypes.h +++ b/include/tscore/DiagsTypes.h @@ -41,7 +41,6 @@ #include "ink_mutex.h" #include "Regex.h" #include "SourceLocation.h" -#include "DbgCtl.h" #include "tscpp/util/ts_diag_levels.h" @@ -172,12 +171,6 @@ class Diags return unlikely(this->on_for_TSDebug()) && tag_activated(tag, DiagsTagType_Debug); } - bool - on(DbgCtl const &ctl) const - { - return unlikely(this->on(DiagsTagType_Debug)) && ctl.ptr()->on; - } - ///////////////////////////////////// // low-level tag inquiry functions // ///////////////////////////////////// diff --git a/include/tscore/Trie.h b/include/tscore/Trie.h index bb37ac4053a..b52b36a5152 100644 --- a/include/tscore/Trie.h +++ b/include/tscore/Trie.h @@ -149,7 +149,7 @@ Trie::Insert(const char *key, T *value, int rank, int key_len /* = -1 */) int i = 0; while (true) { - if (is_dbg_ctl_enabled(dbg_ctl_insert)) { + if (dbg_ctl_insert.on()) { Dbg(dbg_ctl_insert, "Visiting Node..."); curr_node->Print(dbg_ctl_insert); } @@ -195,7 +195,7 @@ Trie::Search(const char *key, int key_len /* = -1 */) const int i = 0; while (curr_node) { - if (is_dbg_ctl_enabled(dbg_ctl_search)) { + if (dbg_ctl_search.on()) { DbgPrint(dbg_ctl_search, "Visiting node..."); curr_node->Print(dbg_ctl_search); } diff --git a/include/tscpp/api/Cleanup.h b/include/tscpp/api/Cleanup.h index b70ccfe3d6a..ab383a5ec36 100644 --- a/include/tscpp/api/Cleanup.h +++ b/include/tscpp/api/Cleanup.h @@ -100,17 +100,6 @@ struct TSIOBufferReaderDeleter { }; using TSIOBufferReaderUniqPtr = std::unique_ptr, TSIOBufferReaderDeleter>; -// Deleter and unique pointer for TSDbgCtl const. -// -struct TSDbgCtlDeleter { - void - operator()(TSDbgCtl const *ptr) - { - TSDbgCtlDestroy(ptr); - } -}; -using TSDbgCtlUniqPtr = std::unique_ptr; - class TxnAuxDataMgrBase { protected: diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc index 660714715f9..1576fa0f0e7 100644 --- a/iocore/cache/Cache.cc +++ b/iocore/cache/Cache.cc @@ -847,7 +847,7 @@ CacheProcessor::diskInitialized() gnvol = 0; for (i = 0; i < gndisks; i++) { CacheDisk *d = gdisks[i]; - if (is_dbg_ctl_enabled(dbg_ctl_cache_hosting)) { + if (dbg_ctl_cache_hosting.on()) { int j; DbgPrint(dbg_ctl_cache_hosting, "Disk: %d:%s: Vol Blocks: %u: Free space: %" PRIu64, i, d->path, d->header->num_diskvol_blks, d->free_space); @@ -1611,7 +1611,7 @@ Ldone : { /* if we come back to the starting position, then we don't have to recover anything */ if (recover_pos == header->write_pos && recover_wrapped) { SET_HANDLER(&Vol::handle_recover_write_dir); - if (is_dbg_ctl_enabled(dbg_ctl_cache_init)) { + if (dbg_ctl_cache_init.on()) { Note("recovery wrapped around. nothing to clear\n"); } return handle_recover_write_dir(EVENT_IMMEDIATE, nullptr); @@ -1732,7 +1732,7 @@ Vol::handle_header_read(int event, void *data) if (hf[0]->sync_serial == hf[1]->sync_serial && (hf[0]->sync_serial >= hf[2]->sync_serial || hf[2]->sync_serial != hf[3]->sync_serial)) { SET_HANDLER(&Vol::handle_dir_read); - if (is_dbg_ctl_enabled(dbg_ctl_cache_init)) { + if (dbg_ctl_cache_init.on()) { Note("using directory A for '%s'", hash_text.get()); } io.aiocb.aio_offset = skip; @@ -1741,7 +1741,7 @@ Vol::handle_header_read(int event, void *data) // try B else if (hf[2]->sync_serial == hf[3]->sync_serial) { SET_HANDLER(&Vol::handle_dir_read); - if (is_dbg_ctl_enabled(dbg_ctl_cache_init)) { + if (dbg_ctl_cache_init.on()) { Note("using directory B for '%s'", hash_text.get()); } io.aiocb.aio_offset = skip + this->dirlen(); @@ -2218,7 +2218,7 @@ CacheVC::handleReadDone(int event, Event *e) } #endif - if (is_dbg_ctl_enabled(dbg_ctl_cache_read)) { + if (dbg_ctl_cache_read.on()) { char xt[CRYPTO_HEX_SIZE]; Dbg(dbg_ctl_cache_read, "Read complete on fragment %s. Length: data payload=%d this fragment=%d total doc=%" PRId64 " prefix=%d", @@ -3039,7 +3039,7 @@ Cache::key_to_vol(const CacheKey *key, const char *hostname, int host_len) if (res.record) { unsigned short *host_hash_table = res.record->vol_hash_table; if (host_hash_table) { - if (is_dbg_ctl_enabled(dbg_ctl_cache_hosting)) { + if (dbg_ctl_cache_hosting.on()) { char format_str[50]; snprintf(format_str, sizeof(format_str), "Volume: %%xd for host: %%.%ds", host_len); Dbg(dbg_ctl_cache_hosting, format_str, res.record, hostname); @@ -3049,7 +3049,7 @@ Cache::key_to_vol(const CacheKey *key, const char *hostname, int host_len) } } if (hash_table) { - if (is_dbg_ctl_enabled(dbg_ctl_cache_hosting)) { + if (dbg_ctl_cache_hosting.on()) { char format_str[50]; snprintf(format_str, sizeof(format_str), "Generic volume: %%xd for host: %%.%ds", host_len); Dbg(dbg_ctl_cache_hosting, format_str, host_rec, hostname); diff --git a/iocore/cache/CacheDir.cc b/iocore/cache/CacheDir.cc index d9f4cd2588d..b4bf725e4e8 100644 --- a/iocore/cache/CacheDir.cc +++ b/iocore/cache/CacheDir.cc @@ -382,7 +382,7 @@ dir_clean_bucket(Dir *b, int s, Vol *vol) } #endif if (!dir_valid(vol, e) || !dir_offset(e)) { - if (is_dbg_ctl_enabled(dbg_ctl_dir_clean)) { + if (dbg_ctl_dir_clean.on()) { Dbg(dbg_ctl_dir_clean, "cleaning Vol:%s: %p tag %X boffset %" PRId64 " b %p p %p bucket len %d", vol->hash_text.get(), e, dir_tag(e), dir_offset(e), b, p, dir_bucket_length(b, s, vol)); } diff --git a/iocore/cache/CacheHosting.cc b/iocore/cache/CacheHosting.cc index 2f8fc061fbb..7589900e810 100644 --- a/iocore/cache/CacheHosting.cc +++ b/iocore/cache/CacheHosting.cc @@ -392,7 +392,7 @@ CacheHostTable::BuildTableFromString(const char *config_file_path, char *file_bu ink_assert(second_pass == numEntries); - if (is_dbg_ctl_enabled(dbg_ctl_matcher)) { + if (dbg_ctl_matcher.on()) { Print(); } return numEntries; @@ -1053,7 +1053,7 @@ execute_and_verify(RegressionTest *t) for (int i = 0; i < gndisks; i++) { CacheDisk *d = gdisks[i]; - if (is_dbg_ctl_enabled(dbg_ctl_cache_hosting)) { + if (dbg_ctl_cache_hosting.on()) { Dbg(dbg_ctl_cache_hosting, "Disk: %d: Vol Blocks: %u: Free space: %" PRIu64, i, d->header->num_diskvol_blks, d->free_space); for (int j = 0; j < static_cast(d->header->num_volumes); j++) { Dbg(dbg_ctl_cache_hosting, "\tVol: %d Size: %" PRIu64, d->disk_vols[j]->vol_number, d->disk_vols[j]->size); diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc index 36d1a0f49bc..f7e55474fe8 100644 --- a/iocore/cache/CacheRead.cc +++ b/iocore/cache/CacheRead.cc @@ -669,7 +669,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) return calluser(VC_EVENT_EOS); } HTTPInfo::FragOffset *frags = alternate.get_frag_table(); - if (is_dbg_ctl_enabled(dbg_ctl_cache_seek)) { + if (dbg_ctl_cache_seek.on()) { char b[CRYPTO_HEX_SIZE], c[CRYPTO_HEX_SIZE]; Dbg(dbg_ctl_cache_seek, "Seek @ %" PRId64 " in %s from #%d @ %" PRId64 "/%d:%s", seek_to, first_key.toHexStr(b), fragment, doc_pos, doc->len, doc->key.toHexStr(c)); @@ -715,7 +715,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) --fragment; } - if (is_dbg_ctl_enabled(dbg_ctl_cache_seek)) { + if (dbg_ctl_cache_seek.on()) { char target_key_str[CRYPTO_HEX_SIZE]; key.toHexStr(target_key_str); DbgPrint(dbg_ctl_cache_seek, "Seek #%d @ %" PRId64 " -> #%d @ %" PRId64 ":%s", cfi, doc_pos, target, seek_to, @@ -732,7 +732,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) seek_to = 0; ntodo = vio.ntodo(); bytes = doc->len - doc_pos; - if (is_dbg_ctl_enabled(dbg_ctl_cache_seek)) { + if (dbg_ctl_cache_seek.on()) { char target_key_str[CRYPTO_HEX_SIZE]; DbgPrint(dbg_ctl_cache_seek, "Read # %d @ %" PRId64 "/%d for %" PRId64 " %s", fragment, doc_pos, doc->len, bytes, key.toHexStr(target_key_str)); @@ -1215,7 +1215,7 @@ CacheVC::openReadStartHead(int event, Event *e) doc_len = doc->total_len; } - if (is_dbg_ctl_enabled(dbg_ctl_cache_read)) { // amc debug + if (dbg_ctl_cache_read.on()) { // amc debug char xt[CRYPTO_HEX_SIZE], yt[CRYPTO_HEX_SIZE]; DbgPrint(dbg_ctl_cache_read, "CacheReadStartHead - read %s target %s - %s %d of %" PRId64 " bytes, %d fragments", doc->key.toHexStr(xt), key.toHexStr(yt), f.single_fragment ? "single" : "multi", doc->len, doc->total_len, diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc index b5207c12bb8..5df8cda6686 100644 --- a/iocore/cache/CacheWrite.cc +++ b/iocore/cache/CacheWrite.cc @@ -1175,7 +1175,7 @@ CacheVC::openWriteCloseDir(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED * dir_delete(&earliest_key, vol, &earliest_dir); } } - if (is_dbg_ctl_enabled(dbg_ctl_cache_update)) { + if (dbg_ctl_cache_update.on()) { if (f.update && closed > 0) { if (!total_len && !f.allow_empty_doc && alternate_index != CACHE_ALT_REMOVED) { Dbg(dbg_ctl_cache_update, "header only %d (%" PRIu64 ", %" PRIu64 ")", DIR_MASK_TAG(first_key.slice32(2)), update_key.b[0], diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc index 7d13ba5cace..fb710acb9ed 100644 --- a/iocore/dns/DNS.cc +++ b/iocore/dns/DNS.cc @@ -1412,7 +1412,7 @@ dns_result(DNSHandler *h, DNSEntry *e, HostEnt *ent, bool retry, bool tcp_retry) h->release_query_id(i); } - if (is_dbg_ctl_enabled(dbg_ctl_dns)) { + if (dbg_ctl_dns.on()) { if (is_addr_query(e->qtype)) { ip_text_buffer buff; const char *ptr = ""; @@ -1753,7 +1753,7 @@ dns_process(DNSHandler *handler, HostEnt *buf, int len) ink_strlcpy(reinterpret_cast(bp), reinterpret_cast(tbuf), buflen); bp += n; buflen -= n; - if (is_dbg_ctl_enabled(dbg_ctl_dns)) { + if (dbg_ctl_dns.on()) { switch (type) { case T_CNAME: DbgPrint(dbg_ctl_dns, "received cname = %s", tbuf); diff --git a/iocore/dns/P_DNSProcessor.h b/iocore/dns/P_DNSProcessor.h index 64b51b507aa..12976842f38 100644 --- a/iocore/dns/P_DNSProcessor.h +++ b/iocore/dns/P_DNSProcessor.h @@ -206,7 +206,7 @@ struct DNSHandler : public Continuation { bool failover_now(int i) { - if (is_dbg_ctl_enabled(_dbg_ctl_dns)) { + if (_dbg_ctl_dns.on()) { DbgPrint(_dbg_ctl_dns, "failover_now: Considering immediate failover, target time is %" PRId64 "", (ink_hrtime)HRTIME_SECONDS(dns_failover_period)); DbgPrint(_dbg_ctl_dns, "\tdelta time is %" PRId64 "", (ink_get_hrtime() - crossed_failover_number[i])); diff --git a/iocore/dns/SplitDNS.cc b/iocore/dns/SplitDNS.cc index ee0c124ca6a..5ea23af08eb 100644 --- a/iocore/dns/SplitDNS.cc +++ b/iocore/dns/SplitDNS.cc @@ -160,7 +160,7 @@ SplitDNSConfig::reconfigure() m_id = configProcessor.set(m_id, params); - if (is_dbg_ctl_enabled(dbg_ctl_splitdns_config)) { + if (dbg_ctl_splitdns_config.on()) { SplitDNSConfig::print(); } @@ -274,7 +274,7 @@ SplitDNS::findServer(RequestData *rdata, SplitDNSResult *result) result->r = DNS_SRVR_SPECIFIED; } - if (is_dbg_ctl_enabled(dbg_ctl_splitdns_config)) { + if (dbg_ctl_splitdns_config.on()) { const char *host = rdata->get_host(); switch (result->r) { diff --git a/iocore/net/SSLDiags.cc b/iocore/net/SSLDiags.cc index 5f0874fbc6e..cd75e1bcf64 100644 --- a/iocore/net/SSLDiags.cc +++ b/iocore/net/SSLDiags.cc @@ -147,9 +147,9 @@ SSLDiagnostic(const SourceLocation &loc, bool debug, SSLNetVConnection *vc, cons while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) { #endif if (debug) { - if (diags()->on(ssl_diags_dbg_ctl)) { - diags()->print(ssl_diags_dbg_ctl.ptr()->tag, DL_Debug, &loc, "SSL::%lu:%s:%s:%d%s%s%s%s", es, ERR_error_string(l, buf), - file, line, (flags & ERR_TXT_STRING) ? ":" : "", (flags & ERR_TXT_STRING) ? data : "", + if (ssl_diags_dbg_ctl.on()) { + diags()->print(ssl_diags_dbg_ctl.tag(), DL_Debug, &loc, "SSL::%lu:%s:%s:%d%s%s%s%s", es, ERR_error_string(l, buf), file, + line, (flags & ERR_TXT_STRING) ? ":" : "", (flags & ERR_TXT_STRING) ? data : "", vc ? ": peer address is " : "", ip_buf); } } else { @@ -172,8 +172,8 @@ SSLDiagnostic(const SourceLocation &loc, bool debug, SSLNetVConnection *vc, cons va_start(ap, fmt); if (debug) { - if (diags()->on(ssl_diags_dbg_ctl)) { - diags()->print_va(ssl_diags_dbg_ctl.ptr()->tag, DL_Debug, &loc, fmt, ap); + if (ssl_diags_dbg_ctl.on()) { + diags()->print_va(ssl_diags_dbg_ctl.tag(), DL_Debug, &loc, fmt, ap); } } else { diags()->error_va(DL_Error, &loc, fmt, ap); diff --git a/iocore/net/SSLUtils.cc b/iocore/net/SSLUtils.cc index b8fcce664a0..d902c88368c 100644 --- a/iocore/net/SSLUtils.cc +++ b/iocore/net/SSLUtils.cc @@ -216,7 +216,7 @@ ssl_new_cached_session(SSL *ssl, SSL_SESSION *sess) if (diags()->on()) { static DbgCtl dbg_ctl("ssl_session_cache.insert"); - if (dbg_ctl.ptr()->on) { + if (dbg_ctl.tag_on()) { char printable_buf[(len * 2) + 1]; sid.toString(printable_buf, sizeof(printable_buf)); @@ -259,7 +259,7 @@ ssl_rm_cached_session(SSL_CTX *ctx, SSL_SESSION *sess) if (diags()->on()) { static DbgCtl dbg_ctl("ssl_session_cache.remove"); - if (dbg_ctl.ptr()->on) { + if (dbg_ctl.tag_on()) { char printable_buf[(len * 2) + 1]; sid.toString(printable_buf, sizeof(printable_buf)); DbgPrint(dbg_ctl, "ssl_rm_cached_session cached session '%s'", printable_buf); diff --git a/iocore/net/TLSSessionResumptionSupport.cc b/iocore/net/TLSSessionResumptionSupport.cc index 9ed2a50f770..b4900f25252 100644 --- a/iocore/net/TLSSessionResumptionSupport.cc +++ b/iocore/net/TLSSessionResumptionSupport.cc @@ -143,7 +143,7 @@ TLSSessionResumptionSupport::getSession(SSL *ssl, const unsigned char *id, int l *copy = 0; if (diags()->on()) { static DbgCtl dbg_ctl("ssl.session_cache.get"); - if (dbg_ctl.ptr()->on) { + if (dbg_ctl.tag_on()) { char printable_buf[(len * 2) + 1]; sid.toString(printable_buf, sizeof(printable_buf)); DbgPrint(dbg_ctl, "ssl_get_cached_session cached session '%s' context %p", printable_buf, SSL_get_SSL_CTX(ssl)); diff --git a/plugins/experimental/webp_transform/ImageTransform.cc b/plugins/experimental/webp_transform/ImageTransform.cc index 7dc81700bfc..a8ef0bd6ed3 100644 --- a/plugins/experimental/webp_transform/ImageTransform.cc +++ b/plugins/experimental/webp_transform/ImageTransform.cc @@ -49,7 +49,7 @@ namespace { GlobalPlugin *plugin; -auto webp_dbg_ctl = TSDbgCtlCreate(TAG); +DbgCtl webp_dbg_ctl{TAG}; enum class ImageEncoding { webp, jpeg, png, unknown }; @@ -114,11 +114,11 @@ class ImageTransform : public TransformationPlugin Blob output_blob; if (_transform_image_type == ImageEncoding::webp) { stat_convert_to_webp.increment(1); - TSDbg(webp_dbg_ctl, "Transforming jpeg or png to webp"); + Dbg(webp_dbg_ctl, "Transforming jpeg or png to webp"); image.magick("WEBP"); } else { stat_convert_to_jpeg.increment(1); - TSDbg(webp_dbg_ctl, "Transforming webp to jpeg"); + Dbg(webp_dbg_ctl, "Transforming webp to jpeg"); image.magick("JPEG"); } image.write(&output_blob); @@ -181,23 +181,23 @@ class GlobalHookPlugin : public GlobalPlugin } } - TSDbg(webp_dbg_ctl, "Content-Type: %s transaction_convert_to_webp: %d transaction_convert_to_jpeg: %d", ctype.c_str(), - transaction_convert_to_webp, transaction_convert_to_jpeg); + Dbg(webp_dbg_ctl, "Content-Type: %s transaction_convert_to_webp: %d transaction_convert_to_jpeg: %d", ctype.c_str(), + transaction_convert_to_webp, transaction_convert_to_jpeg); // If we might need to convert check to see if what the browser supports if (transaction_convert_to_webp == true || transaction_convert_to_jpeg == true) { std::string accept = transaction.getServerRequest().getHeaders().values("Accept"); bool webp_supported = accept.find("image/webp") != std::string::npos; - TSDbg(webp_dbg_ctl, "Accept: %s webp_suppported: %d", accept.c_str(), webp_supported); + Dbg(webp_dbg_ctl, "Accept: %s webp_suppported: %d", accept.c_str(), webp_supported); if (webp_supported == true && transaction_convert_to_webp == true) { - TSDbg(webp_dbg_ctl, "Content type is either jpeg or png. Converting to webp"); + Dbg(webp_dbg_ctl, "Content type is either jpeg or png. Converting to webp"); transaction.addPlugin(new ImageTransform(transaction, input_image_type, ImageEncoding::webp)); } else if (webp_supported == false && transaction_convert_to_jpeg == true) { - TSDbg(webp_dbg_ctl, "Content type is webp. Converting to jpeg"); + Dbg(webp_dbg_ctl, "Content type is webp. Converting to jpeg"); transaction.addPlugin(new ImageTransform(transaction, input_image_type, ImageEncoding::jpeg)); } else { - TSDbg(webp_dbg_ctl, "Nothing to convert"); + Dbg(webp_dbg_ctl, "Nothing to convert"); } } @@ -215,18 +215,18 @@ TSPluginInit(int argc, const char *argv[]) if (argc >= 2) { std::string option(argv[1]); if (option.find("convert_to_webp") != std::string::npos) { - TSDbg(webp_dbg_ctl, "Configured to convert to webp"); + Dbg(webp_dbg_ctl, "Configured to convert to webp"); config_convert_to_webp = true; } if (option.find("convert_to_jpeg") != std::string::npos) { - TSDbg(webp_dbg_ctl, "Configured to convert to jpeg"); + Dbg(webp_dbg_ctl, "Configured to convert to jpeg"); config_convert_to_jpeg = true; } if (config_convert_to_webp == false && config_convert_to_jpeg == false) { TSError("Unknown option: %s", option.c_str()); } } else { - TSDbg(webp_dbg_ctl, "Default configuration is to convert both webp and jpeg"); + Dbg(webp_dbg_ctl, "Default configuration is to convert both webp and jpeg"); config_convert_to_webp = true; config_convert_to_jpeg = true; } diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index a8830cc2bad..63cfe71d0cf 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -7469,16 +7469,6 @@ tsapi::c::TSDebug(const char *tag, const char *format_str, ...) } } -void -tsapi::c::_TSDbg(const char *tag, const char *format_str, ...) -{ - va_list ap; - - va_start(ap, format_str); - diags()->print_va(tag, DL_Diag, nullptr, format_str, ap); - va_end(ap); -} - /************************** Logging API ****************************/ TSReturnCode @@ -10023,23 +10013,6 @@ tsapi::c::TSHttpTxnPostBufferReaderGet(TSHttpTxn txnp) return (TSIOBufferReader)sm->get_postbuf_clone_reader(); } -tsapi::c::TSDbgCtl const * -tsapi::c::TSDbgCtlCreate(char const *tag) -{ - sdk_assert(tag != nullptr); - sdk_assert(*tag != '\0'); - - return DbgCtl::_new_reference(tag); -} - -void -tsapi::c::TSDbgCtlDestroy(TSDbgCtl const *dbg_ctl) -{ - sdk_assert(dbg_ctl != nullptr); - - DbgCtl::_rm_reference(); -} - namespace rpc { extern std::mutex g_rpcHandlingMutex; diff --git a/src/tscore/DbgCtl.cc b/src/tscore/DbgCtl.cc index 9a8dcaf4693..8ae652eb20b 100644 --- a/src/tscore/DbgCtl.cc +++ b/src/tscore/DbgCtl.cc @@ -22,11 +22,10 @@ */ #include -#include +#include #include #include - -#include "swoc/bwf_ip.h" +#include #include #include @@ -39,19 +38,19 @@ class DbgCtl::_RegistryAccessor private: struct TagCmp { bool - operator()(TSDbgCtl const &a, TSDbgCtl const &b) const + operator()(char const *a, char const *b) const { - return std::strcmp(a.tag, b.tag) < 0; + return std::strcmp(a, b) < 0; } }; public: - using Set = std::set; + using Map = std::map; class Registry { public: - Set set; + Map map; private: Registry() = default; @@ -60,8 +59,8 @@ class DbgCtl::_RegistryAccessor // ~Registry() { - for (auto &ctl : set) { - delete[] ctl.tag; + for (auto &elem : map) { + delete[] elem.first; } _mtx.unlock(); } @@ -121,15 +120,11 @@ class DbgCtl::_RegistryAccessor inline static std::atomic _registry_instance{nullptr}; }; -TSDbgCtl const * +DbgCtl::_TagData const * DbgCtl::_new_reference(char const *tag) { ink_assert(tag != nullptr); - TSDbgCtl ctl; - - ctl.tag = tag; - // DbgCtl instances may be declared as static objects in the destructors of objects not destoyed till program exit. // So, we must handle the case where the construction of such instances of DbgCtl overlaps with the destruction of // other instances of DbgCtl. That is why it is important to make sure the reference count is non-zero before @@ -142,7 +137,7 @@ DbgCtl::_new_reference(char const *tag) auto &d{ra.data()}; - if (auto it = d.set.find(ctl); it != d.set.end()) { + if (auto it = d.map.find(tag); it != d.map.end()) { return &*it; } @@ -150,14 +145,11 @@ DbgCtl::_new_reference(char const *tag) ink_assert(sz > 0); - { - char *t = new char[sz + 1]; // Deleted by ~Registry(). - std::memcpy(t, tag, sz + 1); - ctl.tag = t; - } - ctl.on = diags() && diags()->tag_activated(tag, DiagsTagType_Debug); + char *t = new char[sz + 1]; // Deleted by ~Registry(). + std::memcpy(t, tag, sz + 1); + _TagData new_elem{t, diags() && diags()->tag_activated(tag, DiagsTagType_Debug)}; - auto res = d.set.insert(ctl); + auto res = d.map.insert(new_elem); ink_assert(res.second); @@ -191,7 +183,25 @@ DbgCtl::update() auto &d{ra.data()}; - for (auto &i : d.set) { - const_cast(i.on) = diags()->tag_activated(i.tag, DiagsTagType_Debug); + for (auto &i : d.map) { + i.second = diags()->tag_activated(i.first, DiagsTagType_Debug); } } + +void +DbgCtl::print(char const *tag, char const *file, char const *function, int line, char const *fmt_str, ...) +{ + SourceLocation src_loc{file, function, line}; + va_list args; + va_start(args, fmt_str); + diags()->print_va(tag, DL_Diag, &src_loc, fmt_str, args); + va_end(args); +} + +std::atomic DbgCtl::_config_mode{0}; + +bool +DbgCtl::_override_global_on() +{ + return diags()->get_override(); +} diff --git a/src/tscore/Diags.cc b/src/tscore/Diags.cc index 1e9b7f825dc..fa4646d62ab 100644 --- a/src/tscore/Diags.cc +++ b/src/tscore/Diags.cc @@ -45,10 +45,10 @@ #include "tscore/ink_thread.h" #include "tscore/Regression.h" #include "tscore/Diags.h" +#include "ts/ts.h" -int tsapi::c::diags_on_for_plugins = 0; -bool tsapi::c::TSDbgCtlDetail::debug_on = false; -int DiagsConfigState::_enabled[2] = {0, 0}; +int tsapi::c::diags_on_for_plugins = 0; +int DiagsConfigState::_enabled[2] = {0, 0}; using namespace swoc::literals; @@ -61,8 +61,8 @@ DiagsConfigState::enabled(DiagsTagType dtt, int new_value) _enabled[dtt] = new_value; if (DiagsTagType_Debug == dtt) { - diags_on_for_plugins = 1 == new_value; - TSDbgCtlDetail::debug_on = (1 & new_value) != 0; + DbgCtl::_config_mode.store(new_value, std::memory_order_relaxed); + diags_on_for_plugins = (1 & new_value) != 0; } } diff --git a/tests/gold_tests/pluginTest/TSVConnFd/TSVConnFd.cc b/tests/gold_tests/pluginTest/TSVConnFd/TSVConnFd.cc index c1d1a8eb865..798fa376eef 100644 --- a/tests/gold_tests/pluginTest/TSVConnFd/TSVConnFd.cc +++ b/tests/gold_tests/pluginTest/TSVConnFd/TSVConnFd.cc @@ -32,7 +32,6 @@ #include using atscppapi::TSContUniqPtr; -using atscppapi::TSDbgCtlUniqPtr; /* Plugin for testing TSVConnFdCreate(). @@ -446,8 +445,7 @@ Send_to_vconn::_cont_func(TSCont cont, TSEvent event, void *edata) return 0; } -TSDbgCtlUniqPtr dbg_ctl_guard{TSDbgCtlCreate(PIName)}; -TSDbgCtl const *const dbg_ctl{dbg_ctl_guard.get()}; +DbgCtl dbg_ctl{PIName}; // Delete file whose path is specified in the constructor when the instance is destroyed. // @@ -490,8 +488,8 @@ class Ramp_test : private Send_to_vconn int n_bytes_recv) : Send_to_vconn{vconn_, n_groups_send * n_group_bytes}, Recv_from_vconn(vconn_), _f_del{f_del} { - TSDbg(dbg_ctl, "n_groups_send=%d n_group_bytes=%d allow_send_error=%c, n_bytes_recv=%d inst=%p", n_groups_send, n_group_bytes, - allow_send_error ? 'T' : 'F', n_bytes_recv, this); + Dbg(dbg_ctl, "n_groups_send=%d n_group_bytes=%d allow_send_error=%c, n_bytes_recv=%d inst=%p", n_groups_send, n_group_bytes, + allow_send_error ? 'T' : 'F', n_bytes_recv, this); TSReleaseAssert(n_groups_send >= 0); TSReleaseAssert(n_group_bytes >= 0); @@ -582,8 +580,8 @@ void Ramp_test::_Send_recv::_notify_send_to_vconn() { auto st = status(); - if (TSIsDbgCtlSet(dbg_ctl) && (st != Send_to_vconn::IN_PROGRESS)) { - TSDbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_send_to_vconn: status=%d inst=%p", int(st), this); + if (dbg_ctl.on() && (st != Send_to_vconn::IN_PROGRESS)) { + DbgPrint(dbg_ctl, "Ramp_test::_Send_recv::_notify_send_to_vconn: status=%d inst=%p", int(st), this); } switch (st) { case Send_to_vconn::IN_PROGRESS: { @@ -596,7 +594,7 @@ Ramp_test::_Send_recv::_notify_send_to_vconn() _send(_s.buf.data(), _s.n_group_bytes); } else { - TSDbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_send_to_vconn: done inst=%p", this); + Dbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_send_to_vconn: done inst=%p", this); _done(mtx()); } } break; @@ -607,8 +605,8 @@ Ramp_test::_Send_recv::_notify_send_to_vconn() case Send_to_vconn::ERROR: if (_s.allow_error) { - TSDbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_send_to_vconn: error event: %d, inst=%p (error expected)", int(error_event()), - this); + Dbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_send_to_vconn: error event: %d, inst=%p (error expected)", int(error_event()), + this); } else { TSFatal(PINAME ": Ramp_test::_Send_recv::_notify_send_to_vconn: error event: %d, inst=%p", int(error_event()), this); @@ -624,8 +622,8 @@ void Ramp_test::_Send_recv::_notify_recv_from_vconn() { auto st = Recv_from_vconn::_status(); - if (TSIsDbgCtlSet(dbg_ctl) && (st != Recv_from_vconn::IN_PROGRESS)) { - TSDbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_recv_from_vconn: status=%d inst=%p", int(st), this); + if (dbg_ctl.on() && (st != Recv_from_vconn::IN_PROGRESS)) { + DbgPrint(dbg_ctl, "Ramp_test::_Send_recv::_notify_recv_from_vconn: status=%d inst=%p", int(st), this); } switch (st) { case Recv_from_vconn::IN_PROGRESS: { @@ -649,7 +647,7 @@ Ramp_test::_Send_recv::_notify_recv_from_vconn() } } if (!_r.n_bytes_remaining) { - TSDbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_recv_from_vconn: done inst=%p", this); + Dbg(dbg_ctl, "Ramp_test::_Send_recv::_notify_recv_from_vconn: done inst=%p", this); _done(mtx()); } } break; @@ -811,7 +809,7 @@ TSContUniqPtr global_cont; void TSPluginInit(int n_arg, char const *arg[]) { - TSDbg(dbg_ctl, "initializing plugin"); + Dbg(dbg_ctl, "initializing plugin"); TSPluginRegistrationInfo info; @@ -823,7 +821,7 @@ TSPluginInit(int n_arg, char const *arg[]) TSError(PINAME ": failure calling TSPluginRegister."); return; } else { - TSDbg(dbg_ctl, "Plugin registration succeeded."); + Dbg(dbg_ctl, "Plugin registration succeeded."); } global_cont.reset(nonNullPtrRel(TSContCreate(global_cont_func, nullptr))); @@ -847,12 +845,12 @@ TSPluginInit(int n_arg, char const *arg[]) listen_addr.sin_family = AF_INET; for (int i{0};; ++i) { - TSDbg(dbg_ctl, "bind() with TCP port %d", loopback_port); + Dbg(dbg_ctl, "bind() with TCP port %d", loopback_port); int ret = bind(listen_fd, reinterpret_cast(&listen_addr), sizeof(listen_addr)); if (ret >= 0) { break; } - TSDbg(dbg_ctl, "bind() failed: errno=%d", errno); + Dbg(dbg_ctl, "bind() failed: errno=%d", errno); TSReleaseAssert(i < 100); ++loopback_port; listen_addr.sin_port = htons(loopback_port); diff --git a/tests/gold_tests/pluginTest/polite_hook_wait/polite_hook_wait.cc b/tests/gold_tests/pluginTest/polite_hook_wait/polite_hook_wait.cc index 6676572388d..2b15e1d5b31 100644 --- a/tests/gold_tests/pluginTest/polite_hook_wait/polite_hook_wait.cc +++ b/tests/gold_tests/pluginTest/polite_hook_wait/polite_hook_wait.cc @@ -40,8 +40,7 @@ namespace { char PIName[] = PINAME; -atscppapi::TSDbgCtlUniqPtr dbg_ctl_guard{TSDbgCtlCreate(PIName)}; -TSDbgCtl const *const dbg_ctl{dbg_ctl_guard.get()}; +DbgCtl dbg_ctl{PINAME}; enum Test_step { BEGIN, GLOBAL_CONT_READ_HDRS, THREAD, TXN_CONT_READ_HDRS, END }; @@ -94,7 +93,7 @@ next_step(int curr) curr = BEGIN; } - TSDbg(dbg_ctl, "Entering test step %s", step_cstr(curr)); + Dbg(dbg_ctl, "Entering test step %s", step_cstr(curr)); test_step.store(curr, std::memory_order_relaxed); } @@ -113,7 +112,7 @@ class Blocking_action // TSThreadWait(_checker.get()); - TSDbg(dbg_ctl, "In ~Blocking_action()"); + Dbg(dbg_ctl, "In ~Blocking_action()"); } Blocking_action() = default; @@ -146,7 +145,7 @@ Blocking_action::init() int Blocking_action::_global_cont_func(TSCont, TSEvent event, void *eventData) { - TSDbg(dbg_ctl, "entering _global_cont_func()"); + Dbg(dbg_ctl, "entering _global_cont_func()"); TSReleaseAssert(eventData != nullptr); @@ -245,7 +244,7 @@ Blocking_action::_txn_cont_func(TSCont, TSEvent event, void *eventData) void TSPluginInit(int n_arg, char const *arg[]) { - TSDbg(dbg_ctl, "initializing plugin"); + Dbg(dbg_ctl, "initializing plugin"); TSPluginRegistrationInfo info; @@ -257,7 +256,7 @@ TSPluginInit(int n_arg, char const *arg[]) TSError(PINAME ": failure calling TSPluginRegister."); return; } else { - TSDbg(dbg_ctl, "Plugin registration succeeded."); + Dbg(dbg_ctl, "Plugin registration succeeded."); } AuxDataMgr::init(PIName); diff --git a/tests/gold_tests/pluginTest/tsapi/test_tsapi.cc b/tests/gold_tests/pluginTest/tsapi/test_tsapi.cc index bb895beae75..1123a3bc02c 100644 --- a/tests/gold_tests/pluginTest/tsapi/test_tsapi.cc +++ b/tests/gold_tests/pluginTest/tsapi/test_tsapi.cc @@ -41,11 +41,8 @@ namespace { char PIName[] = PINAME; -atscppapi::TSDbgCtlUniqPtr dbg_ctl_guard{TSDbgCtlCreate(PIName)}; -TSDbgCtl const *const dbg_ctl{dbg_ctl_guard.get()}; - -atscppapi::TSDbgCtlUniqPtr off_dbg_ctl_guard{TSDbgCtlCreate("yada-yada-yada")}; -TSDbgCtl const *const off_dbg_ctl{off_dbg_ctl_guard.get()}; +DbgCtl dbg_ctl{PIName}; +DbgCtl off_dbg_ctl{"yada-yada-yada"}; // NOTE: It's important to flush this after writing so that a gold test using this plugin can examine the log before TS // terminates. @@ -179,11 +176,11 @@ transactionContFunc(TSCont, TSEvent event, void *eventData) { logFile << "Transaction: event=" << TSHttpEventNameLookup(event) << std::endl; - TSDbg(dbg_ctl, "Transaction: event=%s(%d) eventData=%p", TSHttpEventNameLookup(event), event, eventData); + Dbg(dbg_ctl, "Transaction: event=%s(%d) eventData=%p", TSHttpEventNameLookup(event), event, eventData); TSDebug(PIName, "Should not see this, enabled set to 3"); - TSDbg(off_dbg_ctl, "Should not see this, tag does not match regular expression"); + Dbg(off_dbg_ctl, "Should not see this, tag does not match regular expression"); switch (event) { case TS_EVENT_HTTP_READ_REQUEST_HDR: { @@ -216,7 +213,7 @@ globalContFunc(TSCont, TSEvent event, void *eventData) { logFile << "Global: event=" << TSHttpEventNameLookup(event) << std::endl; - TSDbg(dbg_ctl, "Global: event=%s(%d) eventData=%p", TSHttpEventNameLookup(event), event, eventData); + Dbg(dbg_ctl, "Global: event=%s(%d) eventData=%p", TSHttpEventNameLookup(event), event, eventData); switch (event) { case TS_EVENT_HTTP_TXN_START: { @@ -258,7 +255,7 @@ globalContFunc(TSCont, TSEvent event, void *eventData) TSReturnCode TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size) { - TSDbg(dbg_ctl, "TSRemapInit()"); + Dbg(dbg_ctl, "TSRemapInit()"); TSReleaseAssert(api_info && errbuf && errbuf_size); From a4827552901daeb99ba23ec7898298115ad856e0 Mon Sep 17 00:00:00 2001 From: Walt Karas Date: Thu, 24 Aug 2023 23:03:22 +0000 Subject: [PATCH 2/2] Fix clang-analyzer error. --- iocore/net/UnixUDPNet.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc index 6c7410adc1e..9b913183328 100644 --- a/iocore/net/UnixUDPNet.cc +++ b/iocore/net/UnixUDPNet.cc @@ -1672,6 +1672,7 @@ UDPQueue::SendMultipleUDPPackets(UDPPacket **p, uint16_t n) if (res > 0) { #ifdef SOL_UDP if (use_udp_gso) { + ink_assert(res <= n); Debug("udp-send", "Sent %d messages by processing %d UDPPackets (GSO)", res, n); } else { #endif