From 4404d817465dfb42881c98d458ec3952d987e1ed Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Thu, 2 Sep 2010 17:11:43 +0200 Subject: [PATCH] dwarflint: Add description of check_debug_pub* --- dwarflint/check_debug_pub.cc | 75 +++++++++++++++++++++++++++--------- dwarflint/dwarflint.hh | 3 +- 2 files changed, 58 insertions(+), 20 deletions(-) diff --git a/dwarflint/check_debug_pub.cc b/dwarflint/check_debug_pub.cc index 65710420f..6dfa0b9db 100644 --- a/dwarflint/check_debug_pub.cc +++ b/dwarflint/check_debug_pub.cc @@ -33,30 +33,71 @@ namespace class check_debug_pub : public check > { + protected: typedef section 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 + { + public: + check_debug_pubnames (checkstack &stack, dwarflint &lint) + : check_debug_pub (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 ()); + (checkdescriptor::create ("check_debug_pubnames") + .prereq () + .prereq () + .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 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 (stack)); + class check_debug_pubtypes + : public check_debug_pub + { + public: + check_debug_pubtypes (checkstack &stack, dwarflint &lint) + : check_debug_pub (stack, lint) + {} + + static checkdescriptor const &descriptor () { + static checkdescriptor cd + (checkdescriptor::create ("check_debug_pubtypes") + .prereq () + .prereq () + .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 reg_debug_pubtypes; template struct where xwhere (A a, B b) @@ -67,7 +108,7 @@ namespace template bool -check_debug_pub::check_pub_structural (check_debug_info *cus) +check_debug_pub::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::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::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::check_pub_structural (check_debug_info *cus) return retval; } - -namespace -{ - reg > reg_debug_pubnames; - reg > reg_debug_pubtypes; -} diff --git a/dwarflint/dwarflint.hh b/dwarflint/dwarflint.hh index 9acd2f767..0e30d2a18 100644 --- a/dwarflint/dwarflint.hh +++ b/dwarflint/dwarflint.hh @@ -125,7 +125,8 @@ public: } template - T *toplev_check (checkstack &stack, T *tag = NULL); + T *toplev_check (checkstack &stack, + __attribute__ ((unused)) T *fake = NULL); }; #endif//DWARFLINT_HH -- 2.47.3