From 635d2c79530bccf218d596dc57e53304133a16f8 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Mon, 30 Nov 2009 16:39:01 +0100 Subject: [PATCH] dwarflint: Const correctness, references in a couple places --- src/dwarflint/check_debug_info.cc | 49 +++++++++++++------------- src/dwarflint/check_debug_info.hh | 10 +++--- src/dwarflint/check_debug_loc_range.cc | 12 ++++--- src/dwarflint/check_debug_loc_range.hh | 2 +- src/dwarflint/low.c | 2 +- src/dwarflint/low.h | 2 +- src/dwarflint/reloc.cc | 2 +- src/dwarflint/reloc.h | 2 +- 8 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/dwarflint/check_debug_info.cc b/src/dwarflint/check_debug_info.cc index 0359145e8..2c3601c0c 100644 --- a/src/dwarflint/check_debug_info.cc +++ b/src/dwarflint/check_debug_info.cc @@ -420,7 +420,7 @@ namespace */ int read_die_chain (dwarf_version_h ver, - struct elf_file *file, + elf_file const &file, struct read_ctx *ctx, struct cu *cu, struct abbrev_table const *abbrevs, @@ -578,7 +578,7 @@ namespace enum message_category extra_mc = mc_none; uint64_t ctx_offset = read_ctx_get_offset (ctx) + cu->head->offset; - bool type_is_rel = file->ehdr.e_type == ET_REL; + bool type_is_rel = file.ehdr.e_type == ET_REL; /* Attribute value. */ uint64_t value = 0; @@ -862,7 +862,7 @@ namespace << "unexpected relocation of " << pri::form (form) << '.' << std::endl; - relocate_one (file, reloc, rel, width, &value, &where, + relocate_one (&file, reloc, rel, width, &value, &where, reloc_target (form, it), symbolp); if (relocatedp != NULL) @@ -920,7 +920,7 @@ namespace << std::endl; else check_range_relocations (mc_die_other, &where, - file, + &file, low_pc_symbol, high_pc_symbol, "DW_AT_low_pc and DW_AT_high_pc"); } @@ -951,14 +951,20 @@ namespace } } +read_cu_headers::read_cu_headers (dwarflint &lint) + : _m_sec_info (lint.check (_m_sec_info)) + , cu_headers (read_info_headers (&_m_sec_info->file, + &_m_sec_info->sect, + _m_sec_info->reldata ())) +{ +} + bool -check_debug_info::check_cu_structural (struct elf_file *file, - struct read_ctx *ctx, +check_debug_info::check_cu_structural (struct read_ctx *ctx, struct cu *const cu, Elf_Data *strings, struct coverage *strings_coverage, - struct relocation_data *reloc, - struct cu_coverage *cu_coverage) + struct relocation_data *reloc) { check_debug_abbrev::abbrev_map const &abbrev_tables = _m_abbrevs->abbrevs; @@ -986,10 +992,10 @@ check_debug_info::check_cu_structural (struct elf_file *file, WIPE (local_die_refs); cu->cudie_offset = read_ctx_get_offset (ctx) + cu->head->offset; - if (read_die_chain (ver, file, ctx, cu, &abbrevs, strings, + if (read_die_chain (ver, _m_file, ctx, cu, &abbrevs, strings, &local_die_refs, strings_coverage, (reloc != NULL && reloc->size > 0) ? reloc : NULL, - cu_coverage) < 0) + &cu_cov) < 0) { _m_abbr_skip.push_back (abbrevs.offset); retval = false; @@ -1001,20 +1007,13 @@ check_debug_info::check_cu_structural (struct elf_file *file, return retval; } -read_cu_headers::read_cu_headers (dwarflint &lint) - : _m_sec_info (lint.check (_m_sec_info)) - , cu_headers (read_info_headers (&_m_sec_info->file, - &_m_sec_info->sect, - _m_sec_info->reldata ())) -{ -} - void -check_debug_info::check_info_structural (struct elf_file *file, - Elf_Data *strings) +check_debug_info::check_info_structural () { std::vector const &cu_headers = _m_cu_headers->cu_headers; sec &sec = _m_sec_info->sect; + Elf_Data *const strings = _m_sec_str->sect.data; + struct ref_record die_refs; WIPE (die_refs); @@ -1032,7 +1031,7 @@ check_debug_info::check_info_structural (struct elf_file *file, relocation_reset (reloc); struct read_ctx ctx; - read_ctx_init (&ctx, sec.data, file->other_byte_order); + read_ctx_init (&ctx, sec.data, _m_file.other_byte_order); for (std::vector ::const_iterator it = cu_headers.begin (); it != cu_headers.end (); ++it) { @@ -1057,9 +1056,8 @@ check_debug_info::check_info_structural (struct elf_file *file, read_ctx_init_sub (&cu_ctx, &ctx, ctx.ptr, cu_end); cu_ctx.ptr += head.head_size; - if (!check_cu_structural (file, &cu_ctx, &cur, - strings, strings_coverage, reloc, - &cu_cov)) + if (!check_cu_structural (&cu_ctx, &cur, + strings, strings_coverage, reloc)) { success = false; break; @@ -1145,11 +1143,12 @@ check_debug_info::check_debug_info (dwarflint &lint) : _m_sec_info (lint.check (_m_sec_info)) , _m_sec_abbrev (lint.check (_m_sec_abbrev)) , _m_sec_str (lint.check (_m_sec_str)) + , _m_file (_m_sec_info->file) , _m_abbrevs (lint.check (_m_abbrevs)) , _m_cu_headers (lint.check (_m_cu_headers)) { memset (&cu_cov, 0, sizeof (cu_cov)); - check_info_structural (&_m_sec_info->file, _m_sec_str->sect.data); + check_info_structural (); // re-link CUs so that they form a chain again. This is to // interface with C-level code. The last CU's next is NULL, so we diff --git a/src/dwarflint/check_debug_info.hh b/src/dwarflint/check_debug_info.hh index 709f76c87..844bc5381 100644 --- a/src/dwarflint/check_debug_info.hh +++ b/src/dwarflint/check_debug_info.hh @@ -47,6 +47,7 @@ class check_debug_info section *_m_sec_info; section *_m_sec_abbrev; section *_m_sec_str; + elf_file const &_m_file; check_debug_abbrev *_m_abbrevs; read_cu_headers *_m_cu_headers; @@ -54,16 +55,13 @@ class check_debug_info // validation. Check for unused abbrevs should be skipped. std::vector< ::Dwarf_Off> _m_abbr_skip; - bool check_cu_structural (struct elf_file *file, - struct read_ctx *ctx, + bool check_cu_structural (struct read_ctx *ctx, struct cu *const cu, Elf_Data *strings, struct coverage *strings_coverage, - struct relocation_data *reloc, - struct cu_coverage *cu_coverage); + struct relocation_data *reloc); - void check_info_structural (elf_file *file, - Elf_Data *strings); + void check_info_structural (); public: // The check pass adds all low_pc/high_pc ranges loaded from DIE diff --git a/src/dwarflint/check_debug_loc_range.cc b/src/dwarflint/check_debug_loc_range.cc index 23ccdbaec..797bf1754 100644 --- a/src/dwarflint/check_debug_loc_range.cc +++ b/src/dwarflint/check_debug_loc_range.cc @@ -491,13 +491,15 @@ namespace if (!read_ctx_read_2ubyte (&ctx, &len)) { - wr_error (&where, ": can't read length of location expression.\n"); + wr_error (where) + << "can't read length of location expression." + << std::endl; return false; } /* location expression itself */ uint64_t expr_start = read_ctx_get_offset (&ctx); - if (!check_location_expression (file, &ctx, cu, expr_start, + if (!check_location_expression (*file, &ctx, cu, expr_start, &sec->rel, len, &where)) return false; uint64_t expr_end = read_ctx_get_offset (&ctx); @@ -821,7 +823,7 @@ namespace } bool - op_read_form (struct elf_file *file, + op_read_form (struct elf_file const &file, struct read_ctx *ctx, struct cu *cu, uint64_t init_off, @@ -857,7 +859,7 @@ namespace where, skip_mismatched))) { if (!isblock) - relocate_one (file, reloc, rel, + relocate_one (&file, reloc, rel, cu->head->address_size, valuep, where, reloc_target_loc (opcode), NULL); else @@ -874,7 +876,7 @@ namespace } bool -check_location_expression (struct elf_file *file, +check_location_expression (elf_file const &file, struct read_ctx *parent_ctx, struct cu *cu, uint64_t init_off, diff --git a/src/dwarflint/check_debug_loc_range.hh b/src/dwarflint/check_debug_loc_range.hh index 9a31c764b..086c455e0 100644 --- a/src/dwarflint/check_debug_loc_range.hh +++ b/src/dwarflint/check_debug_loc_range.hh @@ -59,7 +59,7 @@ struct hole_info DATA->data has to point at d_buf of section in question. */ extern bool found_hole (uint64_t start, uint64_t length, void *data); -extern bool check_location_expression (struct elf_file *file, +extern bool check_location_expression (elf_file const &file, struct read_ctx *parent_ctx, struct cu *cu, uint64_t init_off, diff --git a/src/dwarflint/low.c b/src/dwarflint/low.c index d83676c96..a4b0fc59c 100644 --- a/src/dwarflint/low.c +++ b/src/dwarflint/low.c @@ -213,7 +213,7 @@ supported_version (unsigned version, void check_range_relocations (enum message_category cat, struct where *where, - struct elf_file *file, + struct elf_file const *file, GElf_Sym *begin_symbol, GElf_Sym *end_symbol, const char *description) diff --git a/src/dwarflint/low.h b/src/dwarflint/low.h index f15df275f..db46b98b8 100644 --- a/src/dwarflint/low.h +++ b/src/dwarflint/low.h @@ -154,7 +154,7 @@ extern "C" struct addr_record *line_tables); extern void check_range_relocations (enum message_category cat, struct where *where, - struct elf_file *file, + struct elf_file const *file, GElf_Sym *begin_symbol, GElf_Sym *end_symbol, const char *description); diff --git a/src/dwarflint/reloc.cc b/src/dwarflint/reloc.cc index f58d26867..7b7660f71 100644 --- a/src/dwarflint/reloc.cc +++ b/src/dwarflint/reloc.cc @@ -93,7 +93,7 @@ relocation_skip_rest (struct relocation_data *reloc, which case we failed or didn't get around to obtain the symbol from symbol table, or non-NULL, in which case the symbol was initialized. */ void -relocate_one (struct elf_file *file, +relocate_one (struct elf_file const *file, struct relocation_data *reloc, struct relocation *rel, unsigned width, uint64_t *value, diff --git a/src/dwarflint/reloc.h b/src/dwarflint/reloc.h index ae5f8292f..42e4f0e54 100644 --- a/src/dwarflint/reloc.h +++ b/src/dwarflint/reloc.h @@ -84,7 +84,7 @@ extern "C" void relocation_skip_rest (struct relocation_data *reloc, enum section_id id); - void relocate_one (struct elf_file *file, + void relocate_one (struct elf_file const *file, struct relocation_data *reloc, struct relocation *rel, unsigned width, uint64_t *value, -- 2.47.3