[libunwind] [libunwind] Introduce _LIBUNWIND_TRACE_DWARF_EVAL for increased baremetal friendliness (PR #72040)

Michael Kenzel via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 17:08:09 PST 2023


================
@@ -381,24 +381,22 @@ typename A::pint_t
 DwarfInstructions<A, R>::evaluateExpression(pint_t expression, A &addressSpace,
                                             const R &registers,
                                             pint_t initialStackValue) {
-  const bool log = false;
   pint_t p = expression;
   pint_t expressionEnd = expression + 20; // temp, until len read
   pint_t length = (pint_t)addressSpace.getULEB128(p, expressionEnd);
   expressionEnd = p + length;
-  if (log)
-    fprintf(stderr, "evaluateExpression(): length=%" PRIu64 "\n",
-            (uint64_t)length);
+  _LIBUNWIND_TRACE_DWARF_EVAL("evaluateExpression(): length=%" PRIu64 "\n",
+                              (uint64_t)length);
   pint_t stack[100];
   pint_t *sp = stack;
   *(++sp) = initialStackValue;
 
   while (p < expressionEnd) {
-    if (log) {
-      for (pint_t *t = sp; t > stack; --t) {
-        fprintf(stderr, "sp[] = 0x%" PRIx64 "\n", (uint64_t)(*t));
-      }
+#if _LIBUNWIND_TRACING_DWARF_EVAL
----------------
michael-kenzel wrote:

good question. I think it might be a good idea to completely remove `#include <stdio.h>` everywhere unless some logging is active. I can try to add that. Though maybe this should be a separate PR since I think if we do this, we should do this in the library as a whole? It seems to be included in a majority of the files. Though all those includes are kinda redundant since they all include `"config.h"` anyways, which already includes `<stdio.h>`. I guess we could just conditionally include `<stdio.h>` in `"config.h"` only when logging is active and remove the include everywhere else?

https://github.com/llvm/llvm-project/pull/72040


More information about the cfe-commits mailing list