From c22fa123d877d4fcbd203a480b114478cc05c37c Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Mon, 30 Nov 2009 14:08:43 +0100 Subject: dwarflint: Rename file to match class name --- src/Makefile.am | 2 +- src/dwarflint/check_dups_abstract_origin.cc | 2 +- src/dwarflint/check_expected_trees.cc | 2 +- src/dwarflint/check_highlevel.cc | 142 ---------------------------- src/dwarflint/check_matching_ranges.cc | 2 +- src/dwarflint/check_range_out_of_scope.cc | 2 +- src/dwarflint/checks-high.hh | 76 --------------- src/dwarflint/highlevel_check.cc | 139 +++++++++++++++++++++++++++ src/dwarflint/highlevel_check.hh | 76 +++++++++++++++ 9 files changed, 220 insertions(+), 223 deletions(-) delete mode 100644 src/dwarflint/check_highlevel.cc delete mode 100644 src/dwarflint/checks-high.hh create mode 100644 src/dwarflint/highlevel_check.cc create mode 100644 src/dwarflint/highlevel_check.hh (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index b8fda985..85c066c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -95,7 +95,7 @@ dwarflint_SOURCES = dwarfstrings.c \ dwarflint/reloc.cc dwarflint/reloc.h \ dwarflint/tables.cc dwarflint/tables.hh dwarflint/tables.h \ dwarflint/all-dies-it.hh \ - dwarflint/check_highlevel.cc dwarflint/checks-high.hh \ + dwarflint/highlevel_check.cc dwarflint/highlevel_check.hh \ dwarflint/check_debug_abbrev.cc \ dwarflint/check_debug_info.cc dwarflint/check_debug_info.hh dwarflint/check_debug_info.ii \ dwarflint/check_debug_line.cc \ diff --git a/src/dwarflint/check_dups_abstract_origin.cc b/src/dwarflint/check_dups_abstract_origin.cc index 5c3b3218..8e980a36 100644 --- a/src/dwarflint/check_dups_abstract_origin.cc +++ b/src/dwarflint/check_dups_abstract_origin.cc @@ -34,7 +34,7 @@ # include #endif -#include "checks-high.hh" +#include "highlevel_check.hh" #include "dwarfstrings.h" #include "all-dies-it.hh" #include "pri.hh" diff --git a/src/dwarflint/check_expected_trees.cc b/src/dwarflint/check_expected_trees.cc index 3c385acd..51e980b1 100644 --- a/src/dwarflint/check_expected_trees.cc +++ b/src/dwarflint/check_expected_trees.cc @@ -3,7 +3,7 @@ #endif #include "check_debug_info.hh" -#include "checks-high.hh" +#include "highlevel_check.hh" #include "expected.hh" #include "dwarfstrings.h" #include "../libdw/c++/dwarf-knowledge.cc" diff --git a/src/dwarflint/check_highlevel.cc b/src/dwarflint/check_highlevel.cc deleted file mode 100644 index e387d5b2..00000000 --- a/src/dwarflint/check_highlevel.cc +++ /dev/null @@ -1,142 +0,0 @@ -/* Initialization of high-level check context - Copyright (C) 2009 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 - . */ - - // xxx this will throw an exception on or - // failure. We need to catch it and convert to check_base::failed. - -#include "checks-high.hh" // xxx rename - -namespace -{ - inline bool failed (void *ptr) { return ptr == NULL; } - inline bool failed (int i) { return i < 0; } - - template - inline T - throw_if_failed (T x, char const *msg, - char const *(*errmsgcb) (int) = NULL) - { - if (unlikely (failed (x))) - { - std::stringstream ss; - ss << msg; - if (errmsgcb != NULL) - ss << ": " << errmsgcb (-1); - ss << '.'; - wr_error () << ss.str () << std::endl; - throw check_base::failed (); - } - return x; - } - - Dwfl *open_dwfl () __attribute__ ((nonnull, malloc)); - Dwarf *open_dwarf (Dwfl *dwfl, int fd) __attribute__ ((nonnull, malloc)); - - Dwfl * - open_dwfl () - { - static class my_callbacks - : public Dwfl_Callbacks - { - // Stub libdwfl callback, only the ELF handle already open is ever used. - static int - find_no_debuginfo (Dwfl_Module *mod __attribute__ ((unused)), - void **userdata __attribute__ ((unused)), - const char *modname __attribute__ ((unused)), - Dwarf_Addr base __attribute__ ((unused)), - const char *file_name __attribute__ ((unused)), - const char *debuglink_file __attribute__ ((unused)), - GElf_Word debuglink_crc __attribute__ ((unused)), - char **debuginfo_file_name __attribute__ ((unused))) - { - return -1; - } - - public: - my_callbacks () - { - section_address = dwfl_offline_section_address; - find_debuginfo = find_no_debuginfo; - } - } cbs; - - return throw_if_failed (dwfl_begin (&cbs), - "Couldn't initialize DWFL"); - } - - char const * - mystrerror (int i) - { - if (i == -1) - i = errno; - return strerror (i); - } - - Dwarf * - open_dwarf (Dwfl *dwfl, char const *fname, int fd) - { - dwfl_report_begin (dwfl); - - // Dup FD for dwfl to consume. - int dwfl_fd - = throw_if_failed (dup (fd), "Error: dup", mystrerror); - - Dwfl_Module *mod - = throw_if_failed (dwfl_report_offline (dwfl, fname, fname, dwfl_fd), - "Couldn't add DWFL module", dwfl_errmsg); - dwfl_report_end (dwfl, NULL, NULL); - Dwarf_Addr bias; - throw_if_failed (dwfl_module_getelf (mod, &bias), - "Couldn't open ELF.", dwfl_errmsg); - return throw_if_failed (dwfl_module_getdwarf (mod, &bias), - "Couldn't obtain DWARF descriptor", dwfl_errmsg); - } - - elfutils::dwarf - open_hl_dwarf (Dwarf *dw) - { - try - { - return dw; - } - catch (...) - { - wr_error () - << "Couldn't initialize high-level DWARF descriptor." << std::endl; - throw check_base::failed (); - } - } -} - -open_highlevel_dwarf::open_highlevel_dwarf (dwarflint &lint) - : _m_dwfl (open_dwfl ()) - , _m_dw (open_dwarf (_m_dwfl, lint.fname (), lint.fd ())) - , dw (open_hl_dwarf (_m_dw)) -{} - -open_highlevel_dwarf::~open_highlevel_dwarf () -{ - dwfl_end (_m_dwfl); -} diff --git a/src/dwarflint/check_matching_ranges.cc b/src/dwarflint/check_matching_ranges.cc index 95903070..a9bb20e5 100644 --- a/src/dwarflint/check_matching_ranges.cc +++ b/src/dwarflint/check_matching_ranges.cc @@ -2,7 +2,7 @@ # include #endif -#include "checks-high.hh" +#include "highlevel_check.hh" #include "check_debug_loc_range.hh" using elfutils::dwarf; diff --git a/src/dwarflint/check_range_out_of_scope.cc b/src/dwarflint/check_range_out_of_scope.cc index b271fa1c..e0806582 100644 --- a/src/dwarflint/check_range_out_of_scope.cc +++ b/src/dwarflint/check_range_out_of_scope.cc @@ -2,7 +2,7 @@ # include #endif -#include "checks-high.hh" +#include "highlevel_check.hh" #include "coverage.hh" #include "pri.hh" #include "check_debug_loc_range.hh" diff --git a/src/dwarflint/checks-high.hh b/src/dwarflint/checks-high.hh deleted file mode 100644 index 1d558250..00000000 --- a/src/dwarflint/checks-high.hh +++ /dev/null @@ -1,76 +0,0 @@ -/* Pedantic checking of DWARF files. - Copyright (C) 2009 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 - . */ - -#ifndef DWARFLINT_CHECKS_HIGH_HH -#define DWARFLINT_CHECKS_HIGH_HH - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "checks-low.hh" -#include "config.h" -#include "c++/dwarf" -#include "../libdwfl/libdwfl.h" - -class open_highlevel_dwarf - : public check -{ - Dwfl *const _m_dwfl; - Dwarf *const _m_dw; -public: - elfutils::dwarf const dw; - explicit open_highlevel_dwarf (dwarflint &lint); - ~open_highlevel_dwarf (); -}; - -template -class highlevel_check - : public check > -{ - open_highlevel_dwarf *_m_loader; -public: - elfutils::dwarf const &dw; - - explicit highlevel_check (dwarflint &lint) - : _m_loader (lint.check (_m_loader)) - , dw (_m_loader->dw) - { - if (!do_high_level) - throw check_base::unscheduled (); - } -}; - -template -inline where -to_where (T const &die) -{ - where ret = WHERE (sec_info, NULL); - where_reset_1 (&ret, 0); - where_reset_2 (&ret, die.offset ()); - return ret; -} - -#endif//DWARFLINT_CHECKS_HIGH_HH diff --git a/src/dwarflint/highlevel_check.cc b/src/dwarflint/highlevel_check.cc new file mode 100644 index 00000000..87c64b95 --- /dev/null +++ b/src/dwarflint/highlevel_check.cc @@ -0,0 +1,139 @@ +/* Initialization of high-level check context + Copyright (C) 2009 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 + . */ + +#include "highlevel_check.hh" + +namespace +{ + inline bool failed (void *ptr) { return ptr == NULL; } + inline bool failed (int i) { return i < 0; } + + template + inline T + throw_if_failed (T x, char const *msg, + char const *(*errmsgcb) (int) = NULL) + { + if (unlikely (failed (x))) + { + std::stringstream ss; + ss << msg; + if (errmsgcb != NULL) + ss << ": " << errmsgcb (-1); + ss << '.'; + wr_error () << ss.str () << std::endl; + throw check_base::failed (); + } + return x; + } + + Dwfl *open_dwfl () __attribute__ ((nonnull, malloc)); + Dwarf *open_dwarf (Dwfl *dwfl, int fd) __attribute__ ((nonnull, malloc)); + + Dwfl * + open_dwfl () + { + static class my_callbacks + : public Dwfl_Callbacks + { + // Stub libdwfl callback, only the ELF handle already open is ever used. + static int + find_no_debuginfo (Dwfl_Module *mod __attribute__ ((unused)), + void **userdata __attribute__ ((unused)), + const char *modname __attribute__ ((unused)), + Dwarf_Addr base __attribute__ ((unused)), + const char *file_name __attribute__ ((unused)), + const char *debuglink_file __attribute__ ((unused)), + GElf_Word debuglink_crc __attribute__ ((unused)), + char **debuginfo_file_name __attribute__ ((unused))) + { + return -1; + } + + public: + my_callbacks () + { + section_address = dwfl_offline_section_address; + find_debuginfo = find_no_debuginfo; + } + } cbs; + + return throw_if_failed (dwfl_begin (&cbs), + "Couldn't initialize DWFL"); + } + + char const * + mystrerror (int i) + { + if (i == -1) + i = errno; + return strerror (i); + } + + Dwarf * + open_dwarf (Dwfl *dwfl, char const *fname, int fd) + { + dwfl_report_begin (dwfl); + + // Dup FD for dwfl to consume. + int dwfl_fd + = throw_if_failed (dup (fd), "Error: dup", mystrerror); + + Dwfl_Module *mod + = throw_if_failed (dwfl_report_offline (dwfl, fname, fname, dwfl_fd), + "Couldn't add DWFL module", dwfl_errmsg); + dwfl_report_end (dwfl, NULL, NULL); + Dwarf_Addr bias; + throw_if_failed (dwfl_module_getelf (mod, &bias), + "Couldn't open ELF.", dwfl_errmsg); + return throw_if_failed (dwfl_module_getdwarf (mod, &bias), + "Couldn't obtain DWARF descriptor", dwfl_errmsg); + } + + elfutils::dwarf + open_hl_dwarf (Dwarf *dw) + { + try + { + return dw; + } + catch (...) + { + wr_error () + << "Couldn't initialize high-level DWARF descriptor." << std::endl; + throw check_base::failed (); + } + } +} + +open_highlevel_dwarf::open_highlevel_dwarf (dwarflint &lint) + : _m_dwfl (open_dwfl ()) + , _m_dw (open_dwarf (_m_dwfl, lint.fname (), lint.fd ())) + , dw (open_hl_dwarf (_m_dw)) +{} + +open_highlevel_dwarf::~open_highlevel_dwarf () +{ + dwfl_end (_m_dwfl); +} diff --git a/src/dwarflint/highlevel_check.hh b/src/dwarflint/highlevel_check.hh new file mode 100644 index 00000000..1d558250 --- /dev/null +++ b/src/dwarflint/highlevel_check.hh @@ -0,0 +1,76 @@ +/* Pedantic checking of DWARF files. + Copyright (C) 2009 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 + . */ + +#ifndef DWARFLINT_CHECKS_HIGH_HH +#define DWARFLINT_CHECKS_HIGH_HH + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "checks-low.hh" +#include "config.h" +#include "c++/dwarf" +#include "../libdwfl/libdwfl.h" + +class open_highlevel_dwarf + : public check +{ + Dwfl *const _m_dwfl; + Dwarf *const _m_dw; +public: + elfutils::dwarf const dw; + explicit open_highlevel_dwarf (dwarflint &lint); + ~open_highlevel_dwarf (); +}; + +template +class highlevel_check + : public check > +{ + open_highlevel_dwarf *_m_loader; +public: + elfutils::dwarf const &dw; + + explicit highlevel_check (dwarflint &lint) + : _m_loader (lint.check (_m_loader)) + , dw (_m_loader->dw) + { + if (!do_high_level) + throw check_base::unscheduled (); + } +}; + +template +inline where +to_where (T const &die) +{ + where ret = WHERE (sec_info, NULL); + where_reset_1 (&ret, 0); + where_reset_2 (&ret, die.offset ()); + return ret; +} + +#endif//DWARFLINT_CHECKS_HIGH_HH -- cgit v1.2.3