[diffoscope] 01/01: Split readelf --debug-dump output when examining ELF files

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Jan 31 14:20:06 CET 2016


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository diffoscope.

commit 746bbd0f627cc107c7115a4ba98ea409f49d15df
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sun Jan 31 14:11:15 2016 +0100

    Split readelf --debug-dump output when examining ELF files
    
    Based on a patch by Dhole.
---
 diffoscope/comparators/elf.py | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index edc8f2c..d33ef81 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -118,12 +118,31 @@ class RedaelfVersionInfo(Readelf):
 
 
 class ReadelfDebugDump(Readelf):
+    def __new__(cls, *args, **kwargs):
+        # Find the section group from the class name
+        debug_section_group = cls.__name__[len('ReadelfDebugDump_'):]
+        if debug_section_group:
+            return ReadelfDebugDump(debug_section_group, *args, **kwargs)
+        else:
+            return super(Readelf, cls).__new__(cls)
+
+    def __init__(self, debug_section_group, *args, **kwargs):
+        self._debug_section_group = debug_section_group
+        super().__init__(*args, **kwargs)
+
     def readelf_options(self):
-        return ['--debug-dump']
+        return ['--debug-dump=%s' % self._debug_section_group]
 
-    @staticmethod
-    def should_skip_section(section_name, section_type):
-        return section_name.startswith('.debug_') or section_name.startswith('.zdebug_')
+
+DEBUG_SECTION_GROUPS = ['rawline', 'info', 'abbrev', 'pubnames', 'aranges',
+                        'macro', 'frames', 'loc', 'ranges', 'pubtypes',
+                        'trace_info', 'trace_abbrev', 'trace_aranges',
+                        'gdb_index']
+
+
+READELF_DEBUG_DUMP_COMMANDS = \
+    [ type('ReadelfDebugDump_%s' % section_group, (ReadelfDebugDump,), {})
+      for section_group in  DEBUG_SECTION_GROUPS ]
 
 
 class ReadElfSection(Readelf):
@@ -199,11 +218,11 @@ READELF_COMMANDS = [ReadelfFileHeader,
                     ReadelfDynamic,
                     ReadelfNotes,
                     RedaelfVersionInfo,
-                    ReadelfDebugDump,
                    ]
 
+
 def _compare_elf_data(path1, path2):
-    return [Difference.from_command(cmd, path1, path2) for cmd in READELF_COMMANDS]
+    return [Difference.from_command(cmd, path1, path2) for cmd in READELF_COMMANDS + READELF_DEBUG_DUMP_COMMANDS]
 
 
 def _should_skip_section(name, type):
@@ -211,6 +230,10 @@ def _should_skip_section(name, type):
         if cmd.should_skip_section(name, type):
             logger.debug('skipping section %s, covered by %s', name, cmd)
             return True
+    if name.startswith('.debug') or name.startswith('.zdebug'):
+        # section .debug_str looks much nicer with `readelf --string-dump`
+        # the rest is handled by READELF_DEBUG_DUMP_COMMANDS
+        return name != '.debug_str'
     return False
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list