[Lldb-commits] [lldb] r165438 - in /lldb/trunk: include/lldb/Core/Log.h include/lldb/Interpreter/CommandObject.h include/lldb/Interpreter/CommandObjectMultiword.h include/lldb/lldb-private-log.h source/API/SBCommandInterpreter.cpp source/Commands/CommandObjectCommands.cpp source/Commands/CommandObjectLog.cpp source/Core/Log.cpp source/Core/Module.cpp source/Core/ModuleList.cpp source/lldb-log.cpp

Greg Clayton gclayton at apple.com
Mon Oct 8 15:41:53 PDT 2012


Author: gclayton
Date: Mon Oct  8 17:41:53 2012
New Revision: 165438

URL: http://llvm.org/viewvc/llvm-project?rev=165438&view=rev
Log:
Added a new "module" log channel which covers module creation, deletion, and common module list actions.

Also added a new option for "log enable" which is "--stack" which will print out a stack backtrace for each log line.

This was used to track down the leaking module issue I fixed last week.


Modified:
    lldb/trunk/include/lldb/Core/Log.h
    lldb/trunk/include/lldb/Interpreter/CommandObject.h
    lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h
    lldb/trunk/include/lldb/lldb-private-log.h
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/Commands/CommandObjectCommands.cpp
    lldb/trunk/source/Commands/CommandObjectLog.cpp
    lldb/trunk/source/Core/Log.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Core/ModuleList.cpp
    lldb/trunk/source/lldb-log.cpp

Modified: lldb/trunk/include/lldb/Core/Log.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Log.h?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Log.h (original)
+++ lldb/trunk/include/lldb/Core/Log.h Mon Oct  8 17:41:53 2012
@@ -46,6 +46,7 @@
 #define LLDB_LOG_OPTION_PREPEND_TIMESTAMP       (1u << 4)
 #define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD (1u << 5)
 #define LLDB_LOG_OPTION_PREPEND_THREAD_NAME     (1U << 6)
+#define LLDB_LOG_OPTION_BACKTRACE               (1U << 7)
 
 //----------------------------------------------------------------------
 // Logging Functions

Modified: lldb/trunk/include/lldb/Interpreter/CommandObject.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObject.h?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObject.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObject.h Mon Oct  8 17:41:53 2012
@@ -133,7 +133,7 @@
     // the Command object from the Command dictionary (aliases have their own
     // deletion scheme, so they do not need to care about this)
     virtual bool
-    IsRemovable() { return false; }
+    IsRemovable() const { return false; }
     
     bool
     IsAlias () { return m_is_alias; }

Modified: lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h (original)
+++ lldb/trunk/include/lldb/Interpreter/CommandObjectMultiword.h Mon Oct  8 17:41:53 2012
@@ -74,7 +74,7 @@
              CommandReturnObject &result);
     
     virtual bool
-    IsRemovable() { return m_can_be_removed; }
+    IsRemovable() const { return m_can_be_removed; }
     
     void
     SetRemovable (bool removable)

Modified: lldb/trunk/include/lldb/lldb-private-log.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-log.h?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-log.h (original)
+++ lldb/trunk/include/lldb/lldb-private-log.h Mon Oct  8 17:41:53 2012
@@ -40,6 +40,7 @@
 #define LIBLLDB_LOG_COMMANDS            (1U << 18)
 #define LIBLLDB_LOG_TYPES               (1u << 19)
 #define LIBLLDB_LOG_SYMBOLS             (1u << 20)
+#define LIBLLDB_LOG_MODULES             (1u << 21)
 #define LIBLLDB_LOG_ALL                 (UINT32_MAX)
 #define LIBLLDB_LOG_DEFAULT             (LIBLLDB_LOG_PROCESS              |\
                                          LIBLLDB_LOG_THREAD               |\

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Mon Oct  8 17:41:53 2012
@@ -40,7 +40,7 @@
     m_backend(backend) {}
     
     virtual bool
-    IsRemovable() { return true; }
+    IsRemovable() const { return true; }
     
 protected:
     virtual bool

Modified: lldb/trunk/source/Commands/CommandObjectCommands.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectCommands.cpp?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectCommands.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectCommands.cpp Mon Oct  8 17:41:53 2012
@@ -1186,7 +1186,7 @@
     }
     
     virtual bool
-    IsRemovable ()
+    IsRemovable () const
     {
         return true;
     }

Modified: lldb/trunk/source/Commands/CommandObjectLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectLog.cpp?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectLog.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectLog.cpp Mon Oct  8 17:41:53 2012
@@ -144,6 +144,7 @@
             case 'T':  log_options |= LLDB_LOG_OPTION_PREPEND_TIMESTAMP;      break;
             case 'p':  log_options |= LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD;break;
             case 'n':  log_options |= LLDB_LOG_OPTION_PREPEND_THREAD_NAME;    break;
+            case 'S':  log_options |= LLDB_LOG_OPTION_BACKTRACE;              break;
             default:
                 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
                 break;
@@ -215,6 +216,7 @@
 { LLDB_OPT_SET_1, false, "timestamp",  'T', no_argument,       NULL, 0, eArgTypeNone,       "Prepend all log lines with a timestamp." },
 { LLDB_OPT_SET_1, false, "pid-tid",    'p', no_argument,       NULL, 0, eArgTypeNone,       "Prepend all log lines with the process and thread ID that generates the log line." },
 { LLDB_OPT_SET_1, false, "thread-name",'n', no_argument,       NULL, 0, eArgTypeNone,       "Prepend all log lines with the thread name for the thread that generates the log line." },
+{ LLDB_OPT_SET_1, false, "stack",      'S', no_argument,       NULL, 0, eArgTypeNone,       "Append a stack backtrace to each log line." },
 { 0, false, NULL,                       0,  0,                 NULL, 0, eArgTypeNone,       NULL }
 };
 

Modified: lldb/trunk/source/Core/Log.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Log.cpp?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/source/Core/Log.cpp (original)
+++ lldb/trunk/source/Core/Log.cpp Mon Oct  8 17:41:53 2012
@@ -118,6 +118,9 @@
 
         header.PrintfVarArg (format, args);
         m_stream_sp->Printf("%s\n", header.GetData());
+        
+        if (m_options.Test (LLDB_LOG_OPTION_BACKTRACE))
+            Host::Backtrace (*m_stream_sp, 1024);
         m_stream_sp->Flush();
     }
 }

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon Oct  8 17:41:53 2012
@@ -117,7 +117,7 @@
 }
 
 #endif
-    
+
 Module::Module (const ModuleSpec &module_spec) :
     m_mutex (Mutex::eMutexTypeRecursive),
     m_mod_time (module_spec.GetFileSpec().GetModificationTime()),
@@ -146,7 +146,7 @@
         GetModuleCollection().push_back(this);
     }
     
-    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
+    LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
     if (log)
         log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')",
                      this,
@@ -191,7 +191,7 @@
 
     if (object_name)
         m_object_name = *object_name;
-    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
+    LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
     if (log)
         log->Printf ("%p Module::Module((%s) '%s/%s%s%s%s')",
                      this,
@@ -211,10 +211,10 @@
         ModuleCollection &modules = GetModuleCollection();
         ModuleCollection::iterator end = modules.end();
         ModuleCollection::iterator pos = std::find(modules.begin(), end, this);
-        if (pos != end)
-            modules.erase(pos);
+        assert (pos != end);
+        modules.erase(pos);
     }
-    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
+    LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_OBJECT|LIBLLDB_LOG_MODULES));
     if (log)
         log->Printf ("%p Module::~Module((%s) '%s/%s%s%s%s')",
                      this,

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Mon Oct  8 17:41:53 2012
@@ -724,6 +724,11 @@
                 {
                     if (old_module_sp_ptr && !old_module_sp_ptr->get())
                         *old_module_sp_ptr = module_sp;
+
+                    LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_MODULES));
+                    if (log)
+                        log->Printf("module changed: %p, removing from global module list", module_sp.get());
+
                     shared_module_list.Remove (module_sp);
                     module_sp.reset();
                 }

Modified: lldb/trunk/source/lldb-log.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb-log.cpp?rev=165438&r1=165437&r2=165438&view=diff
==============================================================================
--- lldb/trunk/source/lldb-log.cpp (original)
+++ lldb/trunk/source/lldb-log.cpp Mon Oct  8 17:41:53 2012
@@ -135,6 +135,7 @@
                 else if (0 == ::strncasecmp(arg, "unwind", 6))  flag_bits &= ~LIBLLDB_LOG_UNWIND;
                 else if (0 == ::strncasecmp(arg, "types", 5))   flag_bits &= ~LIBLLDB_LOG_TYPES;
                 else if (0 == ::strncasecmp(arg, "symbol", 6))  flag_bits &= ~LIBLLDB_LOG_SYMBOLS;
+                else if (0 == ::strncasecmp(arg, "module", 6))  flag_bits &= ~LIBLLDB_LOG_MODULES;
                 else
                 {
                     feedback_strm->Printf ("error:  unrecognized log category '%s'\n", arg);
@@ -201,6 +202,7 @@
             else if (0 == ::strncasecmp(arg, "unwind", 6))  flag_bits |= LIBLLDB_LOG_UNWIND;
             else if (0 == ::strncasecmp(arg, "types", 5))   flag_bits |= LIBLLDB_LOG_TYPES;
             else if (0 == ::strncasecmp(arg, "symbol", 6))  flag_bits |= LIBLLDB_LOG_SYMBOLS;
+            else if (0 == ::strncasecmp(arg, "module", 6))  flag_bits |= LIBLLDB_LOG_MODULES;
             else
             {
                 feedback_strm->Printf("error: unrecognized log category '%s'\n", arg);
@@ -220,23 +222,24 @@
 lldb_private::ListLogCategories (Stream *strm)
 {
     strm->Printf("Logging categories for 'lldb':\n"
-        "  all - turn on all available logging categories\n"
-        "  api - enable logging of API calls and return values\n"
-        "  command - log command argument parsing\n"
-        "  default - enable the default set of logging categories for liblldb\n"
-        "  break - log breakpoints\n"
-        "  events - log broadcaster, listener and event queue activities\n"
-        "  expr - log expressions\n"
-        "  object - log object construction/destruction for important objects\n"
-        "  process - log process events and activities\n"
-        "  thread - log thread events and activities\n"
-        "  script - log events about the script interpreter\n"
-        "  dyld - log shared library related activities\n"
-        "  state - log private and public process state changes\n"
-        "  step - log step related activities\n"
-        "  unwind - log stack unwind activities\n"
-        "  verbose - enable verbose logging\n"
-        "  symbol - log symbol related issues and warnings\n"
-        "  watch - log watchpoint related activities\n"
-        "  types - log type system related activities\n");
+                 "  all - turn on all available logging categories\n"
+                 "  api - enable logging of API calls and return values\n"
+                 "  break - log breakpoints\n"
+                 "  command - log command argument parsing\n"
+                 "  default - enable the default set of logging categories for liblldb\n"
+                 "  dyld - log shared library related activities\n"
+                 "  events - log broadcaster, listener and event queue activities\n"
+                 "  expr - log expressions\n"
+                 "  object - log object construction/destruction for important objects\n"
+                 "  module - log module activities such as when modules are created, detroyed, replaced, and more\n"
+                 "  process - log process events and activities\n"
+                 "  script - log events about the script interpreter\n"
+                 "  state - log private and public process state changes\n"
+                 "  step - log step related activities\n"
+                 "  symbol - log symbol related issues and warnings\n"
+                 "  thread - log thread events and activities\n"
+                 "  types - log type system related activities\n"
+                 "  unwind - log stack unwind activities\n"
+                 "  verbose - enable verbose logging\n"
+                 "  watch - log watchpoint related activities\n");
 }





More information about the lldb-commits mailing list