]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
missing files
authorRoland McGrath <roland@redhat.com>
Thu, 2 Jul 2009 02:27:29 +0000 (19:27 -0700)
committerRoland McGrath <roland@redhat.com>
Thu, 2 Jul 2009 02:27:29 +0000 (19:27 -0700)
tests/dwarf_edit.cc [new file with mode: 0644]
tests/print-die.hh [new file with mode: 0644]

diff --git a/tests/dwarf_edit.cc b/tests/dwarf_edit.cc
new file mode 100644 (file)
index 0000000..7c4b3ec
--- /dev/null
@@ -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
+   <http://www.openinventionnetwork.com>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <error.h>
+#include <fcntl.h>
+#include <clocale>
+#include <cstdio>
+#include <libintl.h>
+#include <ostream>
+#include <iomanip>
+
+#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 (file)
index 0000000..c4ff8a2
--- /dev/null
@@ -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<typename file>
+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<file> (*i, indent + 1, limit);
+
+      cout << prefix << "</" << tag << ">\n";
+    }
+  else
+    cout << "/>\n";
+}
+
+template<typename file>
+static void
+print_cu (const typename file::compile_unit &cu, const unsigned int limit)
+{
+  print_die<file> (static_cast<const typename file::debug_info_entry &> (cu),
+                  1, limit);
+}
+
+template<typename file>
+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<file> (*i, limit);
+}