[sanitizer_common] Check 'demangle' flag in StripFunctionName and DemangleFunctionName

To allow getting the original stack trace.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D151411

GitOrigin-RevId: 215a742b8804f33c84f866d3c5aacd8d35129c49
diff --git a/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp b/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
index 337e2d6..2285ad8 100644
--- a/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
+++ b/lib/sanitizer_common/sanitizer_stacktrace_printer.cpp
@@ -11,12 +11,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "sanitizer_stacktrace_printer.h"
+
 #include "sanitizer_file.h"
+#include "sanitizer_flags.h"
 #include "sanitizer_fuchsia.h"
 
 namespace __sanitizer {
 
 const char *StripFunctionName(const char *function) {
+  if (!common_flags()->demangle)
+    return function;
   if (!function)
     return nullptr;
   auto try_strip = [function](const char *prefix) -> const char * {
@@ -39,7 +43,10 @@
 #if !SANITIZER_SYMBOLIZER_MARKUP
 
 static const char *DemangleFunctionName(const char *function) {
-  if (!function) return nullptr;
+  if (!common_flags()->demangle)
+    return function;
+  if (!function)
+    return nullptr;
 
   // NetBSD uses indirection for old threading functions for historical reasons
   // The mangled names are internal implementation detail and should not be