DWARF: allow enabling tracing at runtime

Introduce `logDWARF` and the associated environment variable
`LIBUNWIND_PRINT_DWARF` to trace the CFI instructions.

llvm-svn: 292722
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: c06f0cf88c7697fc015934a3629025934d5523e8
diff --git a/src/libunwind.cpp b/src/libunwind.cpp
index 6035449..3133e5a 100644
--- a/src/libunwind.cpp
+++ b/src/libunwind.cpp
@@ -371,5 +371,17 @@
   return log;
 }
 
+_LIBUNWIND_HIDDEN
+bool logDWARF() {
+  // do manual lock to avoid use of _cxa_guard_acquire or initializers
+  static bool checked = false;
+  static bool log = false;
+  if (!checked) {
+    log = (getenv("LIBUNWIND_PRINT_DWARF") != NULL);
+    checked = true;
+  }
+  return log;
+}
+
 #endif // NDEBUG