summaryrefslogtreecommitdiffstats
path: root/src/tests/vdsosyms.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-02-25 16:51:55 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-02-25 16:51:55 +0000
commit412f6b917fc658c24dd7d624bb82bf1a1e791b95 (patch)
treea63e40b5dd9927bd04ec7427c8797975c2a71f85 /src/tests/vdsosyms.c
parenta969285f70219c5d35ee5aa8ceab0f532fc1e54d (diff)
parent7401a30e8b3a0de25d7e8a6b635fc33f45894118 (diff)
downloadandroid_external_elfutils-412f6b917fc658c24dd7d624bb82bf1a1e791b95.tar.gz
android_external_elfutils-412f6b917fc658c24dd7d624bb82bf1a1e791b95.tar.bz2
android_external_elfutils-412f6b917fc658c24dd7d624bb82bf1a1e791b95.zip
am 7401a30e: am 36e62782: Merge "Upgrade to elfutils 0.161."
* commit '7401a30e8b3a0de25d7e8a6b635fc33f45894118': Upgrade to elfutils 0.161.
Diffstat (limited to 'src/tests/vdsosyms.c')
-rw-r--r--src/tests/vdsosyms.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/tests/vdsosyms.c b/src/tests/vdsosyms.c
new file mode 100644
index 00000000..c1f8d89f
--- /dev/null
+++ b/src/tests/vdsosyms.c
@@ -0,0 +1,109 @@
+/* Test program for getting symbol table from vdso module.
+ Copyright (C) 2014 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file 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; either version 3 of the License, or
+ (at your option) any later version.
+
+ 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 this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <assert.h>
+#include <errno.h>
+#include <error.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include ELFUTILS_HEADER(dwfl)
+
+#ifndef __linux__
+int
+main (int argc __attribute__ ((unused)), char **argv)
+{
+ printf ("Getting the vdso is unsupported.\n");
+ return 77;
+}
+#else /* __linux__ */
+static int vdso_syms = 0;
+
+static int
+module_callback (Dwfl_Module *mod, void **userdata __attribute__((unused)),
+ const char *name, Dwarf_Addr start __attribute__((unused)),
+ void *arg __attribute__((unused)))
+{
+ /* We can only recognize the vdso by inspecting the "magic name". */
+ printf ("module name: %s\n", name);
+ if (strncmp ("[vdso: ", name, 7) == 0)
+ {
+ vdso_syms = dwfl_module_getsymtab (mod);
+ printf ("vdso syms: %d\n", vdso_syms);
+ if (vdso_syms < 0)
+ error (2, 0, "dwfl_module_getsymtab: %s", dwfl_errmsg (-1));
+
+ for (int i = 0; i < vdso_syms; i++)
+ {
+ GElf_Sym sym;
+ GElf_Addr addr;
+ const char *sname = dwfl_module_getsym_info (mod, i, &sym, &addr,
+ NULL, NULL, NULL);
+ assert (sname != NULL);
+ printf ("%d: '%s' %" PRIx64 " (%" PRIx64 ")\n",
+ i, sname, sym.st_value, addr);
+ }
+ }
+
+ return DWARF_CB_OK;
+}
+
+int
+main (int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)))
+{
+ static char *debuginfo_path;
+ static const Dwfl_Callbacks proc_callbacks =
+ {
+ .find_debuginfo = dwfl_standard_find_debuginfo,
+ .debuginfo_path = &debuginfo_path,
+
+ .find_elf = dwfl_linux_proc_find_elf,
+ };
+ Dwfl *dwfl = dwfl_begin (&proc_callbacks);
+ if (dwfl == NULL)
+ error (2, 0, "dwfl_begin: %s", dwfl_errmsg (-1));
+
+ /* Take our parent as "arbitrary" process to inspect. */
+ pid_t pid = getppid();
+
+ int result = dwfl_linux_proc_report (dwfl, pid);
+ if (result < 0)
+ error (2, 0, "dwfl_linux_proc_report: %s", dwfl_errmsg (-1));
+ else if (result > 0)
+ error (2, result, "dwfl_linux_proc_report");
+
+ /* Also explicitly attach for older kernels (cannot read vdso otherwise). */
+ result = dwfl_linux_proc_attach (dwfl, pid, false);
+ if (result < 0)
+ error (2, 0, "dwfl_linux_proc_attach: %s", dwfl_errmsg (-1));
+ else if (result > 0)
+ error (2, result, "dwfl_linux_proc_attach");
+
+ if (dwfl_report_end (dwfl, NULL, NULL) != 0)
+ error (2, 0, "dwfl_report_end: %s", dwfl_errmsg (-1));
+
+ if (dwfl_getmodules (dwfl, module_callback, NULL, 0) != 0)
+ error (1, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1));
+
+ /* No symbols is ok, then we haven't seen the vdso at all on this arch. */
+ return vdso_syms >= 0 ? 0 : -1;
+}
+
+#endif /* ! __linux__ */