From: Petr Machata Date: Tue, 21 Sep 2010 16:09:54 +0000 (+0200) Subject: dwarflint: Move read_size_extra to readctx module X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07d03fef037743c898dc2fc05b99548dd2cf809e;p=thirdparty%2Felfutils.git dwarflint: Move read_size_extra to readctx module --- diff --git a/dwarflint/low.c b/dwarflint/low.c index 9872d4aef..a5aafb5d4 100644 --- a/dwarflint/low.c +++ b/dwarflint/low.c @@ -134,35 +134,6 @@ cu_find_cu (struct cu *cu_chain, uint64_t offset) return NULL; } -bool -read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep, - int *offset_sizep, struct where *wh) -{ - if (size32 == DWARF3_LENGTH_64_BIT) - { - if (!read_ctx_read_8ubyte (ctx, sizep)) - { - wr_error (wh, ": can't read 64bit CU length.\n"); - return false; - } - - *offset_sizep = 8; - } - else if (size32 >= DWARF3_LENGTH_MIN_ESCAPE_CODE) - { - wr_error (wh, ": unrecognized CU length escape value: " - "%" PRIx32 ".\n", size32); - return false; - } - else - { - *sizep = size32; - *offset_sizep = 4; - } - - return true; -} - bool check_zero_padding (struct read_ctx *ctx, enum message_category category, diff --git a/dwarflint/low.h b/dwarflint/low.h index 13f2a9f76..16a74ac5b 100644 --- a/dwarflint/low.h +++ b/dwarflint/low.h @@ -1,5 +1,5 @@ /* Pedantic checking of DWARF files. - Copyright (C) 2008,2009 Red Hat, Inc. + Copyright (C) 2008, 2009, 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 @@ -98,9 +98,6 @@ extern "C" extern bool address_aligned (uint64_t addr, uint64_t align); extern bool necessary_alignment (uint64_t start, uint64_t length, uint64_t align); - extern bool read_size_extra (struct read_ctx *ctx, uint32_t size32, - uint64_t *sizep, int *offset_sizep, - struct where *wh); #define PRI_NOT_ENOUGH ": not enough data for %s.\n" extern bool supported_version (unsigned version, size_t num_supported, struct where *where, ...); diff --git a/dwarflint/readctx.c b/dwarflint/readctx.c index 20666fc86..20bda8d8f 100644 --- a/dwarflint/readctx.c +++ b/dwarflint/readctx.c @@ -1,5 +1,5 @@ /* Pedantic checking of DWARF files. - Copyright (C) 2009 Red Hat, Inc. + Copyright (C) 2009, 2010 Red Hat, Inc. This file is part of Red Hat elfutils. Written by Petr Machata , 2009. @@ -26,10 +26,12 @@ #include "readctx.h" #include "low.h" +#include "../libdw/dwarf.h" #include #include #include +#include /* read_Xubyte_* is basically cut'n'paste from memory-access.h. */ union unaligned @@ -315,3 +317,32 @@ read_ctx_eof (struct read_ctx *ctx) { return !read_ctx_need_data (ctx, 1); } + +bool +read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep, + int *offset_sizep, struct where *wh) +{ + if (size32 == DWARF3_LENGTH_64_BIT) + { + if (!read_ctx_read_8ubyte (ctx, sizep)) + { + wr_error (wh, ": can't read 64bit CU length.\n"); + return false; + } + + *offset_sizep = 8; + } + else if (size32 >= DWARF3_LENGTH_MIN_ESCAPE_CODE) + { + wr_error (wh, ": unrecognized CU length escape value: " + "%" PRIx32 ".\n", size32); + return false; + } + else + { + *sizep = size32; + *offset_sizep = 4; + } + + return true; +} diff --git a/dwarflint/readctx.h b/dwarflint/readctx.h index 45afd4f10..8f7b63642 100644 --- a/dwarflint/readctx.h +++ b/dwarflint/readctx.h @@ -1,5 +1,5 @@ /* Pedantic checking of DWARF files - Copyright (C) 2009,2010 Red Hat, Inc. + Copyright (C) 2009, 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 @@ -28,6 +28,7 @@ #include #include "../libelf/libelf.h" +#include "where.h" #ifdef __cplusplus extern "C" @@ -68,12 +69,18 @@ bool read_ctx_read_2ubyte (struct read_ctx *ctx, uint16_t *ret); bool read_ctx_read_4ubyte (struct read_ctx *ctx, uint32_t *ret); bool read_ctx_read_8ubyte (struct read_ctx *ctx, uint64_t *ret); bool read_ctx_read_offset (struct read_ctx *ctx, bool dwarf64, - uint64_t *ret); + uint64_t *ret); bool read_ctx_read_var (struct read_ctx *ctx, int width, uint64_t *ret); const char *read_ctx_read_str (struct read_ctx *ctx); bool read_ctx_skip (struct read_ctx *ctx, uint64_t len); bool read_ctx_eof (struct read_ctx *ctx); +/* The following procedures build on the ones above and do their own + error reporting. */ + +bool read_size_extra (struct read_ctx *ctx, uint32_t size32, + uint64_t *sizep, int *offset_sizep, struct where *wh); + #ifdef __cplusplus } #endif