]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Add description of check_debug_pub*
authorPetr Machata <pmachata@redhat.com>
Thu, 2 Sep 2010 15:11:43 +0000 (17:11 +0200)
committerPetr Machata <pmachata@redhat.com>
Thu, 2 Sep 2010 15:11:43 +0000 (17:11 +0200)
dwarflint/check_debug_pub.cc
dwarflint/dwarflint.hh

index 65710420fca728b0a92d6e7483fc3dbd669359e3..6dfa0b9dbf53ecbf64027f19a263a7e25fd70245 100644 (file)
@@ -33,30 +33,71 @@ namespace
   class check_debug_pub
     : public check<check_debug_pub<sec_id> >
   {
+  protected:
     typedef section<sec_id> section_t;
     section_t *_m_sec;
     elf_file const &_m_file;
+    check_debug_info *_m_cus;
 
-    bool check_pub_structural (check_debug_info *cus);
+    bool check_pub_structural ();
 
   public:
+    check_debug_pub (checkstack &stack, dwarflint &lint)
+      : _m_sec (lint.check (stack, _m_sec))
+      , _m_file (_m_sec->file)
+      , _m_cus (lint.toplev_check (stack, _m_cus))
+    {
+      check_pub_structural ();
+    }
+  };
+
+  class check_debug_pubnames
+    : public check_debug_pub<sec_pubnames>
+  {
+  public:
+    check_debug_pubnames (checkstack &stack, dwarflint &lint)
+      : check_debug_pub<sec_pubnames> (stack, lint)
+    {}
+
     static checkdescriptor const &descriptor () {
-      static std::string name
-       = (std::string)"check_"
-       + (section_t::descriptor ().name () + 1);
       static checkdescriptor cd
-       (checkdescriptor::create (name.c_str ())
-        .prereq<typeof (*_m_sec)> ());
+       (checkdescriptor::create ("check_debug_pubnames")
+        .prereq<typeof (*_m_sec)> ()
+        .prereq<check_debug_info> ()
+        .description (
+"Checks for low-level structure of .debug_pubnames.  In addition it\n"
+"checks:\n"
+" - for garbage inside padding\n"
+" - that relocations are valid.  In ET_REL files that certain fields\n"
+"   are relocated\n"
+"Furthermore, if .debug_info is valid, it checks:\n"
+" - that references point to actual CUs and DIEs\n"
+" - that there's only one pub section per CU\n"));
       return cd;
     }
+  };
+  reg<check_debug_pubnames> reg_debug_pubnames;
 
-    check_debug_pub (checkstack &stack, dwarflint &lint)
-      : _m_sec (lint.check (stack, _m_sec))
-      , _m_file (_m_sec->file)
-    {
-      check_pub_structural (lint.toplev_check<check_debug_info> (stack));
+  class check_debug_pubtypes
+    : public check_debug_pub<sec_pubtypes>
+  {
+  public:
+    check_debug_pubtypes (checkstack &stack, dwarflint &lint)
+      : check_debug_pub<sec_pubtypes> (stack, lint)
+    {}
+
+    static checkdescriptor const &descriptor () {
+      static checkdescriptor cd
+       (checkdescriptor::create ("check_debug_pubtypes")
+        .prereq<typeof (*_m_sec)> ()
+        .prereq<check_debug_info> ()
+        .description (
+"Checks for low-level structure of .debug_pubtypes.  In addition it\n"
+"makes the same checks as check_debug_pubnames.\n"));
+      return cd;
     }
   };
+  reg<check_debug_pubtypes> reg_debug_pubtypes;
 
   template <class A, class B>
   struct where xwhere (A a, B b)
@@ -67,7 +108,7 @@ namespace
 
 template <section_id sec_id>
 bool
-check_debug_pub<sec_id>::check_pub_structural (check_debug_info *cus)
+check_debug_pub<sec_id>::check_pub_structural ()
 {
   struct read_ctx ctx;
   read_ctx_init (&ctx, _m_sec->sect.data, _m_file.other_byte_order);
@@ -132,10 +173,11 @@ check_debug_pub<sec_id>::check_pub_structural (check_debug_info *cus)
                    PRI_LACK_RELOCATION, "debug info offset");
 
       struct cu *cu = NULL;
-      if (cus != NULL && (cu = cus->find_cu (cu_offset)) == NULL)
+      if (_m_cus != NULL && (cu = _m_cus->find_cu (cu_offset)) == NULL)
        wr_error (where)
          << "unresolved reference to " << pri::CU (cu_offset)
          << '.' << std::endl;
+      // xxx this can be checked even without CU
       if (cu != NULL)
        {
          where.ref = &cu->head->where;
@@ -192,6 +234,7 @@ check_debug_pub<sec_id>::check_pub_structural (check_debug_info *cus)
              goto next;
            }
 
+         // xxx read_ctx_read_str???
          uint8_t c;
          do
            if (!read_ctx_read_ubyte (&sub_ctx, &c))
@@ -229,9 +272,3 @@ check_debug_pub<sec_id>::check_pub_structural (check_debug_info *cus)
 
   return retval;
 }
-
-namespace
-{
-  reg<check_debug_pub<sec_pubnames> > reg_debug_pubnames;
-  reg<check_debug_pub<sec_pubtypes> > reg_debug_pubtypes;
-}
index 9acd2f7675c289a51795506255a73fd12fc1c61f..0e30d2a185460999497dbc6ea1c365f24419b23f 100644 (file)
@@ -125,7 +125,8 @@ public:
   }
 
   template <class T>
-  T *toplev_check (checkstack &stack, T *tag = NULL);
+  T *toplev_check (checkstack &stack,
+                  __attribute__ ((unused)) T *fake = NULL);
 };
 
 #endif//DWARFLINT_HH