expected-at.cc expected.hh \
coverage.cc coverage.h \
readctx.c readctx.h \
+ checked_read.cc checked_read.h \
pri.cc pri.hh \
messages.cc messages.h \
section_id.cc section_id.h \
/* 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.
Red Hat elfutils is free software; you can redistribute it and/or modify
#include "pri.hh"
#include "tables.hh"
#include "sections.hh"
+#include "checked_read.h"
#include <dwarf.h>
#include <sstream>
free (it->second.abbr);
}
}
+
+int
+check_sibling_form (dwarf_version_h ver, uint64_t form)
+{
+ if (!dwver_form_allowed (ver, DW_AT_sibling, form))
+ return -2;
+ else if (form == DW_FORM_ref_addr)
+ return -1;
+ else
+ return 0;
+}
+
/* Low-level checking of .debug_abbrev.
- Copyright (C) 2009 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
~check_debug_abbrev ();
};
+int check_sibling_form (dwarf_version_h ver, uint64_t form);
+
#endif//DWARFLINT_CHECK_DEBUG_ABBREV_HH
#include "check_debug_info.hh"
#include "check_debug_loc_range.hh"
#include "cu_coverage.hh"
+#include "checked_read.h"
checkdescriptor const *
check_debug_aranges::descriptor ()
#include "pri.hh"
#include "option.hh"
#include "sections.hh"
+#include "checked_read.h"
#include "check_debug_loc_range.hh"
#include "check_debug_abbrev.hh"
#include "check_debug_info.hh"
#include "check_debug_info.hh"
#include "sections.hh"
#include "pri.hh"
+#include "checked_read.h"
#include <dwarf.h>
#include "../libdw/known-dwarf.h"
#include "check_debug_loc_range.hh"
#include "check_debug_info.hh"
#include "sections.hh"
+#include "checked_read.h"
#include "../src/dwarf-opcodes.h"
#include "pri.hh"
#include "check_debug_info.hh"
#include "sections.hh"
#include "pri.hh"
-
-namespace
-{
- template <class A, class B>
- struct where xwhere (A a, B b)
- {
- return WHERE (a, b);
- }
-}
+#include "checked_read.h"
template<section_id sec_id>
check_debug_pub<sec_id>::check_debug_pub (checkstack &stack, dwarflint &lint)
--- /dev/null
+/* Pedantic checking of DWARF files
+ Copyright (C) 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
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <dwarf.h>
+#include "checked_read.h"
+#include "messages.h"
+
+bool
+read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep,
+ int *offset_sizep, struct where *where)
+{
+ if (size32 == DWARF3_LENGTH_64_BIT)
+ {
+ if (!read_ctx_read_8ubyte (ctx, sizep))
+ {
+ wr_error (where, ": can't read 64bit CU length.\n");
+ return false;
+ }
+
+ *offset_sizep = 8;
+ }
+ else if (size32 >= DWARF3_LENGTH_MIN_ESCAPE_CODE)
+ {
+ wr_error (where, ": unrecognized CU length escape value: "
+ "%" PRIx32 ".\n", size32);
+ return false;
+ }
+ else
+ {
+ *sizep = size32;
+ *offset_sizep = 4;
+ }
+
+ return true;
+}
+
+bool
+read_address_size (struct read_ctx *ctx,
+ bool addr_64,
+ int *address_sizep,
+ struct where const *where)
+{
+ uint8_t address_size;
+ if (!read_ctx_read_ubyte (ctx, &address_size))
+ {
+ wr_error (where, ": can't read address size.\n");
+ return false;
+ }
+
+ if (address_size != 4 && address_size != 8)
+ {
+ /* Keep going. Deduce the address size from ELF header, and try
+ to parse it anyway. */
+ wr_error (where,
+ ": invalid address size: %d (only 4 or 8 allowed).\n",
+ address_size);
+ address_size = addr_64 ? 8 : 4;
+ }
+ else if ((address_size == 8) != addr_64)
+ /* Keep going, we may still be able to parse it. */
+ wr_error (where,
+ ": CU reports address size of %d in %d-bit ELF.\n",
+ address_size, addr_64 ? 64 : 32);
+
+ *address_sizep = address_size;
+ return true;
+}
+
+bool
+checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
+ struct where *where, const char *what)
+{
+ const unsigned char *ptr = ctx->ptr;
+ int st = read_ctx_read_uleb128 (ctx, ret);
+ if (st < 0)
+ wr_error (where, ": can't read %s.\n", what);
+ else if (st > 0)
+ {
+ char buf[19]; // 16 hexa digits, "0x", terminating zero
+ sprintf (buf, "%#" PRIx64, *ret);
+ wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
+ }
+ return st >= 0;
+}
+
+bool
+checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
+ struct where *where, const char *what)
+{
+ const unsigned char *ptr = ctx->ptr;
+ int st = read_ctx_read_sleb128 (ctx, ret);
+ if (st < 0)
+ wr_error (where, ": can't read %s.\n", what);
+ else if (st > 0)
+ {
+ char buf[20]; // sign, "0x", 16 hexa digits, terminating zero
+ int64_t val = *ret;
+ sprintf (buf, "%s%#" PRIx64, val < 0 ? "-" : "", val < 0 ? -val : val);
+ wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
+ }
+ return st >= 0;
+}
--- /dev/null
+/* Pedantic checking of DWARF files
+ Copyright (C) 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
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ Red Hat elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with Red Hat elfutils; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
+
+ Red Hat elfutils is an included package of the Open Invention Network.
+ An included package of the Open Invention Network is a package for which
+ Open Invention Network licensees cross-license their patents. No patent
+ license is granted, either expressly or impliedly, by designation as an
+ included package. Should you wish to participate in the Open Invention
+ Network licensing program, please visit www.openinventionnetwork.com
+ <http://www.openinventionnetwork.com>. */
+
+#ifndef DWARFLINT_CHECKED_READ_HH
+#define DWARFLINT_CHECKED_READ_HH
+
+#include "readctx.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+bool read_size_extra (struct read_ctx *ctx, uint32_t size32, uint64_t *sizep,
+ int *offset_sizep, struct where *where);
+
+bool read_address_size (struct read_ctx *ctx,
+ bool addr_64,
+ int *address_sizep,
+ struct where const *where);
+
+bool checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
+ struct where *where, const char *what);
+
+bool checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
+ struct where *where, const char *what);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif//DWARFLINT_CHECKED_READ_HH
return address_aligned (start + length, align) && length < align;
}
-bool
-checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
- struct where *where, const char *what)
-{
- const unsigned char *ptr = ctx->ptr;
- int st = read_ctx_read_uleb128 (ctx, ret);
- if (st < 0)
- wr_error (where, ": can't read %s.\n", what);
- else if (st > 0)
- {
- char buf[19]; // 16 hexa digits, "0x", terminating zero
- sprintf (buf, "%#" PRIx64, *ret);
- wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
- }
- return st >= 0;
-}
-
-bool
-checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
- struct where *where, const char *what)
-{
- const unsigned char *ptr = ctx->ptr;
- int st = read_ctx_read_sleb128 (ctx, ret);
- if (st < 0)
- wr_error (where, ": can't read %s.\n", what);
- else if (st > 0)
- {
- char buf[20]; // sign, "0x", 16 hexa digits, terminating zero
- int64_t val = *ret;
- sprintf (buf, "%s%#" PRIx64, val < 0 ? "-" : "", val < 0 ? -val : val);
- wr_format_leb128_message (where, what, buf, ptr, ctx->ptr);
- }
- return st >= 0;
-}
-
-int
-check_sibling_form (dwarf_version_h ver, uint64_t form)
-{
- if (!dwver_form_allowed (ver, DW_AT_sibling, form))
- return -2;
- else if (form == DW_FORM_ref_addr)
- return -1;
- else
- return 0;
-}
-
bool
is_location_attrib (uint64_t name)
{
extern int check_sibling_form (dwarf_version_h ver, uint64_t form);
extern bool is_location_attrib (uint64_t name);
- bool checked_read_uleb128 (struct read_ctx *ctx, uint64_t *ret,
- struct where *where, const char *what);
- bool checked_read_sleb128 (struct read_ctx *ctx, int64_t *ret,
- struct where *where, const char *what);
-
struct abbrev_attrib
{
struct where where;
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 *where)
-{
- if (size32 == DWARF3_LENGTH_64_BIT)
- {
- if (!read_ctx_read_8ubyte (ctx, sizep))
- {
- wr_error (where, ": can't read 64bit CU length.\n");
- return false;
- }
-
- *offset_sizep = 8;
- }
- else if (size32 >= DWARF3_LENGTH_MIN_ESCAPE_CODE)
- {
- wr_error (where, ": unrecognized CU length escape value: "
- "%" PRIx32 ".\n", size32);
- return false;
- }
- else
- {
- *sizep = size32;
- *offset_sizep = 4;
- }
-
- return true;
-}
-
-bool
-read_address_size (struct read_ctx *ctx,
- bool addr_64,
- int *address_sizep,
- struct where const *where)
-{
- uint8_t address_size;
- if (!read_ctx_read_ubyte (ctx, &address_size))
- {
- wr_error (where, ": can't read address size.\n");
- return false;
- }
-
- if (address_size != 4 && address_size != 8)
- {
- /* Keep going. Deduce the address size from ELF header, and try
- to parse it anyway. */
- wr_error (where,
- ": invalid address size: %d (only 4 or 8 allowed).\n",
- address_size);
- address_size = addr_64 ? 8 : 4;
- }
- else if ((address_size == 8) != addr_64)
- /* Keep going, we may still be able to parse it. */
- wr_error (where,
- ": CU reports address size of %d in %d-bit ELF.\n",
- address_size, addr_64 ? 64 : 32);
-
- *address_sizep = address_size;
- return true;
-}
-
static void
update_off (struct read_ctx *ctx,
uint64_t *ret_off)
#include <stdbool.h>
#include "../libelf/libelf.h"
-// xxx We don't really like this one
-#include "where.h"
-
#ifdef __cplusplus
extern "C"
{
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 in addition. */
-
-bool read_size_extra (struct read_ctx *ctx, uint32_t size32,
- uint64_t *sizep, int *offset_sizep,
- struct where *where);
-
-bool read_address_size (struct read_ctx *ctx,
- bool addr_64,
- int *address_sizep,
- struct where const *where);
-
/* See if what remains in the read context is just a zero padding. If
yes, return true. If it isn't, revert the read pointer back as if
nothing had happened and return false. Furthermore, in any case,