aadsm updated this revision to Diff 290113.
aadsm added a comment.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Check lowest code address instead of checking if the section is code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87173/new/

https://reviews.llvm.org/D87173

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp

Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===================================================================
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -35,14 +35,16 @@
 #include "lldb/Utility/ArchSpec.h"
 #include "lldb/Utility/DataEncoder.h"
 #include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Reproducer.h"
 #include "lldb/Utility/StreamString.h"
 
 using namespace lldb;
 using namespace lldb_private;
 
 class SymbolFileDWARFTests : public testing::Test {
-  SubsystemRAII<FileSystem, HostInfo, ObjectFilePECOFF, ObjectFileMachO,
-                SymbolFileDWARF, TypeSystemClang, SymbolFilePDB>
+  SubsystemRAII<repro::Reproducer, FileSystem, HostInfo, ObjectFilePECOFF,
+                ObjectFileMachO, SymbolFileDWARF, TypeSystemClang,
+                SymbolFilePDB>
       subsystems;
 
 public:
@@ -367,3 +369,27 @@
   ASSERT_NE(section_sp.get(), nullptr);
   EXPECT_EQ(section_sp->GetType(), eSectionTypeCode);
 }
+
+TEST_F(SymbolFileDWARFTests, EnsureAllParseFunctionsExistInCodeSections) {
+  auto ExpectedFile = TestFile::fromYamlFile("test-invalid-offsets.yaml");
+  ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+  lldb::ModuleSP module_sp =
+      std::make_shared<Module>(ExpectedFile->moduleSpec());
+  SymbolFile *symfile = module_sp->GetSymbolFile();
+  ASSERT_NE(symfile, nullptr);
+
+  SymbolContextList sc_list;
+  RegularExpression regex(".");
+  symfile->FindFunctions(regex, false, sc_list);
+  ASSERT_EQ(sc_list.GetSize(), 1U);
+
+  SymbolContext sc;
+  sc_list.GetContextAtIndex(0, sc);
+  EXPECT_STREQ(sc.function->GetName().AsCString(), "main");
+
+  auto section_sp =
+      sc.function->GetAddressRange().GetBaseAddress().GetSection();
+  ASSERT_NE(section_sp.get(), nullptr);
+  EXPECT_EQ(section_sp->GetType(), eSectionTypeCode);
+}
Index: lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
===================================================================
--- lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
+++ lldb/unittests/SymbolFile/DWARF/Inputs/test-invalid-addresses.yaml
@@ -420,8 +420,8 @@
             - Value:           0x0000000100000F80
             - Value:           0x0000000000000030
         - AbbrCode:        0x00000002
-          Values:
-            - Value:           0x0000000100000F80
+          Values: # DW_TAG_subprogram foo
+            - Value:           0x0000000000000F80 # DW_AT_low_pc points to invalid loc
             - Value:           0x000000000000000B
             - Value:           0x0000000000000001
               BlockData:       [ 0x56 ]
@@ -432,7 +432,7 @@
             - Value:           0x000000000000006F
             - Value:           0x0000000000000001
         - AbbrCode:        0x00000003
-          Values:
+          Values: # DW_TAG_subprogram main
             - Value:           0x0000000100000F90
             - Value:           0x0000000000000020
             - Value:           0x0000000000000001
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -779,7 +779,8 @@
   if (!dwarf_ast)
     return nullptr;
 
-  return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die);
+  return dwarf_ast->ParseFunctionFromDWARF(comp_unit, die,
+                                           m_first_code_address);
 }
 
 lldb::addr_t SymbolFileDWARF::FixupAddress(lldb::addr_t file_addr) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -47,7 +47,8 @@
 
   lldb_private::Function *
   ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit,
-                         const DWARFDIE &die) override;
+                         const DWARFDIE &die,
+                         lldb::addr_t first_code_address) override;
 
   bool
   CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type,
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2226,8 +2226,10 @@
   return enumerators_added;
 }
 
-Function *DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
-                                                      const DWARFDIE &die) {
+Function *
+DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
+                                            const DWARFDIE &die,
+                                            lldb::addr_t first_code_address) {
   DWARFRangeList func_ranges;
   const char *name = nullptr;
   const char *mangled = nullptr;
@@ -2262,7 +2264,9 @@
         func_range.SetByteSize(highest_func_addr - lowest_func_addr);
     }
 
-    if (func_range.GetBaseAddress().IsValid()) {
+    if (lowest_func_addr >= first_code_address &&
+        lowest_func_addr != LLDB_INVALID_ADDRESS &&
+        lowest_func_addr <= highest_func_addr) {
       Mangled func_name;
       if (mangled)
         func_name.SetValue(ConstString(mangled), true);
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -32,7 +32,8 @@
 
   virtual lldb_private::Function *
   ParseFunctionFromDWARF(lldb_private::CompileUnit &comp_unit,
-                         const DWARFDIE &die) = 0;
+                         const DWARFDIE &die,
+                         lldb::addr_t first_code_address) = 0;
 
   virtual bool
   CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type,
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to