From: Roland McGrath Date: Thu, 2 Jul 2009 02:27:29 +0000 (-0700) Subject: missing files X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdbe23862600c7d1b34906430e0c2586ebd00edb;p=thirdparty%2Felfutils.git missing files --- diff --git a/tests/dwarf_edit.cc b/tests/dwarf_edit.cc new file mode 100644 index 000000000..7c4b3ecf7 --- /dev/null +++ b/tests/dwarf_edit.cc @@ -0,0 +1,65 @@ +/* Test program for elfutils::dwarf_edit basics. + 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 + . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "c++/dwarf_edit" + +using namespace elfutils; +using namespace std; + +#include "print-die.hh" + + +int +main (int argc, char **argv) +{ + unsigned int depth; + print_die_main (argc, argv, depth); + + dwarf_edit f; + + dwarf_edit::compile_unit &cu = f.add_unit (); + + cu.attributes ()[DW_AT_name].source_file () = "source-file.c"; + + cu.add_entry (DW_TAG_subprogram) + .attributes ()[DW_AT_name].identifier () = "foo"; + + print_file ("consed", f, depth); + + return 0; +} diff --git a/tests/print-die.hh b/tests/print-die.hh new file mode 100644 index 000000000..c4ff8a25f --- /dev/null +++ b/tests/print-die.hh @@ -0,0 +1,75 @@ + +static void +print_die_main (int &argc, char **&argv, unsigned int &depth) +{ + /* Set locale. */ + (void) setlocale (LC_ALL, ""); + + /* Make sure the message catalog can be found. */ + (void) bindtextdomain (PACKAGE_TARNAME, LOCALEDIR); + + /* Initialize the message catalog. */ + (void) textdomain (PACKAGE_TARNAME); + + cout << hex << setiosflags (ios::showbase); + + depth = 0; + if (argc > 1 && sscanf (argv[1], "--depth=%u", &depth) == 1) + { + --argc; + ++argv; + } +} + +template +static void +print_die (const typename file::debug_info_entry &die, + unsigned int indent, unsigned int limit) +{ + string prefix (indent, ' '); + const string tag = dwarf::tags::name (die.tag ()); + + cout << prefix << "<" << tag << " offset=[" << die.offset () << "]"; + + for (typename file::debug_info_entry::attributes_type::const_iterator i + = die.attributes ().begin (); i != die.attributes ().end (); ++i) + cout << " " << to_string (*i); + + if (die.has_children ()) + { + if (limit != 0 && indent >= limit) + { + cout << ">...\n"; + return; + } + + cout << ">\n"; + + for (typename file::debug_info_entry::children_type::const_iterator i + = die.children ().begin (); i != die.children ().end (); ++i) + print_die (*i, indent + 1, limit); + + cout << prefix << "\n"; + } + else + cout << "/>\n"; +} + +template +static void +print_cu (const typename file::compile_unit &cu, const unsigned int limit) +{ + print_die (static_cast (cu), + 1, limit); +} + +template +static void +print_file (const char *name, const file &dw, const unsigned int limit) +{ + cout << name << ":\n"; + + for (typename file::compile_units::const_iterator i + = dw.compile_units ().begin (); i != dw.compile_units ().end (); ++i) + print_cu (*i, limit); +}