]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Declare template "section" using an enum type
authorPetr Machata <pmachata@redhat.com>
Thu, 19 Aug 2010 15:08:14 +0000 (17:08 +0200)
committerPetr Machata <pmachata@redhat.com>
Thu, 19 Aug 2010 15:08:14 +0000 (17:08 +0200)
* split out enum section_id to separate file to make this possible
* also define section names there

dwarflint/Makefile.am
dwarflint/section_id.cc [new file with mode: 0644]
dwarflint/section_id.h [new file with mode: 0644]
dwarflint/sections.hh
dwarflint/sections.ii
dwarflint/where.h

index a3bfed6bbe00096f8425a921876f77f588eb7a10..5056ec66a4eccac9d8695f74016dacb8978ad1cc 100644 (file)
@@ -45,6 +45,7 @@ dwarflint_SOURCES = main.cc \
                    readctx.c  readctx.h \
                    pri.cc pri.hh \
                    messages.cc messages.h \
+                   section_id.cc section_id.h \
                    where.c where.h \
                    options.cc options.h \
                    addr-record.cc addr-record.h \
diff --git a/dwarflint/section_id.cc b/dwarflint/section_id.cc
new file mode 100644 (file)
index 0000000..a9d28c6
--- /dev/null
@@ -0,0 +1,36 @@
+/* Pedantic checking of DWARF files
+   Copyright (C) 2010 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+
+   Red Hat elfutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by the
+   Free Software Foundation; version 2 of the License.
+
+   Red Hat elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with Red Hat elfutils; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+   Red Hat elfutils is an included package of the Open Invention Network.
+   An included package of the Open Invention Network is a package for which
+   Open Invention Network licensees cross-license their patents.  No patent
+   license is granted, either expressly or impliedly, by designation as an
+   included package.  Should you wish to participate in the Open Invention
+   Network licensing program, please visit www.openinventionnetwork.com
+   <http://www.openinventionnetwork.com>.  */
+
+#include "section_id.h"
+
+#include <stdlib.h>
+
+char const *section_name[] = {
+  "<invalid>",
+#define SEC(n) ".debug_"#n,
+  DEBUGINFO_SECTIONS
+  NULL
+#undef SEC
+};
diff --git a/dwarflint/section_id.h b/dwarflint/section_id.h
new file mode 100644 (file)
index 0000000..dd7bd00
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef DWARFLINT_SECTION_ID_H
+#define DWARFLINT_SECTION_ID_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define DEBUGINFO_SECTIONS \
+  SEC (info)              \
+  SEC (abbrev)            \
+  SEC (aranges)                   \
+  SEC (pubnames)          \
+  SEC (pubtypes)          \
+  SEC (str)               \
+  SEC (line)              \
+  SEC (loc)               \
+  SEC (mac)               \
+  SEC (ranges)
+
+  enum section_id
+  {
+    sec_invalid = 0,
+
+    /* Debuginfo sections:  */
+#define SEC(n) sec_##n,
+    DEBUGINFO_SECTIONS
+    count_debuginfo_sections,
+#undef SEC
+
+    /* Non-debuginfo sections:  */
+    sec_rel = count_debuginfo_sections,
+    sec_rela,
+
+    // XXX the following should really be split out to different enum
+    /* Non-sections:  */
+    sec_locexpr,       /* Not a section, but a portion of file that
+                          contains a location expression.  */
+    rel_value,         /* For relocations, this denotes that the
+                          relocation is applied to taget value, not a
+                          section offset.  */
+    rel_address,       /* Same as above, but for addresses.  */
+    rel_exec,          /* Some as above, but we expect EXEC bit.  */
+  };
+
+  extern char const *section_name[];
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif//DWARFLINT_SECTION_ID_H
index 3bd2c63dafe4f35fa576fa574f6a13d92d11d689..e12621c3a1ceca6a8e734c94e453fea71d071501 100644 (file)
@@ -53,7 +53,7 @@ public:
   }
 };
 
-template<unsigned sec_id>
+template<section_id sec_id>
 class section
   : public section_base
   , public check<section<sec_id> >
index 67f5e3f3f58a6249bc81bff39f67cf194ee2cc31..bc726d440c1e2192714c94b4fb843af69467d8e6 100644 (file)
@@ -1 +1,2 @@
-template<unsigned> class section;
+#include "section_id.h"
+template<enum section_id> class section;
index f8fd6c136236efca7985940654c3c926358e9798..feefd0547a4e3b4ddbd0a8a35e4ec25de2d80f32 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef DWARFLINT_WHERE_H
 #define DWARFLINT_WHERE_H
 
+#include "section_id.h"
+
 #include <stdint.h>
 #include <stdlib.h>
 
@@ -10,42 +12,6 @@ extern "C"
 {
 #endif
 
-#define DEBUGINFO_SECTIONS \
-  SEC (info)              \
-  SEC (abbrev)            \
-  SEC (aranges)                   \
-  SEC (pubnames)          \
-  SEC (pubtypes)          \
-  SEC (str)               \
-  SEC (line)              \
-  SEC (loc)               \
-  SEC (mac)               \
-  SEC (ranges)
-
-  enum section_id
-  {
-    sec_invalid = 0,
-
-    /* Debuginfo sections:  */
-#define SEC(n) sec_##n,
-    DEBUGINFO_SECTIONS
-    count_debuginfo_sections,
-#undef SEC
-
-    /* Non-debuginfo sections:  */
-    sec_rel = count_debuginfo_sections,
-    sec_rela,
-
-    /* Non-sections:  */
-    sec_locexpr,       /* Not a section, but a portion of file that
-                          contains a location expression.  */
-    rel_value,         /* For relocations, this denotes that the
-                          relocation is applied to taget value, not a
-                          section offset.  */
-    rel_address,       /* Same as above, but for addresses.  */
-    rel_exec,          /* Some as above, but we expect EXEC bit.  */
-  };
-
   enum where_formatting
   {
     wf_plain = 0, /* Default formatting for given section.  */