Adapt ENGINE_REF_COUNT_DEBUG to the new generic trace API
authorRichard Levitte <levitte@openssl.org>
Thu, 13 Dec 2018 00:42:46 +0000 (01:42 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 6 Mar 2019 10:15:14 +0000 (11:15 +0100)
Co-authored-by: Dr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/8198)

crypto/engine/eng_int.h
crypto/trace.c
include/openssl/trace.h

index 7bb1d73680dfa19e5059430af983be725b84ff9f..d45617567cbfdebfebf2f002b9f58a0cf6f716fd 100644 (file)
 extern CRYPTO_RWLOCK *global_engine_lock;
 
 /*
- * If we compile with this symbol defined, then both reference counts in the
- * ENGINE structure will be monitored with a line of output on stderr for
- * each change. This prints the engine's pointer address (truncated to
- * unsigned int), "struct" or "funct" to indicate the reference type, the
- * before and after reference count, and the file:line-number pair. The
- * "engine_ref_debug" statements must come *after* the change.
+ * This prints the engine's pointer address (truncated to unsigned int),
+ * "struct" or "funct" to indicate the reference type, the before and after
+ * reference count, and the file:line-number pair. The "engine_ref_debug"
+ * statements must come *after* the change.
  */
-# ifdef ENGINE_REF_COUNT_DEBUG
-
-#  define engine_ref_debug(e, isfunct, diff) \
-        fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \
-                (unsigned int)(e), (isfunct ? "funct" : "struct"), \
-                ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \
-                ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
-                (OPENSSL_FILE), (OPENSSL_LINE))
-
-# else
-
-#  define engine_ref_debug(e, isfunct, diff)
-
-# endif
+# define engine_ref_debug(e, isfunct, diff)                             \
+    OSSL_TRACE6(ENGINE_REF_COUNT,                                       \
+               "engine: %p %s from %d to %d (%s:%d)\n",               \
+               (void *)(e), (isfunct ? "funct" : "struct"),             \
+               ((isfunct)                                               \
+                ? ((e)->funct_ref - (diff))                             \
+                : ((e)->struct_ref - (diff))),                          \
+               ((isfunct) ? (e)->funct_ref : (e)->struct_ref),          \
+               (OPENSSL_FILE), (OPENSSL_LINE))
 
 /*
  * Any code that will need cleanup operations should use these functions to
index 38ef7ae2328f13ae260e35fff7a1c1a1fcdb6c03..8e1db68190439496b6fd40bd36131ddd00381e1c 100644 (file)
@@ -125,6 +125,7 @@ static const struct trace_category_st trace_categories[] = {
     TRACE_CATEGORY_(TLS_CIPHER),
     TRACE_CATEGORY_(ENGINE_CONF),
     TRACE_CATEGORY_(ENGINE_TABLE),
+    TRACE_CATEGORY_(ENGINE_REF_COUNT),
 };
 
 const char *OSSL_trace_get_category_name(int num)
index 4dd9bb40804d3fbb247dd1c42c47006c10517d35..47da0d66a60b859224bd67cfdbfca328df9837ef 100644 (file)
@@ -38,7 +38,8 @@ extern "C" {
 # define OSSL_TRACE_CATEGORY_TLS_CIPHER          3
 # define OSSL_TRACE_CATEGORY_ENGINE_CONF         4
 # define OSSL_TRACE_CATEGORY_ENGINE_TABLE        5
-# define OSSL_TRACE_CATEGORY_NUM                 6
+# define OSSL_TRACE_CATEGORY_ENGINE_REF_COUNT    6
+# define OSSL_TRACE_CATEGORY_NUM                 7
 
 /* Returns the trace category number for the given |name| */
 int OSSL_trace_get_category_num(const char *name);