It's also worth pointing out that the method I've implemented here is a more general case of something already in LLDB. lldb_private::LogIfXXXCategoriesSet(). These 2 methods are equivalent to getting the log, checking for null, and logging if non null, except they always evaluate the arguments, as does my method. But the method I've implemented here allows access to every method of Log. Like Warn, Error, etc, so is even more flexible <br><div class="gmail_quote">On Wed, Apr 29, 2015 at 6:14 PM Enrico Granata <<a href="mailto:egranata@apple.com">egranata@apple.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>One possible avenue to fix the performance issue would be to have your log calls take a lambda expression that returns the string to be printed, e.g.</div><div><br></div><div><div>#include <functional></div><div>#include <string></div><div>#include <iostream></div><div>#include <stdlib.h></div><div><br></div><div>typedef std::function<std::string()> LogFunction;</div><div><br></div><div>void log(bool dolog, LogFunction f) {</div><div> if (dolog)</div><div> std::cout << f() << std::endl;</div><div>}</div><div><br></div><div>int main() {</div><div> log(true, [] () -> std::string { return "hello world"; } );</div><div> log(false, [] {sleep(10); return "hi"; });</div><div> return 0;</div><div>}</div><div><br></div><div>I don’t think the code gets much better doing this compared to the previous if (log) model we were using - but that’s at least arguable</div><div><br></div></div></div><div style="word-wrap:break-word"><br><blockquote type="cite">More importantly, I don't think this is a good change. I want to be able to freely put complex log statements where ever I need without having to worry about the performance implications. That was always possible, because the cost of not logging was checking if log was NULL.<br><br>With this change I'm always going to get back a log, so I'm always going to marshall the arguments, and do whatever work was going to go into printing, etc and then call a virtual function that does nothing with the results.<br><br>That seems undesirable to me. You could work around this by having any code that does logging in a loop or that has complex arguments check if the log is a null log and not do the work if it is, but then we're right back where we started except now we only do the check sometimes, making things even more confusing.<br><br>Jim<br><br></blockquote><blockquote type="cite">On Apr 29, 2015, at 4:30 PM, Sean Callanan <<a href="mailto:scallanan@apple.com" target="_blank">scallanan@apple.com</a>> wrote:<br><br>Zachary,<br><br>Log.cpp doesn’t build anymore with this change. In particular, you have<br>–<br>+ virtual void<br>+ VAPrintf(const char *format, va_list args);<br>–<br>but at several places VAPrintf is called with no va_list, e.g.,<br>–<br>void<br>-Log::Error (const char *format, ...)<br>+Log::Error(const char *format, ...)<br>{<br>- char *arg_msg = NULL;<br>+ char *arg_msg = nullptr;<br> va_list args;<br>- va_start (args, format);<br>- ::vasprintf (&arg_msg, format, args);<br>- va_end (args);<br>+ va_start(args, format);<br>+ ::vasprintf(&arg_msg, format, args);<br>+ va_end(args);<br><br>- if (arg_msg != NULL)<br>- {<br>- PrintfWithFlags (LLDB_LOG_FLAG_ERROR, "error: %s", arg_msg);<br>- free (arg_msg);<br>- }<br>+ if (arg_msg == nullptr)<br>+ return;<br>+<br>+ VAPrintf("error: %s", arg_msg);<br>+ free(arg_msg);<br>}<br>–<br>Do you have more commits coming that are going to resolve this problem?<br><br>Sean<br><br><br><blockquote type="cite">On Apr 29, 2015, at 3:55 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br><br>Author: zturner<br>Date: Wed Apr 29 17:55:28 2015<br>New Revision: 236174<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=236174&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=236174&view=rev</a><br>Log:<br>Introduce a NullLog class, which ignores all messages.<br><br>The purpose of this class is so that GetLogIfAllCategoriesSet<br>can always return an instance of some class, whether it be a real<br>logging class or a "null" class, which ignores messages. Code<br>that is littered with if statements that only log if the pointer<br>is non-null can get very unwieldy very quickly, so this should<br>help code readability in such circumstances.<br><br>Since I'm in this code anyway, I'm also deleting the<br>PrintfWithFlags methods, as well as all the flags, since they<br>appear to be dead code that have been superceded by newer<br>mechanisms and all the flags are simply ignored.<br><br>Added:<br> lldb/trunk/include/lldb/Core/NullLog.h<br> lldb/trunk/source/Core/NullLog.cpp<br>Modified:<br> lldb/trunk/include/lldb/Core/Log.h<br> lldb/trunk/source/Core/CMakeLists.txt<br> lldb/trunk/source/Core/Log.cpp<br><br>Modified: lldb/trunk/include/lldb/Core/Log.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Log.h?rev=236174&r1=236173&r2=236174&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Log.h?rev=236174&r1=236173&r2=236174&view=diff</a><br>==============================================================================<br>--- lldb/trunk/include/lldb/Core/Log.h (original)<br>+++ lldb/trunk/include/lldb/Core/Log.h Wed Apr 29 17:55:28 2015<br>@@ -26,17 +26,6 @@<br>#include "lldb/Core/PluginInterface.h"<br><br>//----------------------------------------------------------------------<br>-// Logging types<br>-//----------------------------------------------------------------------<br>-#define LLDB_LOG_FLAG_STDOUT (1u << 0)<br>-#define LLDB_LOG_FLAG_STDERR (1u << 1)<br>-#define LLDB_LOG_FLAG_FATAL (1u << 2)<br>-#define LLDB_LOG_FLAG_ERROR (1u << 3)<br>-#define LLDB_LOG_FLAG_WARNING (1u << 4)<br>-#define LLDB_LOG_FLAG_DEBUG (1u << 5)<br>-#define LLDB_LOG_FLAG_VERBOSE (1u << 6)<br>-<br>-//----------------------------------------------------------------------<br>// Logging Options<br>//----------------------------------------------------------------------<br>#define LLDB_LOG_OPTION_THREADSAFE (1u << 0)<br>@@ -61,12 +50,10 @@ public:<br> //------------------------------------------------------------------<br> // Callback definitions for abstracted plug-in log access.<br> //------------------------------------------------------------------<br>- typedef void (*DisableCallback) (const char **categories, Stream *feedback_strm);<br>- typedef Log * (*EnableCallback) (lldb::StreamSP &log_stream_sp,<br>- uint32_t log_options,<br>- const char **categories,<br>- Stream *feedback_strm);<br>- typedef void (*ListCategoriesCallback) (Stream *strm);<br>+ typedef void (*DisableCallback)(const char **categories, Stream *feedback_strm);<br>+ typedef Log *(*EnableCallback)(lldb::StreamSP &log_stream_sp, uint32_t log_options, const char **categories,<br>+ Stream *feedback_strm);<br>+ typedef void (*ListCategoriesCallback)(Stream *strm);<br><br> struct Callbacks<br> {<br>@@ -79,86 +66,78 @@ public:<br> // Static accessors for logging channels<br> //------------------------------------------------------------------<br> static void<br>- RegisterLogChannel (const ConstString &channel,<br>- const Log::Callbacks &log_callbacks);<br>+ RegisterLogChannel(const ConstString &channel, const Log::Callbacks &log_callbacks);<br><br> static bool<br>- UnregisterLogChannel (const ConstString &channel);<br>+ UnregisterLogChannel(const ConstString &channel);<br><br> static bool<br>- GetLogChannelCallbacks (const ConstString &channel,<br>- Log::Callbacks &log_callbacks);<br>-<br>+ GetLogChannelCallbacks(const ConstString &channel, Log::Callbacks &log_callbacks);<br><br> static void<br>- EnableAllLogChannels (lldb::StreamSP &log_stream_sp,<br>- uint32_t log_options,<br>- const char **categories,<br>- Stream *feedback_strm);<br>+ EnableAllLogChannels(lldb::StreamSP &log_stream_sp, uint32_t log_options, const char **categories,<br>+ Stream *feedback_strm);<br><br> static void<br>- DisableAllLogChannels (Stream *feedback_strm);<br>+ DisableAllLogChannels(Stream *feedback_strm);<br><br> static void<br>- ListAllLogChannels (Stream *strm);<br>+ ListAllLogChannels(Stream *strm);<br><br> static void<br>- Initialize ();<br>+ Initialize();<br><br> static void<br>- Terminate ();<br>- <br>+ Terminate();<br>+<br> //------------------------------------------------------------------<br> // Auto completion<br> //------------------------------------------------------------------<br> static void<br>- AutoCompleteChannelName (const char *channel_name, <br>- StringList &matches);<br>+ AutoCompleteChannelName(const char *channel_name, StringList &matches);<br><br> //------------------------------------------------------------------<br> // Member functions<br> //------------------------------------------------------------------<br>- Log ();<br>+ Log();<br><br>- Log (const lldb::StreamSP &stream_sp);<br>+ Log(const lldb::StreamSP &stream_sp);<br><br>- ~Log ();<br>-<br>- void<br>- PutCString (const char *cstr);<br>+ virtual<br>+ ~Log();<br><br>- void<br>- Printf (const char *format, ...) __attribute__ ((format (printf, 2, 3)));<br>+ virtual void<br>+ PutCString(const char *cstr);<br><br>- void<br>- VAPrintf (const char *format, va_list args);<br>+ virtual void<br>+ Printf(const char *format, ...) __attribute__((format(printf, 2, 3)));<br><br>- void<br>- PrintfWithFlags( uint32_t flags, const char *format, ...) __attribute__ ((format (printf, 3, 4)));<br>+ virtual void<br>+ VAPrintf(const char *format, va_list args);<br><br>- void<br>- LogIf (uint32_t mask, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));<br>+ virtual void<br>+ LogIf(uint32_t mask, const char *fmt, ...) __attribute__((format(printf, 3, 4)));<br><br>- void<br>- Debug (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));<br>+ virtual void<br>+ Debug(const char *fmt, ...) __attribute__((format(printf, 2, 3)));<br><br>- void<br>- DebugVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));<br>+ virtual void<br>+ DebugVerbose(const char *fmt, ...) __attribute__((format(printf, 2, 3)));<br><br>- void<br>- Error (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));<br>+ virtual void<br>+ Error(const char *fmt, ...) __attribute__((format(printf, 2, 3)));<br><br>- void<br>- FatalError (int err, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));<br>+ virtual void<br>+ FatalError(int err, const char *fmt, ...) __attribute__((format(printf, 3, 4)));<br><br>- void<br>- Verbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));<br>+ virtual void<br>+ Verbose(const char *fmt, ...) __attribute__((format(printf, 2, 3)));<br><br>- void<br>- Warning (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));<br>+ virtual void<br>+ Warning(const char *fmt, ...) __attribute__((format(printf, 2, 3)));<br><br>- void<br>- WarningVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));<br>+ virtual void<br>+ WarningVerbose(const char *fmt, ...) __attribute__((format(printf, 2, 3)));<br><br> Flags &<br> GetOptions();<br>@@ -179,7 +158,7 @@ public:<br> GetDebug() const;<br><br> void<br>- SetStream (const lldb::StreamSP &stream_sp)<br>+ SetStream(const lldb::StreamSP &stream_sp)<br> {<br> m_stream_sp = stream_sp;<br> }<br>@@ -192,43 +171,35 @@ protected:<br> Flags m_options;<br> Flags m_mask_bits;<br><br>- void<br>- PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args);<br>-<br>private:<br>- DISALLOW_COPY_AND_ASSIGN (Log);<br>+ DISALLOW_COPY_AND_ASSIGN(Log);<br>};<br><br><br>class LogChannel : public PluginInterface<br>{<br>public:<br>- LogChannel ();<br>+ LogChannel();<br><br>- virtual<br>- ~LogChannel ();<br>+ virtual ~LogChannel();<br><br>- static lldb::LogChannelSP<br>- FindPlugin (const char *plugin_name);<br>+ static lldb::LogChannelSP FindPlugin(const char *plugin_name);<br><br> // categories is a an array of chars that ends with a NULL element.<br>- virtual void<br>- Disable (const char **categories, Stream *feedback_strm) = 0;<br>+ virtual void Disable(const char **categories, Stream *feedback_strm) = 0;<br><br>- virtual bool<br>- Enable (lldb::StreamSP &log_stream_sp,<br>- uint32_t log_options,<br>- Stream *feedback_strm, // Feedback stream for argument errors etc<br>- const char **categories) = 0;// The categories to enable within this logging stream, if empty, enable default set<br>+ virtual bool Enable(<br>+ lldb::StreamSP &log_stream_sp, uint32_t log_options,<br>+ Stream *feedback_strm, // Feedback stream for argument errors etc<br>+ const char **categories) = 0; // The categories to enable within this logging stream, if empty, enable default set<br><br>- virtual void<br>- ListCategories (Stream *strm) = 0;<br>+ virtual void ListCategories(Stream *strm) = 0;<br><br>protected:<br> std::unique_ptr<Log> m_log_ap;<br><br>private:<br>- DISALLOW_COPY_AND_ASSIGN (LogChannel);<br>+ DISALLOW_COPY_AND_ASSIGN(LogChannel);<br>};<br><br><br><br>Added: lldb/trunk/include/lldb/Core/NullLog.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/NullLog.h?rev=236174&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/NullLog.h?rev=236174&view=auto</a><br>==============================================================================<br>--- lldb/trunk/include/lldb/Core/NullLog.h (added)<br>+++ lldb/trunk/include/lldb/Core/NullLog.h Wed Apr 29 17:55:28 2015<br>@@ -0,0 +1,58 @@<br>+//===-- NullLog.h -----------------------------------------------*- C++ -*-===//<br>+//<br>+// The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+<br>+#ifndef liblldb_Core_NullLog_H_<br>+#define liblldb_Core_NullLog_H_<br>+<br>+#include "lldb/Core/Log.h"<br>+<br>+//----------------------------------------------------------------------<br>+// Logging Functions<br>+//----------------------------------------------------------------------<br>+namespace lldb_private<br>+{<br>+<br>+class NullLog : public Log<br>+{<br>+ NullLog(NullLog &) = delete;<br>+ NullLog &operator=(NullLog &) = delete;<br>+<br>+ public:<br>+ //------------------------------------------------------------------<br>+ // Member functions<br>+ //------------------------------------------------------------------<br>+ NullLog();<br>+ ~NullLog();<br>+<br>+ void PutCString(const char *cstr) override;<br>+<br>+ void Printf(const char *format, ...) override __attribute__((format(printf, 2, 3)));<br>+<br>+ void VAPrintf(const char *format, va_list args) override;<br>+<br>+ void LogIf(uint32_t mask, const char *fmt, ...) override __attribute__((format(printf, 3, 4)));<br>+<br>+ void Debug(const char *fmt, ...) override __attribute__((format(printf, 2, 3)));<br>+<br>+ void DebugVerbose(const char *fmt, ...) override __attribute__((format(printf, 2, 3)));<br>+<br>+ void Error(const char *fmt, ...) override __attribute__((format(printf, 2, 3)));<br>+<br>+ void FatalError(int err, const char *fmt, ...) override __attribute__((format(printf, 3, 4)));<br>+<br>+ void Verbose(const char *fmt, ...) override __attribute__((format(printf, 2, 3)));<br>+<br>+ void Warning(const char *fmt, ...) override __attribute__((format(printf, 2, 3)));<br>+<br>+ void WarningVerbose(const char *fmt, ...) override __attribute__((format(printf, 2, 3)));<br>+};<br>+<br>+} // namespace lldb_private<br>+<br>+#endif // liblldb_Core_NullLog_H_<br><br>Modified: lldb/trunk/source/Core/CMakeLists.txt<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CMakeLists.txt?rev=236174&r1=236173&r2=236174&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/CMakeLists.txt?rev=236174&r1=236173&r2=236174&view=diff</a><br>==============================================================================<br>--- lldb/trunk/source/Core/CMakeLists.txt (original)<br>+++ lldb/trunk/source/Core/CMakeLists.txt Wed Apr 29 17:55:28 2015<br>@@ -38,6 +38,7 @@ add_lldb_library(lldbCore<br>Module.cpp<br>ModuleChild.cpp<br>ModuleList.cpp<br>+ NullLog.cpp<br>Opcode.cpp<br>PluginManager.cpp<br>RegisterValue.cpp<br><br>Modified: lldb/trunk/source/Core/Log.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Log.cpp?rev=236174&r1=236173&r2=236174&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Log.cpp?rev=236174&r1=236173&r2=236174&view=diff</a><br>==============================================================================<br>--- lldb/trunk/source/Core/Log.cpp (original)<br>+++ lldb/trunk/source/Core/Log.cpp Wed Apr 29 17:55:28 2015<br>@@ -77,6 +77,23 @@ Log::GetMask() const<br> return m_mask_bits;<br>}<br><br>+void<br>+Log::PutCString(const char *cstr)<br>+{<br>+ Printf("%s", cstr);<br>+}<br>+<br>+//----------------------------------------------------------------------<br>+// Simple variable argument logging with flags.<br>+//----------------------------------------------------------------------<br>+void<br>+Log::Printf(const char *format, ...)<br>+{<br>+ va_list args;<br>+ va_start(args, format);<br>+ VAPrintf(format, args);<br>+ va_end(args);<br>+}<br><br>//----------------------------------------------------------------------<br>// All logging eventually boils down to this function call. If we have<br>@@ -84,7 +101,7 @@ Log::GetMask() const<br>// a valid file handle, we also log to the file.<br>//----------------------------------------------------------------------<br>void<br>-Log::PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args)<br>+Log::VAPrintf(const char *format, va_list args)<br>{<br> // Make a copy of our stream shared pointer in case someone disables our<br> // log while we are logging and releases the stream<br>@@ -136,59 +153,20 @@ Log::PrintfWithFlagsVarArg (uint32_t fla<br> }<br>}<br><br>-<br>-void<br>-Log::PutCString (const char *cstr)<br>-{<br>- Printf ("%s", cstr);<br>-}<br>-<br>-<br>-//----------------------------------------------------------------------<br>-// Simple variable argument logging with flags.<br>-//----------------------------------------------------------------------<br>-void<br>-Log::Printf(const char *format, ...)<br>-{<br>- va_list args;<br>- va_start (args, format);<br>- PrintfWithFlagsVarArg (0, format, args);<br>- va_end (args);<br>-}<br>-<br>-void<br>-Log::VAPrintf (const char *format, va_list args)<br>-{<br>- PrintfWithFlagsVarArg (0, format, args);<br>-}<br>-<br>-<br>-//----------------------------------------------------------------------<br>-// Simple variable argument logging with flags.<br>-//----------------------------------------------------------------------<br>-void<br>-Log::PrintfWithFlags (uint32_t flags, const char *format, ...)<br>-{<br>- va_list args;<br>- va_start (args, format);<br>- PrintfWithFlagsVarArg (flags, format, args);<br>- va_end (args);<br>-}<br>-<br>//----------------------------------------------------------------------<br>// Print debug strings if and only if the global debug option is set to<br>// a non-zero value.<br>//----------------------------------------------------------------------<br>void<br>-Log::Debug (const char *format, ...)<br>+Log::Debug(const char *format, ...)<br>{<br>- if (GetOptions().Test(LLDB_LOG_OPTION_DEBUG))<br>- {<br>- va_list args;<br>- va_start (args, format);<br>- PrintfWithFlagsVarArg (LLDB_LOG_FLAG_DEBUG, format, args);<br>- va_end (args);<br>- }<br>+ if (!GetOptions().Test(LLDB_LOG_OPTION_DEBUG))<br>+ return;<br>+<br>+ va_list args;<br>+ va_start(args, format);<br>+ VAPrintf(format, args);<br>+ va_end(args);<br>}<br><br><br>@@ -197,15 +175,15 @@ Log::Debug (const char *format, ...)<br>// a non-zero value.<br>//----------------------------------------------------------------------<br>void<br>-Log::DebugVerbose (const char *format, ...)<br>+Log::DebugVerbose(const char *format, ...)<br>{<br>- if (GetOptions().AllSet (LLDB_LOG_OPTION_DEBUG | LLDB_LOG_OPTION_VERBOSE))<br>- {<br>- va_list args;<br>- va_start (args, format);<br>- PrintfWithFlagsVarArg (LLDB_LOG_FLAG_DEBUG | LLDB_LOG_FLAG_VERBOSE, format, args);<br>- va_end (args);<br>- }<br>+ if (!GetOptions().AllSet(LLDB_LOG_OPTION_DEBUG | LLDB_LOG_OPTION_VERBOSE))<br>+ return;<br>+<br>+ va_list args;<br>+ va_start(args, format);<br>+ VAPrintf(format, args);<br>+ va_end(args);<br>}<br><br><br>@@ -213,34 +191,34 @@ Log::DebugVerbose (const char *format, .<br>// Log only if all of the bits are set<br>//----------------------------------------------------------------------<br>void<br>-Log::LogIf (uint32_t bits, const char *format, ...)<br>+Log::LogIf(uint32_t bits, const char *format, ...)<br>{<br>- if (m_options.AllSet (bits))<br>- {<br>- va_list args;<br>- va_start (args, format);<br>- PrintfWithFlagsVarArg (0, format, args);<br>- va_end (args);<br>- }<br>+ if (!m_options.AllSet(bits))<br>+ return;<br>+<br>+ va_list args;<br>+ va_start(args, format);<br>+ VAPrintf(format, args);<br>+ va_end(args);<br>}<br><br>//----------------------------------------------------------------------<br>// Printing of errors that are not fatal.<br>//----------------------------------------------------------------------<br>void<br>-Log::Error (const char *format, ...)<br>+Log::Error(const char *format, ...)<br>{<br>- char *arg_msg = NULL;<br>+ char *arg_msg = nullptr;<br> va_list args;<br>- va_start (args, format);<br>- ::vasprintf (&arg_msg, format, args);<br>- va_end (args);<br>+ va_start(args, format);<br>+ ::vasprintf(&arg_msg, format, args);<br>+ va_end(args);<br><br>- if (arg_msg != NULL)<br>- {<br>- PrintfWithFlags (LLDB_LOG_FLAG_ERROR, "error: %s", arg_msg);<br>- free (arg_msg);<br>- }<br>+ if (arg_msg == nullptr)<br>+ return;<br>+<br>+ VAPrintf("error: %s", arg_msg);<br>+ free(arg_msg);<br>}<br><br>//----------------------------------------------------------------------<br>@@ -248,20 +226,20 @@ Log::Error (const char *format, ...)<br>// immediately.<br>//----------------------------------------------------------------------<br>void<br>-Log::FatalError (int err, const char *format, ...)<br>+Log::FatalError(int err, const char *format, ...)<br>{<br>- char *arg_msg = NULL;<br>+ char *arg_msg = nullptr;<br> va_list args;<br>- va_start (args, format);<br>- ::vasprintf (&arg_msg, format, args);<br>- va_end (args);<br>+ va_start(args, format);<br>+ ::vasprintf(&arg_msg, format, args);<br>+ va_end(args);<br><br>- if (arg_msg != NULL)<br>+ if (arg_msg != nullptr)<br> {<br>- PrintfWithFlags (LLDB_LOG_FLAG_ERROR | LLDB_LOG_FLAG_FATAL, "error: %s", arg_msg);<br>- ::free (arg_msg);<br>+ VAPrintf("error: %s", arg_msg);<br>+ ::free(arg_msg);<br> }<br>- ::exit (err);<br>+ ::exit(err);<br>}<br><br><br>@@ -270,15 +248,15 @@ Log::FatalError (int err, const char *fo<br>// enabled.<br>//----------------------------------------------------------------------<br>void<br>-Log::Verbose (const char *format, ...)<br>+Log::Verbose(const char *format, ...)<br>{<br>- if (m_options.Test(LLDB_LOG_OPTION_VERBOSE))<br>- {<br>- va_list args;<br>- va_start (args, format);<br>- PrintfWithFlagsVarArg (LLDB_LOG_FLAG_VERBOSE, format, args);<br>- va_end (args);<br>- }<br>+ if (!m_options.Test(LLDB_LOG_OPTION_VERBOSE))<br>+ return;<br>+<br>+ va_list args;<br>+ va_start(args, format);<br>+ VAPrintf(format, args);<br>+ va_end(args);<br>}<br><br>//----------------------------------------------------------------------<br>@@ -286,40 +264,40 @@ Log::Verbose (const char *format, ...)<br>// enabled.<br>//----------------------------------------------------------------------<br>void<br>-Log::WarningVerbose (const char *format, ...)<br>+Log::WarningVerbose(const char *format, ...)<br>{<br>- if (m_options.Test(LLDB_LOG_OPTION_VERBOSE))<br>- {<br>- char *arg_msg = NULL;<br>- va_list args;<br>- va_start (args, format);<br>- ::vasprintf (&arg_msg, format, args);<br>- va_end (args);<br>+ if (!m_options.Test(LLDB_LOG_OPTION_VERBOSE))<br>+ return;<br><br>- if (arg_msg != NULL)<br>- {<br>- PrintfWithFlags (LLDB_LOG_FLAG_WARNING | LLDB_LOG_FLAG_VERBOSE, "warning: %s", arg_msg);<br>- free (arg_msg);<br>- }<br>- }<br>+ char *arg_msg = nullptr;<br>+ va_list args;<br>+ va_start(args, format);<br>+ ::vasprintf(&arg_msg, format, args);<br>+ va_end(args);<br>+<br>+ if (arg_msg == nullptr)<br>+ return;<br>+<br>+ VAPrintf("warning: %s", arg_msg);<br>+ free(arg_msg);<br>}<br>//----------------------------------------------------------------------<br>// Printing of warnings that are not fatal.<br>//----------------------------------------------------------------------<br>void<br>-Log::Warning (const char *format, ...)<br>+Log::Warning(const char *format, ...)<br>{<br>- char *arg_msg = NULL;<br>+ char *arg_msg = nullptr;<br> va_list args;<br>- va_start (args, format);<br>- ::vasprintf (&arg_msg, format, args);<br>- va_end (args);<br>+ va_start(args, format);<br>+ ::vasprintf(&arg_msg, format, args);<br>+ va_end(args);<br><br>- if (arg_msg != NULL)<br>- {<br>- PrintfWithFlags (LLDB_LOG_FLAG_WARNING, "warning: %s", arg_msg);<br>- free (arg_msg);<br>- }<br>+ if (arg_msg == nullptr)<br>+ return;<br>+<br>+ VAPrintf("warning: %s", arg_msg);<br>+ free(arg_msg);<br>}<br><br>typedef std::map <ConstString, Log::Callbacks> CallbackMap;<br><br>Added: lldb/trunk/source/Core/NullLog.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/NullLog.cpp?rev=236174&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/NullLog.cpp?rev=236174&view=auto</a><br>==============================================================================<br>--- lldb/trunk/source/Core/NullLog.cpp (added)<br>+++ lldb/trunk/source/Core/NullLog.cpp Wed Apr 29 17:55:28 2015<br>@@ -0,0 +1,74 @@<br>+//===-- NullLog.cpp ---------------------------------------------*- C++ -*-===//<br>+//<br>+// The LLVM Compiler Infrastructure<br>+//<br>+// This file is distributed under the University of Illinois Open Source<br>+// License. See LICENSE.TXT for details.<br>+//<br>+//===----------------------------------------------------------------------===//<br>+<br>+#include "lldb/Core/NullLog.h"<br>+<br>+using namespace lldb_private;<br>+<br>+NullLog::NullLog()<br>+{<br>+}<br>+NullLog::~NullLog()<br>+{<br>+}<br>+<br>+void<br>+NullLog::PutCString(const char *cstr)<br>+{<br>+}<br>+<br>+void<br>+NullLog::Printf(const char *format, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::VAPrintf(const char *format, va_list args)<br>+{<br>+}<br>+<br>+void<br>+NullLog::LogIf(uint32_t mask, const char *fmt, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::Debug(const char *fmt, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::DebugVerbose(const char *fmt, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::Error(const char *fmt, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::FatalError(int err, const char *fmt, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::Verbose(const char *fmt, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::Warning(const char *fmt, ...)<br>+{<br>+}<br>+<br>+void<br>+NullLog::WarningVerbose(const char *fmt, ...)<br>+{<br>+}<br><br><br>_______________________________________________<br>lldb-commits mailing list<br><a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br></blockquote><br><br>_______________________________________________<br>lldb-commits mailing list<br><a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br></blockquote><br><br>_______________________________________________<br>lldb-commits mailing list<br><a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits</a><br></div><div style="word-wrap:break-word"><div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br>Thanks,</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><i>- Enrico</i><br>📩 egranata@<font color="#ff2600"></font>.com ☎️ 27683</div>
</div>
<br></div></blockquote></div>