|
| 1 | +commit 445c6dd4845daf2fbc5e8e8b9bac6a39cd90a470 |
| 2 | +Author: partouf < [email protected]> |
| 3 | +Date: Sat Dec 10 14:07:08 2022 +0100 |
| 4 | + |
| 5 | + change dbgs() in case of --debug-to-stdout |
| 6 | + |
| 7 | +diff --git a/llvm/lib/Support/Debug.cpp b/llvm/lib/Support/Debug.cpp |
| 8 | +index 98a9ac4722b5..a04aabe67627 100644 |
| 9 | +--- a/llvm/lib/Support/Debug.cpp |
| 10 | ++++ b/llvm/lib/Support/Debug.cpp |
| 11 | +@@ -78,6 +78,11 @@ void setCurrentDebugTypes(const char **Types, unsigned Count) { |
| 12 | + } |
| 13 | + } // namespace llvm |
| 14 | + |
| 15 | ++cl::opt<bool> LogDebugToStdOut( |
| 16 | ++ "debug-to-stdout", |
| 17 | ++ llvm::cl::desc("Log debugging to stdout instead of stderr"), |
| 18 | ++ cl::init(false), cl::Hidden); |
| 19 | ++ |
| 20 | + // All Debug.h functionality is a no-op in NDEBUG mode. |
| 21 | + #ifndef NDEBUG |
| 22 | + |
| 23 | +@@ -161,23 +166,27 @@ static void debug_user_sig_handler(void *Cookie) { |
| 24 | + |
| 25 | + /// dbgs - Return a circular-buffered debug stream. |
| 26 | + raw_ostream &llvm::dbgs() { |
| 27 | +- // Do one-time initialization in a thread-safe way. |
| 28 | +- static struct dbgstream { |
| 29 | +- circular_raw_ostream strm; |
| 30 | +- |
| 31 | +- dbgstream() |
| 32 | +- : strm(errs(), "*** Debug Log Output ***\n", |
| 33 | +- (!EnableDebugBuffering || !DebugFlag) ? 0 : *DebugBufferSize) { |
| 34 | +- if (EnableDebugBuffering && DebugFlag && *DebugBufferSize != 0) |
| 35 | +- // TODO: Add a handler for SIGUSER1-type signals so the user can |
| 36 | +- // force a debug dump. |
| 37 | +- sys::AddSignalHandler(&debug_user_sig_handler, nullptr); |
| 38 | +- // Otherwise we've already set the debug stream buffer size to |
| 39 | +- // zero, disabling buffering so it will output directly to errs(). |
| 40 | +- } |
| 41 | +- } thestrm; |
| 42 | +- |
| 43 | +- return thestrm.strm; |
| 44 | ++ if (LogDebugToStdOut) { |
| 45 | ++ return outs(); |
| 46 | ++ } else { |
| 47 | ++ // Do one-time initialization in a thread-safe way. |
| 48 | ++ static struct dbgstream { |
| 49 | ++ circular_raw_ostream strm; |
| 50 | ++ |
| 51 | ++ dbgstream() |
| 52 | ++ : strm(errs(), "*** Debug Log Output ***\n", |
| 53 | ++ (!EnableDebugBuffering || !DebugFlag) ? 0 : *DebugBufferSize) { |
| 54 | ++ if (EnableDebugBuffering && DebugFlag && *DebugBufferSize != 0) |
| 55 | ++ // TODO: Add a handler for SIGUSER1-type signals so the user can |
| 56 | ++ // force a debug dump. |
| 57 | ++ sys::AddSignalHandler(&debug_user_sig_handler, nullptr); |
| 58 | ++ // Otherwise we've already set the debug stream buffer size to |
| 59 | ++ // zero, disabling buffering so it will output directly to errs(). |
| 60 | ++ } |
| 61 | ++ } thestrm; |
| 62 | ++ |
| 63 | ++ return thestrm.strm; |
| 64 | ++ } |
| 65 | + } |
| 66 | + |
| 67 | + #else |
| 68 | +@@ -185,7 +194,11 @@ raw_ostream &llvm::dbgs() { |
| 69 | + namespace llvm { |
| 70 | + /// dbgs - Return errs(). |
| 71 | + raw_ostream &dbgs() { |
| 72 | +- return errs(); |
| 73 | ++ if (LogDebugToStdOut) { |
| 74 | ++ return outs(); |
| 75 | ++ } else { |
| 76 | ++ return errs(); |
| 77 | ++ } |
| 78 | + } |
| 79 | + } |
| 80 | + void llvm::initDebugOptions() {} |
0 commit comments