From: Petr Machata Date: Mon, 11 Oct 2010 21:33:19 +0000 (+0200) Subject: dwarflint: move read_sc_value to checked_read module X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04c016170bac1cf3b3eb626f0dca41f5b938acbb;p=thirdparty%2Felfutils.git dwarflint: move read_sc_value to checked_read module --- diff --git a/dwarflint/check_debug_info.cc b/dwarflint/check_debug_info.cc index 022c71fe0..a8877f7ef 100644 --- a/dwarflint/check_debug_info.cc +++ b/dwarflint/check_debug_info.cc @@ -495,37 +495,6 @@ namespace ref_record_add (&ctx->cu->decl_file_refs, value, ctx->where); } - /// Read value depending on the form width and storage class. - bool - read_sc_value (uint64_t *valuep, form const *form, cu const *cu, - read_ctx *ctx, where *wherep) - { - form_width_t width = form->width (cu); - switch (width) - { - case fw_0: - // Who knows, DW_FORM_flag_absent might turn up one day... - assert (form->name () == DW_FORM_flag_present); - *valuep = 1; - return true; - - case fw_1: - case fw_2: - case fw_4: - case fw_8: - return read_ctx_read_var (ctx, width, valuep); - - case fw_uleb: - case fw_sleb: - return checked_read_leb128 (ctx, width, valuep, - wherep, "attribute value"); - - case fw_unknown: - ; - } - UNREACHABLE; - } - /* Returns: -1 in case of error @@ -659,7 +628,7 @@ namespace if (ver->form_class (form, attribute) == cl_indirect) { uint64_t value; - if (!read_sc_value (&value, form, cu, ctx, &where)) + if (!read_sc_value (&value, form->width (cu), ctx, &where)) return -1; form_name = value; form = check_debug_abbrev::check_form @@ -809,7 +778,7 @@ namespace } else { - if (!read_sc_value (&value, form, cu, ctx, &where)) + if (!read_sc_value (&value, form->width (cu), ctx, &where)) { // Note that for fw_uleb and fw_sleb we report the // error the second time now. diff --git a/dwarflint/checked_read.cc b/dwarflint/checked_read.cc index 131449f57..4b73152dc 100644 --- a/dwarflint/checked_read.cc +++ b/dwarflint/checked_read.cc @@ -35,6 +35,7 @@ #include "checked_read.hh" #include "messages.hh" +#include "misc.hh" bool read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep, @@ -148,3 +149,30 @@ checked_read_leb128 (read_ctx *ctx, form_width_t width, uint64_t *ret, else return checked_read_uleb128 (ctx, ret, where, what); } + +bool +read_sc_value (uint64_t *valuep, form_width_t width, + read_ctx *ctx, where const *where) +{ + switch (width) + { + case fw_0: + *valuep = 1; + return true; + + case fw_1: + case fw_2: + case fw_4: + case fw_8: + return read_ctx_read_var (ctx, width, valuep); + + case fw_uleb: + case fw_sleb: + return checked_read_leb128 (ctx, width, valuep, + where, "attribute value"); + + case fw_unknown: + ; + } + UNREACHABLE; +} diff --git a/dwarflint/checked_read.hh b/dwarflint/checked_read.hh index 612ec6977..39927e5b1 100644 --- a/dwarflint/checked_read.hh +++ b/dwarflint/checked_read.hh @@ -47,4 +47,8 @@ bool checked_read_sleb128 (read_ctx *ctx, int64_t *ret, bool checked_read_leb128 (read_ctx *ctx, form_width_t width, uint64_t *ret, where const *where, const char *what); +/// Read value depending on the form width and storage class. +bool read_sc_value (uint64_t *valuep, form_width_t width, + read_ctx *ctx, where const *where); + #endif//DWARFLINT_CHECKED_READ_HH