kbaladurin updated this revision to Diff 140628.
kbaladurin added a comment.

@davide thank you! I've updated diff. Yes, I need somebody to commit this, so I 
haven't commit access.


https://reviews.llvm.org/D44998

Files:
  include/lldb/Core/Section.h
  lit/Modules/elf-code-section.yaml
  packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile
  
packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py
  packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
  source/Core/Section.cpp
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  tools/lldb-test/lldb-test.cpp

Index: tools/lldb-test/lldb-test.cpp
===================================================================
--- tools/lldb-test/lldb-test.cpp
+++ tools/lldb-test/lldb-test.cpp
@@ -212,6 +212,8 @@
       auto S = Sections->GetSectionAtIndex(I);
       assert(S);
       Printer.formatLine("Index: {0}", I);
+      Printer.formatLine("Type: {0}",
+                         Section::GetSectionTypeAsCString(S->GetType()));
       Printer.formatLine("Name: {0}", S->GetName().GetStringRef());
       Printer.formatLine("VM size: {0}", S->GetByteSize());
       Printer.formatLine("File size: {0}", S->GetFileSize());
Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1947,6 +1947,16 @@
         sect_type = kalimbaSectionType(m_header, header);
       }
 
+      // In common case ELF code section can have arbitrary name (for example,
+      // we can specify it using section attribute for particular function) so
+      // assume that section is a code section if it has SHF_EXECINSTR flag set
+      // and has SHT_PROGBITS type.
+      if (eSectionTypeOther == sect_type &&
+          llvm::ELF::SHT_PROGBITS == header.sh_type &&
+          (header.sh_flags & SHF_EXECINSTR)) {
+        sect_type = eSectionTypeCode;
+      }
+
       const uint32_t target_bytes_size =
           (eSectionTypeData == sect_type || eSectionTypeZeroFill == sect_type)
               ? m_arch_spec.GetDataByteSize()
Index: source/Core/Section.cpp
===================================================================
--- source/Core/Section.cpp
+++ source/Core/Section.cpp
@@ -27,7 +27,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
-static const char *GetSectionTypeAsCString(lldb::SectionType sect_type) {
+const char *Section::GetSectionTypeAsCString(lldb::SectionType sect_type) {
   switch (sect_type) {
   case eSectionTypeInvalid:
     return "invalid";
Index: packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/main.c
@@ -0,0 +1,8 @@
+__attribute__((section("__codesection")))
+int f(int a) {
+  return a + 1; // Set break point at this line.
+}
+
+int main() {
+  return f(10);
+}
Index: packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/TestBreakpointThumbCodesection.py
@@ -0,0 +1,35 @@
+"""
+Test that breakpoints correctly work in an thumb function in an arbitrary
+named codesection.
+"""
+from __future__ import print_function
+
+
+import lldb
+import os
+import time
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestBreakpointThumbCodesection(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    @skipIf(archs=no_match(["arm"]))
+    def test_breakpoint(self):
+        self.build()
+        exe = self.getBuildArtifact("a.out")
+        line = line_number('main.c', '// Set break point at this line.')
+
+        self.runCmd("target create %s" % exe)
+        bpid = lldbutil.run_break_set_by_file_and_line(self, "main.c", line)
+
+        self.runCmd("run")
+
+        self.assertIsNotNone(lldbutil.get_one_thread_stopped_at_breakpoint_id(
+            self.process(), bpid), "Process is not stopped at breakpoint")
+
+        self.process().Continue()
+        self.assertEqual(self.process().GetState(), lldb.eStateExited, PROCESS_EXITED)
Index: packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile
===================================================================
--- /dev/null
+++ packages/Python/lldbsuite/test/arm/breakpoint-thumb-codesection/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../make
+
+C_SOURCES := main.c
+CFLAGS_EXTRAS = -mthumb
+
+include $(LEVEL)/Makefile.rules
\ No newline at end of file
Index: lit/Modules/elf-code-section.yaml
===================================================================
--- /dev/null
+++ lit/Modules/elf-code-section.yaml
@@ -0,0 +1,25 @@
+# RUN: yaml2obj %s > %t
+# RUN: lldb-test module-sections %t | FileCheck %s
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_386
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    Content:         deadbeefbaadf00d
+  - Name:            __codesection
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    Content:         deadbeefbaadf00d
+
+# CHECK: Index: 1
+# CHECK-NEXT: Type: code
+# CHECK-NEXT: Name: .text
+
+# CHECK: Index: 2
+# CHECK-NEXT: Type: code
+# CHECK-NEXT: Name: __codesection
\ No newline at end of file
Index: include/lldb/Core/Section.h
===================================================================
--- include/lldb/Core/Section.h
+++ include/lldb/Core/Section.h
@@ -251,6 +251,8 @@
 
   void SetIsRelocated(bool b) { m_relocated = b; }
 
+  static const char *GetSectionTypeAsCString(lldb::SectionType sect_type);
+
 protected:
   ObjectFile *m_obj_file;   // The object file that data for this section should
                             // be read from
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to