[Lldb-commits] [lldb] r274585 - Warning about debugging optimized code was not happening without dSYMs. Now it works for DWARF in .o files on Darwin.

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 5 16:01:21 PDT 2016


Author: gclayton
Date: Tue Jul  5 18:01:20 2016
New Revision: 274585

URL: http://llvm.org/viewvc/llvm-project?rev=274585&view=rev
Log:
Warning about debugging optimized code was not happening without dSYMs. Now it works for DWARF in .o files on Darwin.

I changed "m_is_optimized" in lldb_private::CompileUnit over to be a lldb::LazyBool so that it can be set to eLazyBoolCalculate if it needs to be parsed later. With SymbolFileDWARFDebugMap, we don't actually open the DWARF in the .o files for each compile unit until later, and we can't tell if a compile unit is optimized ahead of time. So to avoid pulling in all .o right away just so we can answer the questions of "is this compile unit optimized" we defer it until a point where we will have the compile unit parsed.

<rdar://problem/26068360> 

Modified:
    lldb/trunk/include/lldb/Symbol/CompileUnit.h
    lldb/trunk/include/lldb/Symbol/SymbolFile.h
    lldb/trunk/include/lldb/Symbol/SymbolVendor.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
    lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
    lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
    lldb/trunk/source/Symbol/CompileUnit.cpp
    lldb/trunk/source/Symbol/SymbolVendor.cpp

Modified: lldb/trunk/include/lldb/Symbol/CompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/CompileUnit.h?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/CompileUnit.h (original)
+++ lldb/trunk/include/lldb/Symbol/CompileUnit.h Tue Jul  5 18:01:20 2016
@@ -68,11 +68,16 @@ public:
     ///     of this compile unit.
     ///
     /// @param[in] is_optimized
-    ///     true if this compile unit was compiled with optimization.
+    ///     A value that can initialized with eLazyBoolYes, eLazyBoolNo
+    ///     or eLazyBoolCalculate. If set to eLazyBoolCalculate, then
+    ///     an extra call into SymbolVendor will be made to calculate if
+    ///     the compile unit is optimized will be made when
+    ///     CompileUnit::GetIsOptimized() is called.
     ///
     /// @see lldb::LanguageType
     //------------------------------------------------------------------
-    CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const char *pathname, lldb::user_id_t uid, lldb::LanguageType language, bool is_optimized);
+    CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const char *pathname, lldb::user_id_t uid,
+                lldb::LanguageType language, lldb_private::LazyBool is_optimized);
 
     //------------------------------------------------------------------
     /// Construct with a module, file spec, UID and language.
@@ -103,11 +108,16 @@ public:
     ///     of this compile unit.
     ///
     /// @param[in] is_optimized
-    ///     true if this compile unit was compiled with optimization.
+    ///     A value that can initialized with eLazyBoolYes, eLazyBoolNo
+    ///     or eLazyBoolCalculate. If set to eLazyBoolCalculate, then
+    ///     an extra call into SymbolVendor will be made to calculate if
+    ///     the compile unit is optimized will be made when
+    ///     CompileUnit::GetIsOptimized() is called.
     ///
     /// @see lldb::LanguageType
     //------------------------------------------------------------------
-    CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &file_spec, lldb::user_id_t uid, lldb::LanguageType language, bool is_optimized);
+    CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &file_spec, lldb::user_id_t uid,
+                lldb::LanguageType language, lldb_private::LazyBool is_optimized);
 
     //------------------------------------------------------------------
     /// Destructor
@@ -446,7 +456,7 @@ protected:
     std::unique_ptr<LineTable> m_line_table_ap; ///< Line table that will get parsed on demand.
     DebugMacrosSP m_debug_macros_sp; ///< Debug macros that will get parsed on demand.
     lldb::VariableListSP m_variables; ///< Global and static variable list that will get parsed on demand.
-    bool       m_is_optimized; /// eLazyBoolYes if this compile unit was compiled with optimization.
+    lldb_private::LazyBool m_is_optimized; /// eLazyBoolYes if this compile unit was compiled with optimization.
 
 private:
     enum

Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Tue Jul  5 18:01:20 2016
@@ -127,6 +127,11 @@ public:
     virtual bool            ParseCompileUnitLineTable (const SymbolContext& sc) = 0;
     virtual bool            ParseCompileUnitDebugMacros (const SymbolContext& sc) = 0;
     virtual bool            ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files) = 0;
+    virtual bool
+    ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc)
+    {
+        return false;
+    }
     virtual bool            ParseImportedModules (const SymbolContext &sc, std::vector<ConstString> &imported_modules) = 0;
     virtual size_t          ParseFunctionBlocks (const SymbolContext& sc) = 0;
     virtual size_t          ParseTypes (const SymbolContext& sc) = 0;

Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Tue Jul  5 18:01:20 2016
@@ -68,7 +68,10 @@ public:
     virtual bool
     ParseCompileUnitSupportFiles (const SymbolContext& sc,
                                   FileSpecList& support_files);
-    
+
+    virtual bool
+    ParseCompileUnitIsOptimized(const SymbolContext &sc);
+
     virtual bool
     ParseImportedModules (const SymbolContext &sc,
                           std::vector<ConstString> &imported_modules);

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=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Tue Jul  5 18:01:20 2016
@@ -915,12 +915,8 @@ SymbolFileDWARF::ParseCompileUnit (DWARF
                         LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0));
 
                         bool is_optimized = dwarf_cu->GetIsOptimized ();
-                        cu_sp.reset(new CompileUnit (module_sp,
-                                                     dwarf_cu,
-                                                     cu_file_spec, 
-                                                     dwarf_cu->GetID(),
-                                                     cu_language,
-                                                     is_optimized));
+                        cu_sp.reset(new CompileUnit(module_sp, dwarf_cu, cu_file_spec, dwarf_cu->GetID(), cu_language,
+                                                    is_optimized ? eLazyBoolYes : eLazyBoolNo));
                         if (cu_sp)
                         {
                             // If we just created a compile unit with an invalid file spec, try and get the
@@ -1070,7 +1066,17 @@ SymbolFileDWARF::ParseCompileUnitSupport
 }
 
 bool
-SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
+SymbolFileDWARF::ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc)
+{
+    DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
+    if (dwarf_cu)
+        return dwarf_cu->GetIsOptimized();
+    return false;
+}
+
+bool
+SymbolFileDWARF::ParseImportedModules(const lldb_private::SymbolContext &sc,
+                                      std::vector<lldb_private::ConstString> &imported_modules)
 {
     assert (sc.comp_unit);
     DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);

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=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Tue Jul  5 18:01:20 2016
@@ -137,8 +137,11 @@ public:
                                   lldb_private::FileSpecList& support_files) override;
 
     bool
-    ParseImportedModules (const lldb_private::SymbolContext &sc,
-                          std::vector<lldb_private::ConstString> &imported_modules) override;
+    ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
+
+    bool
+    ParseImportedModules(const lldb_private::SymbolContext &sc,
+                         std::vector<lldb_private::ConstString> &imported_modules) override;
 
     size_t
     ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override;

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Tue Jul  5 18:01:20 2016
@@ -637,13 +637,9 @@ SymbolFileDWARFDebugMap::ParseCompileUni
                 // zero in each .o file since each .o file can only have
                 // one compile unit for now.
                 lldb::user_id_t cu_id = 0;
-                m_compile_unit_infos[cu_idx].compile_unit_sp.reset(new CompileUnit (m_obj_file->GetModule(),
-                                                                                    NULL,
-                                                                                    so_file_spec,
-                                                                                    cu_id,
-                                                                                    eLanguageTypeUnknown,
-                                                                                    false));
-            
+                m_compile_unit_infos[cu_idx].compile_unit_sp.reset(new CompileUnit(
+                    m_obj_file->GetModule(), NULL, so_file_spec, cu_id, eLanguageTypeUnknown, eLazyBoolCalculate));
+
                 if (m_compile_unit_infos[cu_idx].compile_unit_sp)
                 {
                     // Let our symbol vendor know about this compile unit
@@ -727,7 +723,16 @@ SymbolFileDWARFDebugMap::ParseCompileUni
 }
 
 bool
-SymbolFileDWARFDebugMap::ParseImportedModules (const SymbolContext &sc, std::vector<ConstString> &imported_modules)
+SymbolFileDWARFDebugMap::ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc)
+{
+    SymbolFileDWARF *oso_dwarf = GetSymbolFile(sc);
+    if (oso_dwarf)
+        return oso_dwarf->ParseCompileUnitIsOptimized(sc);
+    return false;
+}
+
+bool
+SymbolFileDWARFDebugMap::ParseImportedModules(const SymbolContext &sc, std::vector<ConstString> &imported_modules)
 {
     SymbolFileDWARF *oso_dwarf = GetSymbolFile (sc);
     if (oso_dwarf)

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Tue Jul  5 18:01:20 2016
@@ -65,6 +65,8 @@ public:
     bool            ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc) override;
     bool            ParseCompileUnitDebugMacros (const lldb_private::SymbolContext& sc) override;
     bool            ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList &support_files) override;
+    bool
+    ParseCompileUnitIsOptimized(const lldb_private::SymbolContext &sc) override;
     bool            ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) override;
     size_t          ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override;
     size_t          ParseTypes (const lldb_private::SymbolContext& sc) override;

Modified: lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp Tue Jul  5 18:01:20 2016
@@ -614,7 +614,7 @@ SymbolFilePDB::ParseCompileUnitForSymInd
         lang = TranslateLanguage(details->getLanguage());
 
     // Don't support optimized code for now, DebugInfoPDB does not return this information.
-    bool optimized = false;
+    LazyBool optimized = eLazyBoolNo;
     auto result = std::make_shared<CompileUnit>(m_obj_file->GetModule(), nullptr, path.c_str(), id, lang, optimized);
     m_comp_units.insert(std::make_pair(id, result));
     return result;

Modified: lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp Tue Jul  5 18:01:20 2016
@@ -153,7 +153,8 @@ SymbolFileSymtab::ParseCompileUnitAtInde
     {
         const Symbol *cu_symbol = m_obj_file->GetSymtab()->SymbolAtIndex(m_source_indexes[idx]);
         if (cu_symbol)
-            cu_sp.reset(new CompileUnit (m_obj_file->GetModule(), NULL, cu_symbol->GetName().AsCString(), 0, eLanguageTypeUnknown, false));
+            cu_sp.reset(new CompileUnit(m_obj_file->GetModule(), NULL, cu_symbol->GetName().AsCString(), 0,
+                                        eLanguageTypeUnknown, eLazyBoolNo));
     }
     return cu_sp;
 }

Modified: lldb/trunk/source/Symbol/CompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CompileUnit.cpp?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/CompileUnit.cpp (original)
+++ lldb/trunk/source/Symbol/CompileUnit.cpp Tue Jul  5 18:01:20 2016
@@ -17,36 +17,40 @@
 using namespace lldb;
 using namespace lldb_private;
 
-CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const char *pathname, const lldb::user_id_t cu_sym_id, lldb::LanguageType language, bool is_optimized) :
-    ModuleChild(module_sp),
-    FileSpec (pathname, false),
-    UserID(cu_sym_id),
-    m_user_data (user_data),
-    m_language (language),
-    m_flags (0),
-    m_functions (),
-    m_support_files (),
-    m_line_table_ap (),
-    m_variables(),
-    m_is_optimized (is_optimized)
+CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const char *pathname,
+                         const lldb::user_id_t cu_sym_id, lldb::LanguageType language,
+                         lldb_private::LazyBool is_optimized)
+    : ModuleChild(module_sp),
+      FileSpec(pathname, false),
+      UserID(cu_sym_id),
+      m_user_data(user_data),
+      m_language(language),
+      m_flags(0),
+      m_functions(),
+      m_support_files(),
+      m_line_table_ap(),
+      m_variables(),
+      m_is_optimized(is_optimized)
 {
     if (language != eLanguageTypeUnknown)
         m_flags.Set(flagsParsedLanguage);
     assert(module_sp);
 }
 
-CompileUnit::CompileUnit (const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &fspec, const lldb::user_id_t cu_sym_id, lldb::LanguageType language, bool is_optimized) :
-    ModuleChild(module_sp),
-    FileSpec (fspec),
-    UserID(cu_sym_id),
-    m_user_data (user_data),
-    m_language (language),
-    m_flags (0),
-    m_functions (),
-    m_support_files (),
-    m_line_table_ap (),
-    m_variables(),
-    m_is_optimized (is_optimized)
+CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data, const FileSpec &fspec,
+                         const lldb::user_id_t cu_sym_id, lldb::LanguageType language,
+                         lldb_private::LazyBool is_optimized)
+    : ModuleChild(module_sp),
+      FileSpec(fspec),
+      UserID(cu_sym_id),
+      m_user_data(user_data),
+      m_language(language),
+      m_flags(0),
+      m_functions(),
+      m_support_files(),
+      m_line_table_ap(),
+      m_variables(),
+      m_is_optimized(is_optimized)
 {
     if (language != eLanguageTypeUnknown)
         m_flags.Set(flagsParsedLanguage);
@@ -468,6 +472,17 @@ CompileUnit::ResolveSymbolContext
 bool
 CompileUnit::GetIsOptimized ()
 {
+    if (m_is_optimized == eLazyBoolCalculate)
+    {
+        m_is_optimized = eLazyBoolNo;
+        if (SymbolVendor *symbol_vendor = GetModule()->GetSymbolVendor())
+        {
+            SymbolContext sc;
+            CalculateSymbolContext(&sc);
+            if (symbol_vendor->ParseCompileUnitIsOptimized(sc))
+                m_is_optimized = eLazyBoolYes;
+        }
+    }
     return m_is_optimized;
 }
 

Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=274585&r1=274584&r2=274585&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Tue Jul  5 18:01:20 2016
@@ -211,8 +211,20 @@ SymbolVendor::ParseCompileUnitSupportFil
 }
 
 bool
-SymbolVendor::ParseImportedModules (const SymbolContext &sc,
-                                    std::vector<ConstString> &imported_modules)
+SymbolVendor::ParseCompileUnitIsOptimized(const SymbolContext &sc)
+{
+    ModuleSP module_sp(GetModule());
+    if (module_sp)
+    {
+        std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+        if (m_sym_file_ap.get())
+            return m_sym_file_ap->ParseCompileUnitIsOptimized(sc);
+    }
+    return false;
+}
+
+bool
+SymbolVendor::ParseImportedModules(const SymbolContext &sc, std::vector<ConstString> &imported_modules)
 {
     ModuleSP module_sp(GetModule());
     if (module_sp)




More information about the lldb-commits mailing list