[Lldb-commits] [lldb] r145219 - in /lldb/trunk: include/lldb/Core/Module.h include/lldb/Symbol/SymbolFile.h include/lldb/Target/Platform.h source/Commands/CommandObjectProcess.cpp source/Core/Module.cpp source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h source/Symbol/SymbolFile.cpp

Greg Clayton gclayton at apple.com
Sun Nov 27 17:45:01 PST 2011


Author: gclayton
Date: Sun Nov 27 19:45:00 2011
New Revision: 145219

URL: http://llvm.org/viewvc/llvm-project?rev=145219&view=rev
Log:
CommandObjectProcess was recently changed to automatically use the platform
to launch a process for debugging. Since this isn't supported on all platforms,
we need to do what we used to do if this isn't supported. I added:

    bool
    Platform::CanDebugProcess ();
    
This will get checked before trying to launch a process for debugging and then
fall back to launching the process through the current host debugger. This
should solve the issue for linux and keep the platform code clean.

Centralized logging code for logging errors, warnings and logs when reporting
things for modules or symbol files. Both lldb_private::Module and 
lldb_private::SymbolFile now have the following member functions:

    void                    
    LogMessage (Log *log, const char *format, ...);

    void
    ReportWarning (const char *format, ...);

    void
    ReportError (const char *format, ...);

These will all output the module name and object (if any) such as:

    "error: lldb.so ...."
    "warning: my_archive.a(foo.o) ...."
    
This will keep the output consistent and stop a lot of logging calls from 
having to try and output all of the information that uniquely identifies
a module or symbol file. Many places in the code were grabbing the path to the
object file manually and if the module represented a .o file in an archive, we
would see log messages like:

    error: foo.a - some error happened


Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/include/lldb/Symbol/SymbolFile.h
    lldb/trunk/include/lldb/Target/Platform.h
    lldb/trunk/source/Commands/CommandObjectProcess.cpp
    lldb/trunk/source/Core/Module.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/source/Symbol/SymbolFile.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Sun Nov 27 19:45:00 2011
@@ -114,7 +114,8 @@
     CalculateSymbolContextModule ();
 
     void
-    GetDescription (Stream *s);
+    GetDescription (Stream *s,
+                    lldb::DescriptionLevel level = lldb::eDescriptionLevelFull);
 
     //------------------------------------------------------------------
     /// Dump a description of this object to a Stream.
@@ -664,6 +665,19 @@
     ClangASTContext &
     GetClangASTContext ();
 
+    // Special error functions that can do printf style formatting that will prepend the message with
+    // something appropriate for this module (like the architecture, path and object name (if any)). 
+    // This centralizes code so that everyone doesn't need to format their error and log messages on
+    // their own and keeps the output a bit more consistent.
+    void                    
+    LogMessage (Log *log, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
+
+    void
+    ReportWarning (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+
+    void
+    ReportError (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+
 protected:
     //------------------------------------------------------------------
     // Member Variables

Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Sun Nov 27 19:45:00 2011
@@ -133,6 +133,14 @@
 
     ObjectFile*             GetObjectFile() { return m_obj_file; }
     const ObjectFile*       GetObjectFile() const { return m_obj_file; }
+    
+    // Special error functions that can do printf style formatting that will prepend the message with
+    // something appropriate for this symbol file (like the architecture, path and object name). This
+    // centralizes code so that everyone doesn't need to format their error and log messages on their
+    // own and keeps the output a bit more consistent.
+    void                    LogMessage (Log *log, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
+    void                    ReportWarning (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+    void                    ReportError (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
 protected:
     ObjectFile*             m_obj_file; // The object file that symbols can be extracted from.
 

Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Sun Nov 27 19:45:00 2011
@@ -276,6 +276,19 @@
         LaunchProcess (ProcessLaunchInfo &launch_info);
 
         //------------------------------------------------------------------
+        /// Not all platforms will support debugging a process by spawning
+        /// somehow halted for a debugger (specified using the 
+        /// "eLaunchFlagDebug" launch flag) and then attaching. If your 
+        /// platform doesn't support this, override this function and return
+        /// false.
+        //------------------------------------------------------------------
+        virtual bool
+        CanDebugProcess ()
+        {
+            return true; 
+        }
+
+        //------------------------------------------------------------------
         /// Subclasses should NOT need to implement this function as it uses
         /// the Platform::LaunchProcess() followed by Platform::Attach ()
         //------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectProcess.cpp?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectProcess.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectProcess.cpp Sun Nov 27 19:45:00 2011
@@ -257,11 +257,23 @@
             if (!m_options.launch_info.GetArchitecture().IsValid())
                 m_options.launch_info.GetArchitecture() = target->GetArchitecture();
 
-            process = target->GetPlatform()->DebugProcess (m_options.launch_info, 
-                                                           debugger,
-                                                           target,
-                                                           debugger.GetListener(),
-                                                           error).get();
+            PlatformSP platform_sp (target->GetPlatform());
+            
+            if (platform_sp && platform_sp->CanDebugProcess ())
+            {
+                process = target->GetPlatform()->DebugProcess (m_options.launch_info, 
+                                                               debugger,
+                                                               target,
+                                                               debugger.GetListener(),
+                                                               error).get();
+            }
+            else
+            {
+                const char *plugin_name = m_options.launch_info.GetProcessPluginName();
+                process = target->CreateProcess (debugger.GetListener(), plugin_name).get();
+                if (process)
+                    error = process->Launch (m_options.launch_info);
+            }
 
             if (process == NULL)
             {

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Sun Nov 27 19:45:00 2011
@@ -11,6 +11,7 @@
 #include "lldb/Core/Log.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/RegularExpression.h"
+#include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/lldb-private-log.h"
 #include "lldb/Symbol/ObjectFile.h"
@@ -578,16 +579,28 @@
 }
 
 void
-Module::GetDescription (Stream *s)
+Module::GetDescription (Stream *s, lldb::DescriptionLevel level)
 {
     Mutex::Locker locker (m_mutex);
 
-    if (m_arch.IsValid())
-        s->Printf("(%s) ", m_arch.GetArchitectureName());
+    if (level >= eDescriptionLevelFull)
+    {
+        if (m_arch.IsValid())
+            s->Printf("(%s) ", m_arch.GetArchitectureName());
+    }
 
-    char path[PATH_MAX];
-    if (m_file.GetPath(path, sizeof(path)))
-        s->PutCString(path);
+    if (level == eDescriptionLevelBrief)
+    {
+        const char *filename = m_file.GetFilename().GetCString();
+        if (filename)
+            s->PutCString (filename);
+    }
+    else
+    {
+        char path[PATH_MAX];
+        if (m_file.GetPath(path, sizeof(path)))
+            s->PutCString(path);
+    }
 
     const char *object_name = m_object_name.GetCString();
     if (object_name)
@@ -595,6 +608,48 @@
 }
 
 void
+Module::ReportError (const char *format, ...)
+{
+    StreamString module_description;
+    GetDescription(&module_description, lldb::eDescriptionLevelBrief);
+    ::fprintf (stderr, "error: %s ", module_description.GetString().c_str());
+    
+    va_list args;
+    va_start (args, format);
+    vfprintf (stderr, format, args);
+    va_end (args);
+}
+
+void
+Module::ReportWarning (const char *format, ...)
+{
+    StreamString module_description;
+    GetDescription(&module_description, lldb::eDescriptionLevelBrief);
+    ::fprintf (stderr, "warning: %s ", module_description.GetString().c_str());
+    
+    va_list args;
+    va_start (args, format);
+    vfprintf (stderr, format, args);
+    va_end (args);
+}
+
+void
+Module::LogMessage (Log *log, const char *format, ...)
+{
+    if (log)
+    {
+        StreamString log_message;
+        GetDescription(&log_message, lldb::eDescriptionLevelBrief);
+        log_message.PutCString (": ");
+        va_list args;
+        va_start (args, format);
+        log_message.PrintfVarArg (format, args);
+        va_end (args);
+        log->PutCString(log_message.GetString().c_str());
+    }
+}
+
+void
 Module::Dump(Stream *s)
 {
     Mutex::Locker locker (m_mutex);

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Sun Nov 27 19:45:00 2011
@@ -10,6 +10,7 @@
 #include "DWARFCompileUnit.h"
 
 #include "lldb/Core/Mangled.h"
+#include "lldb/Core/Module.h"
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Symbol/ObjectFile.h"
@@ -164,14 +165,16 @@
 
     DWARFDebugInfoEntry die;
         // Keep a flat array of the DIE for binary lookup by DIE offset
-//    Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
-//        if (log)
-//            log->Printf("0x%8.8x: Compile Unit: length = 0x%8.8x, version = 0x%4.4x, abbr_offset = 0x%8.8x, addr_size = 0x%2.2x",
-//                        cu->GetOffset(),
-//                        cu->GetLength(),
-//                        cu->GetVersion(),
-//                        cu->GetAbbrevOffset(),
-//                        cu->GetAddressByteSize());
+    if (!cu_die_only)
+    {
+        LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
+        if (log)
+        {
+            m_dwarf2Data->LogMessage (log.get(), 
+                                      "DWARFCompileUnit::ExtractDIEsIfNeeded () for compile unit at .debug_info[0x%8.8x]", 
+                                      GetOffset());
+        }
+    }
 
     uint32_t depth = 0;
     // We are in our compile unit, parse starting at the offset
@@ -263,13 +266,9 @@
     // unit header).
     if (offset > next_cu_offset)
     {
-        char path[PATH_MAX];
-        ObjectFile *objfile = m_dwarf2Data->GetObjectFile();
-        if (objfile)
-        {
-            objfile->GetFileSpec().GetPath(path, sizeof(path));
-        }
-        fprintf (stderr, "warning: DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8x in '%s'\n", GetOffset(), offset, path);
+        m_dwarf2Data->ReportWarning ("DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8x\n", 
+                                     GetOffset(), 
+                                     offset);
     }
 
     // Since std::vector objects will double their size, we really need to
@@ -282,7 +281,7 @@
         DWARFDebugInfoEntry::collection exact_size_die_array (m_die_array.begin(), m_die_array.end());
         exact_size_die_array.swap (m_die_array);
     }
-    LogSP log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_DEBUG_INFO));
+    LogSP log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_DEBUG_INFO | DWARF_LOG_VERBOSE));
     if (log)
     {
         StreamString strm;
@@ -404,10 +403,11 @@
         LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_ARANGES));
 
         if (log)
-            log->Printf ("DWARFCompileUnit::GetFunctionAranges() for \"%s/%s\" compile unit at 0x%8.8x",
-                         m_dwarf2Data->GetObjectFile()->GetFileSpec().GetDirectory().GetCString(),
-                         m_dwarf2Data->GetObjectFile()->GetFileSpec().GetFilename().GetCString(),
-                         m_offset);
+        {
+            m_dwarf2Data->LogMessage (log.get(), 
+                                      "DWARFCompileUnit::GetFunctionAranges() for compile unit at .debug_info[0x%8.8x]",
+                                      GetOffset());
+        }
         DIE()->BuildFunctionAddressRangeTable (m_dwarf2Data, this, m_func_aranges_ap.get());
         const bool minimize = false;
         m_func_aranges_ap->Sort(minimize);
@@ -573,6 +573,15 @@
 
     const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize());
 
+    LogSP log (LogChannelDWARF::GetLogIfAll (DWARF_LOG_LOOKUPS));
+    
+    if (log)
+    {
+        m_dwarf2Data->LogMessage (log.get(), 
+                                  "DWARFCompileUnit::Index() for compile unit at .debug_info[0x%8.8x]",
+                                  GetOffset());
+    }
+
     DWARFDebugInfoEntry::const_iterator pos;
     DWARFDebugInfoEntry::const_iterator begin = m_die_array.begin();
     DWARFDebugInfoEntry::const_iterator end = m_die_array.end();

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Sun Nov 27 19:45:00 2011
@@ -92,6 +92,15 @@
 }
 
 uint64_t
+DWARFDebugInfoEntry::Attributes::FormValueAsUnsigned (SymbolFileDWARF* dwarf2Data, dw_attr_t attr, uint64_t fail_value) const
+{
+    const uint32_t attr_idx = FindAttributeIndex (attr);
+    if (attr_idx != UINT32_MAX)
+        return FormValueAsUnsignedAtIndex (dwarf2Data, attr_idx, fail_value);
+    return fail_value;
+}
+
+uint64_t
 DWARFDebugInfoEntry::Attributes::FormValueAsUnsignedAtIndex(SymbolFileDWARF* dwarf2Data, uint32_t i, uint64_t fail_value) const
 {
     DWARFFormValue form_value;
@@ -1713,6 +1722,152 @@
 }
 
 
+const DWARFDebugInfoEntry *
+DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, 
+											  DWARFCompileUnit* cu) const
+{
+	DWARFDebugInfoEntry::Attributes attributes;
+	GetAttributes(dwarf2Data, cu, NULL, attributes);
+	return GetParentDeclContextDIE (dwarf2Data, cu, attributes);
+}
+
+const DWARFDebugInfoEntry *
+DWARFDebugInfoEntry::GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, 
+											  DWARFCompileUnit* cu,
+											  const DWARFDebugInfoEntry::Attributes& attributes) const
+{
+	const DWARFDebugInfoEntry * die = this;
+	
+	while (die != NULL)
+	{
+		// If this is the original DIE that we are searching for a declaration 
+		// for, then don't look in the cache as we don't want our own decl 
+		// context to be our decl context...
+		if (die != this)
+		{            
+			switch (die->Tag())
+			{
+				case DW_TAG_compile_unit:
+				case DW_TAG_namespace:
+				case DW_TAG_structure_type:
+				case DW_TAG_union_type:
+				case DW_TAG_class_type:
+					return die;
+					
+				default:
+					break;
+			}
+		}
+		
+		dw_offset_t die_offset;
+        
+		die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_specification, DW_INVALID_OFFSET);
+		if (die_offset != DW_INVALID_OFFSET)
+		{
+			const DWARFDebugInfoEntry *spec_die = cu->GetDIEPtr (die_offset);
+			if (spec_die)
+			{
+				const DWARFDebugInfoEntry *spec_die_decl_ctx_die = spec_die->GetParentDeclContextDIE (dwarf2Data, cu);
+				if (spec_die_decl_ctx_die)
+					return spec_die_decl_ctx_die;
+			}
+		}
+		
+        die_offset = attributes.FormValueAsUnsigned(dwarf2Data, DW_AT_abstract_origin, DW_INVALID_OFFSET);
+		if (die_offset != DW_INVALID_OFFSET)
+		{
+			const DWARFDebugInfoEntry *abs_die = cu->GetDIEPtr (die_offset);
+			if (abs_die)
+			{
+				const DWARFDebugInfoEntry *abs_die_decl_ctx_die = abs_die->GetParentDeclContextDIE (dwarf2Data, cu);
+				if (abs_die_decl_ctx_die)
+					return abs_die_decl_ctx_die;
+			}
+		}
+		
+		die = die->GetParent();
+	}
+    return NULL;
+}
+
+
+const char *
+DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data, 
+									   DWARFCompileUnit* cu,
+									   std::string &storage) const
+{
+	DWARFDebugInfoEntry::Attributes attributes;
+	GetAttributes(dwarf2Data, cu, NULL, attributes);
+	return GetQualifiedName (dwarf2Data, cu, attributes, storage);
+}
+
+const char*
+DWARFDebugInfoEntry::GetQualifiedName (SymbolFileDWARF* dwarf2Data, 
+									   DWARFCompileUnit* cu,
+									   const DWARFDebugInfoEntry::Attributes& attributes,
+									   std::string &storage) const
+{
+	
+	const char *name = GetName (dwarf2Data, cu);
+	
+	if (name)
+	{
+		const DWARFDebugInfoEntry *parent_decl_ctx_die = GetParentDeclContextDIE (dwarf2Data, cu);
+		storage.clear();
+		// TODO: change this to get the correct decl context parent....
+		while (parent_decl_ctx_die)
+		{
+			const dw_tag_t parent_tag = parent_decl_ctx_die->Tag();
+			switch (parent_tag)
+			{
+                case DW_TAG_namespace:
+				{
+					const char *namespace_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
+					if (namespace_name)
+					{
+						storage.insert (0, "::");
+						storage.insert (0, namespace_name);
+					}
+					else
+					{
+						storage.insert (0, "(anonymous namespace)::");
+					}
+					parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
+				}
+                    break;
+					
+                case DW_TAG_class_type:
+                case DW_TAG_structure_type:
+                case DW_TAG_union_type:
+				{
+					const char *class_union_struct_name = parent_decl_ctx_die->GetName (dwarf2Data, cu);
+                    
+					if (class_union_struct_name)
+					{
+						storage.insert (0, "::");
+						storage.insert (0, class_union_struct_name);
+					}
+					parent_decl_ctx_die = parent_decl_ctx_die->GetParentDeclContextDIE(dwarf2Data, cu);
+				}
+                    break;
+                    
+                default:
+                    parent_decl_ctx_die = NULL;
+                    break;
+			}
+		}
+		
+		if (storage.empty())
+			storage.append ("::");
+        
+		storage.append (name);
+	}
+	if (storage.empty())
+		return NULL;
+	return storage.c_str();
+}
+
+
 //----------------------------------------------------------------------
 // LookupAddress
 //----------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h Sun Nov 27 19:45:00 2011
@@ -68,6 +68,7 @@
         dw_attr_t FormAtIndex(uint32_t i) const { return m_infos[i].form; }
         bool ExtractFormValueAtIndex (SymbolFileDWARF* dwarf2Data, uint32_t i, DWARFFormValue &form_value) const;
         uint64_t FormValueAsUnsignedAtIndex (SymbolFileDWARF* dwarf2Data, uint32_t i, uint64_t fail_value) const;
+        uint64_t FormValueAsUnsigned (SymbolFileDWARF* dwarf2Data, dw_attr_t attr, uint64_t fail_value) const;
         uint32_t FindAttributeIndex(dw_attr_t attr) const;
         bool ContainsAttribute(dw_attr_t attr) const;
         bool RemoveAttribute(dw_attr_t attr);
@@ -226,6 +227,17 @@
                     const dw_offset_t die_offset,
                     lldb_private::Stream &s);
 
+    const char * GetQualifiedName (
+                    SymbolFileDWARF* dwarf2Data, 
+                    DWARFCompileUnit* cu,
+                    std::string &storage) const;
+    
+    const char * GetQualifiedName (
+                    SymbolFileDWARF* dwarf2Data, 
+                    DWARFCompileUnit* cu,
+                    const DWARFDebugInfoEntry::Attributes& attributes,
+                    std::string &storage) const;
+
 //    static int  Compare(
 //                    SymbolFileDWARF* dwarf2Data,
 //                    dw_offset_t a_die_offset,
@@ -340,6 +352,13 @@
             DWARFDebugInfoEntry*    GetFirstChild()         { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; }
     const   DWARFDebugInfoEntry*    GetFirstChild() const   { return (HasChildren() && !m_empty_children) ? this + 1 : NULL; }
 
+    
+    const   DWARFDebugInfoEntry*    GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, 
+                                                             DWARFCompileUnit* cu) const;
+    const   DWARFDebugInfoEntry*    GetParentDeclContextDIE (SymbolFileDWARF* dwarf2Data, 
+                                                             DWARFCompileUnit* cu, 
+                                                             const DWARFDebugInfoEntry::Attributes& attributes) const;
+
     void        
     SetParent (DWARFDebugInfoEntry* parent)     
     {

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Sun Nov 27 19:45:00 2011
@@ -2273,10 +2273,12 @@
 
     if (log)
     {
-        log->Printf ("SymbolFileDWARF::FindGlobalVariables (file=\"%s/%s\", name=\"%s\", append=%u, max_matches=%u, variables)", 
-                     m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                     m_obj_file->GetFileSpec().GetFilename().GetCString(),
-                     name.GetCString(), append, max_matches);
+        LogMessage (log.get(), 
+                    "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)", 
+                    name.GetCString(), 
+                    namespace_decl,
+                    append, 
+                    max_matches);
     }
     
     if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
@@ -2369,10 +2371,11 @@
     
     if (log)
     {
-        log->Printf ("SymbolFileDWARF::FindGlobalVariables (file=\"%s/%s\", regex=\"%s\", append=%u, max_matches=%u, variables)", 
-                     m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                     m_obj_file->GetFileSpec().GetFilename().GetCString(),
-                     regex.GetText(), append, max_matches);
+        LogMessage (log.get(), 
+                    "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)", 
+                    regex.GetText(), 
+                    append, 
+                    max_matches);
     }
 
     DWARFDebugInfo* info = DebugInfo();
@@ -2649,10 +2652,11 @@
     
     if (log)
     {
-        log->Printf ("SymbolFileDWARF::FindFunctions (file=\"%s/%s\", name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", 
-                     m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                     m_obj_file->GetFileSpec().GetFilename().GetCString(),
-                     name.GetCString(), name_type_mask, append);
+        LogMessage (log.get(), 
+                    "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)", 
+                    name.GetCString(), 
+                    name_type_mask, 
+                    append);
     }
 
     // If we aren't appending the results to this list, then clear the list
@@ -2922,10 +2926,10 @@
     
     if (log)
     {
-        log->Printf ("SymbolFileDWARF::FindFunctions (file=\"%s/%s\", regex=\"%s\"append=%u, sc_list)", 
-                     m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                     m_obj_file->GetFileSpec().GetFilename().GetCString(),
-                     regex.GetText(), append);
+        LogMessage (log.get(), 
+                    "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)", 
+                     regex.GetText(), 
+                    append);
     }
     
 
@@ -2957,40 +2961,6 @@
     return sc_list.GetSize() - original_size;
 }
 
-void
-SymbolFileDWARF::ReportError (const char *format, ...)
-{
-    ::fprintf (stderr, 
-               "error: %s/%s ", 
-               m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-               m_obj_file->GetFileSpec().GetFilename().GetCString());
-
-    if (m_obj_file->GetModule()->GetObjectName())
-        ::fprintf (stderr, "(%s) ", m_obj_file->GetModule()->GetObjectName().GetCString());
-
-    va_list args;
-    va_start (args, format);
-    vfprintf (stderr, format, args);
-    va_end (args);
-}
-
-void
-SymbolFileDWARF::ReportWarning (const char *format, ...)
-{
-    ::fprintf (stderr, 
-               "warning: %s/%s ", 
-               m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-               m_obj_file->GetFileSpec().GetFilename().GetCString());
-
-    if (m_obj_file->GetModule()->GetObjectName())
-        ::fprintf (stderr, "(%s) ", m_obj_file->GetModule()->GetObjectName().GetCString());
-
-    va_list args;
-    va_start (args, format);
-    vfprintf (stderr, format, args);
-    va_end (args);
-}
-
 uint32_t
 SymbolFileDWARF::FindTypes(const SymbolContext& sc, const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, TypeList& types)
 {
@@ -3002,10 +2972,11 @@
     
     if (log)
     {
-        log->Printf ("SymbolFileDWARF::FindTypes (file=\"%s/%s\", sc, name=\"%s\", append=%u, max_matches=%u, type_list)", 
-                     m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                     m_obj_file->GetFileSpec().GetFilename().GetCString(),
-                     name.GetCString(), append, max_matches);
+        LogMessage (log.get(), 
+                    "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)", 
+                    name.GetCString(), 
+                    append, 
+                    max_matches);
     }
 
     // If we aren't appending the results to this list, then clear the list
@@ -3086,9 +3057,8 @@
     
     if (log)
     {
-        log->Printf ("SymbolFileDWARF::FindNamespace (file=\"%s/%s\", sc, name=\"%s\")", 
-                     m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                     m_obj_file->GetFileSpec().GetFilename().GetCString(),
+        LogMessage (log.get(), 
+                    "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")", 
                      name.GetCString());
     }
     
@@ -3635,33 +3605,24 @@
             LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
             if (log)
             {
-                const char *object_name = m_obj_file->GetModule()->GetObjectName().GetCString();
                 if (namespace_name)
                 {
-                    log->Printf ("ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl * %p in %s/%s%s%s%s (original = %p)", 
+                    LogMessage (log.get(), 
+                                "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)", 
                                  GetClangASTContext().getASTContext(),
                                  MakeUserID(die->GetOffset()),
                                  namespace_name,
                                  namespace_decl,
-                                 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                                 m_obj_file->GetFileSpec().GetFilename().GetCString(),
-                                 object_name ? "(" : "",
-                                 object_name ? object_name : "",
-                                 object_name ? "(" : "",
                                  namespace_decl->getOriginalNamespace());
                 }
                 else
                 {
-                    log->Printf ("ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl * %p in %s/%s%s%s%s (original = %p)", 
-                                 GetClangASTContext().getASTContext(),
-                                 MakeUserID(die->GetOffset()),
-                                 namespace_decl,
-                                 m_obj_file->GetFileSpec().GetDirectory().GetCString(),
-                                 m_obj_file->GetFileSpec().GetFilename().GetCString(),
-                                 object_name ? "(" : "",
-                                 object_name ? object_name : "",
-                                 object_name ? "(" : "",
-                                 namespace_decl->getOriginalNamespace());
+                    LogMessage (log.get(),
+                                "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)", 
+                                GetClangASTContext().getASTContext(),
+                                MakeUserID(die->GetOffset()),
+                                namespace_decl,
+                                namespace_decl->getOriginalNamespace());
                 }
             }
 
@@ -4196,6 +4157,15 @@
                         // current type index just in case we have a forward
                         // declaration followed by an actual declarations in the
                         // DWARF. If this fails, we need to look elsewhere...
+                        if (log)
+                        {
+                            LogMessage (log.get(), 
+                                        "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is forward declaration, trying to find real type", 
+                                        this,
+                                        die->GetOffset(), 
+                                        DW_TAG_value_to_name(tag),
+                                        type_name_cstr);
+                        }
                     
                         type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
 
@@ -4209,6 +4179,16 @@
 
                         if (type_sp)
                         {
+                            if (log)
+                            {
+                                log->Printf ("SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is forward declaration, real type is 0x%8.8llx", 
+                                             this,
+                                             die->GetOffset(), 
+                                             DW_TAG_value_to_name(tag),
+                                             type_name_cstr,
+                                             type_sp->GetID());
+                            }
+
                             // We found a real definition for this type elsewhere
                             // so lets use it and cache the fact that we found
                             // a complete type for this die

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Sun Nov 27 19:45:00 2011
@@ -456,11 +456,6 @@
                             const lldb_private::ClangASTContext::TemplateParameterInfos &template_param_infos);
 
 
-    void
-    ReportError (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
-    void
-    ReportWarning (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
-    
     SymbolFileDWARFDebugMap *       m_debug_map_symfile;
     clang::TranslationUnitDecl *    m_clang_tu_decl;
     lldb_private::Flags             m_flags;

Modified: lldb/trunk/source/Symbol/SymbolFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolFile.cpp?rev=145219&r1=145218&r2=145219&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolFile.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolFile.cpp Sun Nov 27 19:45:00 2011
@@ -7,10 +7,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/lldb-private.h"
 #include "lldb/Symbol/SymbolFile.h"
+
+#include "lldb/lldb-private.h"
+#include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
+#include "lldb/Core/StreamString.h"
 #include "lldb/Symbol/ObjectFile.h"
 
 using namespace lldb_private;
@@ -68,3 +71,45 @@
     return m_obj_file->GetModule()->GetClangASTContext();
 }
 
+
+void
+SymbolFile::ReportError (const char *format, ...)
+{
+    StreamString module_description;
+    m_obj_file->GetModule()->GetDescription (&module_description, lldb::eDescriptionLevelBrief);
+    ::fprintf (stderr, "error: %s ", module_description.GetString().c_str());
+    
+    va_list args;
+    va_start (args, format);
+    vfprintf (stderr, format, args);
+    va_end (args);
+}
+
+void
+SymbolFile::ReportWarning (const char *format, ...)
+{
+    StreamString module_description;
+    m_obj_file->GetModule()->GetDescription (&module_description, lldb::eDescriptionLevelBrief);
+    ::fprintf (stderr, "warning: %s ", module_description.GetString().c_str());
+    
+    va_list args;
+    va_start (args, format);
+    vfprintf (stderr, format, args);
+    va_end (args);
+}
+
+void
+SymbolFile::LogMessage (Log *log, const char *format, ...)
+{
+    if (log)
+    {
+        StreamString log_message;
+        m_obj_file->GetModule()->GetDescription (&log_message, lldb::eDescriptionLevelBrief);
+        log_message.PutChar(' ');
+        va_list args;
+        va_start (args, format);
+        log_message.PrintfVarArg (format, args);
+        va_end (args);
+        log->PutCString (log_message.GetString().c_str());
+    }
+}





More information about the lldb-commits mailing list