From 761d70da2cd9999fb28df8dcbdee87307db9ec0f Mon Sep 17 00:00:00 2001
From: Serge Lamikhov-Center <to_serge@users.sourceforge.net>
Date: Sat, 22 Aug 2020 23:10:11 -0700
Subject: [PATCH] Add dump function for .modinfo section

---
 elfio/elfio_dump.hpp         | 25 +++++++++++++++++++++++++
 examples/elfdump/elfdump.cpp |  1 +
 2 files changed, 26 insertions(+)

diff --git a/elfio/elfio_dump.hpp b/elfio/elfio_dump.hpp
index ce90942..65af0c6 100644
--- a/elfio/elfio_dump.hpp
+++ b/elfio/elfio_dump.hpp
@@ -671,6 +671,31 @@ class dump
         }
     }
 
+    //------------------------------------------------------------------------------
+    static void modinfo( std::ostream& out, const elfio& reader )
+    {
+        Elf_Half no = reader.sections.size();
+        for ( Elf_Half i = 0; i < no; ++i ) { // For all sections
+            section* sec = reader.sections[i];
+            if ( ".modinfo" == sec->get_name() ) { // Look for the section
+                out << "Section .modinfo" << std::endl;
+
+                const_modinfo_section_accessor modinfo( sec );
+                for ( auto i = 0; i < modinfo.get_attribute_num(); i++ ) {
+                    std::string field;
+                    std::string value;
+                    if ( modinfo.get_attribute( i, field, value ) ) {
+                        out << "  " << std::setw( 20 ) << field
+                            << std::setw( 0 ) <<  " = " << value << std::endl;
+                    }
+                }
+
+                out << std::endl;
+                break;
+            }
+        }
+    }
+
     //------------------------------------------------------------------------------
     static void
     note( std::ostream& out, int no, Elf_Word type, const std::string& name )
diff --git a/examples/elfdump/elfdump.cpp b/examples/elfdump/elfdump.cpp
index 466adc9..af724ba 100644
--- a/examples/elfdump/elfdump.cpp
+++ b/examples/elfdump/elfdump.cpp
@@ -51,6 +51,7 @@ int main( int argc, char** argv )
     dump::segment_headers( std::cout, reader );
     dump::symbol_tables( std::cout, reader );
     dump::notes( std::cout, reader );
+    dump::modinfo( std::cout, reader );
     dump::dynamic_tags( std::cout, reader );
     dump::section_datas( std::cout, reader );
     dump::segment_datas( std::cout, reader );