]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
New test for dwarf_getstring.
authorMarek Polacek <mpolacek@redhat.com>
Mon, 7 Mar 2011 19:16:50 +0000 (11:16 -0800)
committerRoland McGrath <roland@redhat.com>
Mon, 7 Mar 2011 19:17:44 +0000 (11:17 -0800)
tests/ChangeLog
tests/Makefile.am
tests/dwarf-getstring.c [new file with mode: 0644]
tests/run-dwarf-getstring.sh [new file with mode: 0755]

index b079677490ded4c0a7cc283772ccf4d6aa0168cd..4ec3853c6c2a570bb6bda2036e15c1f8b6cc519e 100644 (file)
@@ -1,3 +1,9 @@
+2011-04-02  Marek Polacek  <mpolacek@redhat.com>
+
+       * dwarf-getstring.c: New test.
+       * run-dwarf-getstring.sh: And its wrapper.
+       * Makefile.am (EXTRA_DIST): Add and update all.
+
 2011-02-27  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * Makefile.am (TESTS): Add run-readelf-twofiles.sh.
index d0e4246564b6c930c8b62d0e3ee02ae602256c6f..37eb568e1713ebe79ece74ef38309572e02056ac 100644 (file)
@@ -57,7 +57,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
                  dwfl-bug-addr-overflow arls dwfl-bug-fd-leak \
                  dwfl-addr-sect dwfl-bug-report early-offscn \
                  dwfl-bug-getmodules dwarf-getmacros addrcfi \
-                 test-flag-nobits
+                 test-flag-nobits dwarf-getstring
 asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
            asm-tst6 asm-tst7 asm-tst8 asm-tst9
 
@@ -83,7 +83,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
        run-dwfl-bug-offline-rel.sh run-dwfl-addr-sect.sh \
        run-disasm-x86.sh run-disasm-x86-64.sh \
        run-early-offscn.sh run-dwarf-getmacros.sh \
-       run-test-flag-nobits.sh run-prelink-addr-test.sh
+       run-test-flag-nobits.sh run-prelink-addr-test.sh \
+       run-dwarf-getstring.sh
 # run-show-ciefde.sh
 
 if !STANDALONE
@@ -117,6 +118,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
             run-addrname-test.sh run-dwfl-bug-offline-rel.sh \
             run-dwfl-addr-sect.sh run-early-offscn.sh \
             run-dwarf-getmacros.sh run-test-flag-nobits.sh \
+            run-dwarf-getstring.sh \
             testfile15.bz2 testfile15.debug.bz2 \
             testfile16.bz2 testfile16.debug.bz2 \
             testfile17.bz2 testfile17.debug.bz2 \
@@ -246,6 +248,7 @@ dwfl_bug_getmodules_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
 dwfl_addr_sect_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
 sha1_tst_LDADD = $(libeu) $(libmudflap)
 dwarf_getmacros_LDADD = $(libdw) $(libmudflap)
+dwarf_getstring_LDADD = $(libdw) $(libmudflap)
 addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
 test_flag_nobits_LDADD = $(libelf) $(libmudflap)
 
diff --git a/tests/dwarf-getstring.c b/tests/dwarf-getstring.c
new file mode 100644 (file)
index 0000000..66ab329
--- /dev/null
@@ -0,0 +1,85 @@
+/* Copyright (C) 2011 Red Hat, Inc.
+   This file is part of Red Hat elfutils.
+   Written by Marek Polacek <mpolacek@redhat.com>, 2011.
+
+   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 ELFUTILS_HEADER(dwfl)
+#include <assert.h>
+#include <dwarf.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+  int cnt;
+
+  for (cnt = 1; cnt < argc; ++cnt)
+    {
+      Dwarf_Off offset = 0;
+      size_t len;
+
+      int fd = open64 (argv[cnt], O_RDONLY);
+      if (fd == -1)
+       {
+         printf ("cannot open '%s': %m\n", argv[cnt]);
+         return 1;
+       }
+
+      Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+      if (dbg == NULL)
+       {
+         printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
+         close (fd);
+         return 1;
+       }
+
+      /* Try to use NULL Dwarf object.  */
+      const char *str = dwarf_getstring (NULL, offset, &len);
+      assert (str == NULL);
+
+      /* Use insane offset.  */
+      str = dwarf_getstring (dbg, ~0UL, &len);
+      assert (str == NULL);
+
+      /* Now do some real work.  */
+      for (int i = 0; i < 100; ++i)
+       {
+         str = dwarf_getstring (dbg, offset, &len);
+         puts (str);
+
+         /* Advance.  */
+         offset += len + 1;
+       }
+
+      close (fd);
+    }
+
+  return 0;
+}
diff --git a/tests/run-dwarf-getstring.sh b/tests/run-dwarf-getstring.sh
new file mode 100755 (executable)
index 0000000..df90a58
--- /dev/null
@@ -0,0 +1,133 @@
+#! /bin/sh
+# Copyright (C) 2011 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>.
+
+. $srcdir/test-subr.sh
+
+testfiles testfile11
+
+testrun_compare ./dwarf-getstring testfile11 <<\EOF
+_ZNSbIwSt11char_traitsIwESaIwEE13_S_copy_charsEPwS3_S3_
+itimerspec
+_G_int32_t
+_IO_last_state
+antiquities
+_ZNSbIwSt11char_traitsIwESaIwEEpLEw
+insert
+_ZNSbIwSt11char_traitsIwESaIwEE12_M_leak_hardEv
+__lockkind
+_ZNKSbIwSt11char_traitsIwESaIwEE8capacityEv
+_ZNSs7_M_leakEv
+_M_ref_count
+_ZNSt11char_traitsIwE6assignEPwjw
+_ZNKSs13find_first_ofEPKcj
+._14
+._15
+._16
+._17
+_ZNKSs16find_last_not_ofEPKcj
+_G_iconv_t
+_ZN10__gnu_test9gnu_obj_2IlEaSERKS1_
+_ZN11random_dataaSERKS_
+_ZNSt11char_traitsIcE7not_eofERKi
+__class_type_info
+tm_sec
+_ZNKSbIwSt11char_traitsIwESaIwEE5c_strEv
+__rlim64_t
+seek
+pthread_mutex_t
+_ZNSs5eraseEN9__gnu_cxx17__normal_iteratorIPcSsEE
+_ZNSsaSEc
+__not_va_list__
+_ZNKSs12find_last_ofEPKcj
+_ZNSs7replaceEN9__gnu_cxx17__normal_iteratorIPcSsEES2_S2_S2_
+__gconv_info
+_ZNSt11__ios_flags12_S_showpointE
+output_iterator_tag
+gnu_obj_2<long int>
+_ZNSs6insertEjRKSsjj
+_ZN13__type_traitsIbEaSERKS0_
+_ZNKSbIwSt11char_traitsIwESaIwEE4copyEPwjj
+_ZNSs9_M_mutateEjjj
+__ios_flags
+short unsigned int
+_ZNKSs4findEPKcj
+compare
+_ZNSbIwSt11char_traitsIwESaIwEE4_Rep7_M_grabERKS1_S5_
+tm_yday
+unsigned char
+__stacksize
+__gconv_init_fct
+_IO_FILE
+__counter
+._26
+._27
+bidirectional_iterator_tag
+._29
+it_value
+const_iterator
+_ZNSt11__ios_flags6_S_outE
+_M_set_leaked
+_Is_integer<unsigned int>
+__value
+timeval
+_IO_jump_t
+_ZN11sched_paramaSERKS_
+__normal_iterator<char*,std::basic_string<char, std::char_traits<char>, std::allocator<char> > >
+_ZNSs4_Rep7_M_grabERKSaIcES2_
+_wide_vtable
+__codecvt_destr
+_STL_mutex_lock
+_ZNSt24__default_alloc_templateILb1ELi0EE17_S_freelist_indexEj
+_ZNSbIwSt11char_traitsIwESaIwEE7replaceEjjjw
+_ZN17__gconv_step_dataaSERKS_
+__w_stopval
+__int64_t
+__type_traits<double>
+~_Lock
+_ZNKSbIwSt11char_traitsIwESaIwEE5beginEv
+ptrdiff_t
+test
+_Integral
+cookie_seek_function_t
+__vmi_class_type_info
+_ZNSs7replaceEjjjc
+__int32_t
+register_t
+~_STL_auto_lock
+_ZNKSbIwSt11char_traitsIwESaIwEE16find_last_not_ofEPKwjj
+__arg
+_ZNSs7replaceEjjPKcj
+_ZNSbIwSt11char_traitsIwESaIwEE7replaceEjjRKS2_jj
+_ZNKSbIwSt11char_traitsIwESaIwEE12find_last_ofEPKwjj
+_ZN11_Is_integerImEaSERKS0_
+__default_alloc_template
+_S_hex
+__statep
+_ZNSt11char_traitsIwE2ltERKwS2_
+_M_p
+_ZNKSs4sizeEv
+EOF
+
+exit 0