mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2024-11-22 07:37:38 +01:00
0d7738ed4f
Cleanup dynamically allocated memory before exit in tests in a few places where missing. While such cleanups right before exit do not usually make much sense (as the operating system would cleanup anyway, so manual cleanups only burn CPU cycles), we will want to catch any potential problems in libunwind related to the cleanups. This also stops valgrind complaining about unreleased memory.
170 lines
5 KiB
C
170 lines
5 KiB
C
/* libunwind - a platform-independent unwind library
|
|
Copyright (C) 2003 Hewlett-Packard Co
|
|
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
|
|
|
This file is part of libunwind.
|
|
|
|
Copyright (c) 2003 Hewlett-Packard Co.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
a copy of this software and associated documentation files (the
|
|
"Software"), to deal in the Software without restriction, including
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
distribute, sublicense, and/or sell copies of the Software, and to
|
|
permit persons to whom the Software is furnished to do so, subject to
|
|
the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be
|
|
included in all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/* This test program checks whether proc_info lookup failures are
|
|
cached. They must NOT be cached because it could otherwise turn
|
|
temporary failures into permanent ones. Furthermore, we allow apps
|
|
to return -UNW_ESTOPUNWIND to terminate unwinding (though this
|
|
feature is deprecated and dynamic unwind info should be used
|
|
instead). */
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <libunwind.h>
|
|
|
|
int errors;
|
|
|
|
#define panic(args...) \
|
|
{ ++errors; fprintf (stderr, args); return -1; }
|
|
|
|
static int
|
|
find_proc_info (unw_addr_space_t as __attribute__((unused)),
|
|
unw_word_t ip __attribute__((unused)),
|
|
unw_proc_info_t *pip __attribute__((unused)),
|
|
int need_unwind_info __attribute__((unused)),
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
return -UNW_ESTOPUNWIND;
|
|
}
|
|
|
|
static int
|
|
access_mem (unw_addr_space_t as __attribute__((unused)),
|
|
unw_word_t addr __attribute__((unused)),
|
|
unw_word_t *valp, int write,
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
if (!write)
|
|
*valp = 0;
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
access_reg (unw_addr_space_t as __attribute__((unused)),
|
|
unw_regnum_t regnum __attribute__((unused)),
|
|
unw_word_t *valp, int write,
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
if (!write)
|
|
*valp = 32;
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
access_fpreg (unw_addr_space_t as __attribute__((unused)),
|
|
unw_regnum_t regnum __attribute__((unused)),
|
|
unw_fpreg_t *valp, int write,
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
if (!write)
|
|
memset (valp, 0, sizeof (*valp));
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
get_dyn_info_list_addr (unw_addr_space_t as __attribute__((unused)),
|
|
unw_word_t *dilap __attribute__((unused)),
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
return -UNW_ENOINFO;
|
|
}
|
|
|
|
static void
|
|
put_unwind_info (unw_addr_space_t as __attribute__((unused)),
|
|
unw_proc_info_t *pi __attribute__((unused)),
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
++errors;
|
|
fprintf (stderr, "%s() got called!\n", __FUNCTION__);
|
|
}
|
|
|
|
static int
|
|
resume (unw_addr_space_t as __attribute__((unused)),
|
|
unw_cursor_t *reg __attribute__((unused)),
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
panic ("%s() got called!\n", __FUNCTION__);
|
|
}
|
|
|
|
static int
|
|
get_proc_name (unw_addr_space_t as __attribute__((unused)),
|
|
unw_word_t ip __attribute__((unused)),
|
|
char *buf __attribute__((unused)),
|
|
size_t buf_len __attribute__((unused)),
|
|
unw_word_t *offp __attribute__((unused)),
|
|
void *arg __attribute__((unused)))
|
|
{
|
|
panic ("%s() got called!\n", __FUNCTION__);
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
unw_accessors_t acc;
|
|
unw_addr_space_t as;
|
|
int ret, verbose = 0;
|
|
unw_cursor_t c;
|
|
|
|
if (argc > 1 && strcmp (argv[1], "-v") == 0)
|
|
verbose = 1;
|
|
|
|
memset (&acc, 0, sizeof (acc));
|
|
acc.find_proc_info = find_proc_info;
|
|
acc.put_unwind_info = put_unwind_info;
|
|
acc.get_dyn_info_list_addr = get_dyn_info_list_addr;
|
|
acc.access_mem = access_mem;
|
|
acc.access_reg = access_reg;
|
|
acc.access_fpreg = access_fpreg;
|
|
acc.resume = resume;
|
|
acc.get_proc_name = get_proc_name;
|
|
|
|
as = unw_create_addr_space (&acc, 0);
|
|
if (!as)
|
|
panic ("unw_create_addr_space() failed\n");
|
|
|
|
unw_set_caching_policy (as, UNW_CACHE_GLOBAL);
|
|
|
|
ret = unw_init_remote (&c, as, NULL);
|
|
if (ret < 0)
|
|
panic ("unw_init_remote() returned %d instead of 0\n", ret);
|
|
|
|
ret = unw_step (&c);
|
|
if (ret != -UNW_ESTOPUNWIND)
|
|
panic ("First call to unw_step() returned %d instead of %d\n",
|
|
ret, -UNW_ESTOPUNWIND);
|
|
|
|
ret = unw_step (&c);
|
|
if (ret != -UNW_ESTOPUNWIND)
|
|
panic ("Second call to unw_step() returned %d instead of %d\n",
|
|
ret, -UNW_ESTOPUNWIND);
|
|
|
|
unw_destroy_addr_space (as);
|
|
|
|
if (verbose)
|
|
printf ("SUCCESS\n");
|
|
return 0;
|
|
}
|