When LIBCLANG_CODE_COMPLETION_LOGGING is set in the environment, log code-completion command lines to stderr
llvm-svn: 109395
diff --git a/clang/tools/libclang/CIndexCodeCompletion.cpp b/clang/tools/libclang/CIndexCodeCompletion.cpp
index 277fadf..2df5241 100644
--- a/clang/tools/libclang/CIndexCodeCompletion.cpp
+++ b/clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -22,6 +22,8 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/System/Program.h"
+#include <cstdlib>
+#include <cstdio>
#ifdef UDP_CODE_COMPLETION_LOGGER
#include "clang/Basic/Version.h"
@@ -273,6 +275,8 @@
#endif
#endif
+ bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != 0;
+
// The indexer, which is mainly used to determine where diagnostics go.
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
@@ -348,6 +352,15 @@
argv.push_back(arg);
}
+ if (EnableLogging) {
+ std::string Log = ClangPath.str();
+ for (unsigned I = 0, N = argv.size(); I != N; ++I) {
+ Log += ' ';
+ Log += argv[I];
+ }
+ fprintf(stderr, "libclang (Code Completion): %s\n", Log.c_str());
+ }
+
// Add the null terminator.
argv.push_back(NULL);
@@ -363,6 +376,8 @@
llvm::sys::Path DiagnosticsFile(tmpResultsFileName);
TemporaryFiles.push_back(DiagnosticsFile);
+
+
// Invoke 'clang'.
llvm::sys::Path DevNull; // leave empty, causes redirection to /dev/null
// on Unix or NUL (Windows).