1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-25 08:37:38 +01:00
libunwind-eh_elf/tests/test-proc-info.c

172 lines
4.6 KiB
C
Raw Normal View History

/* 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. */
2003-09-18 08:09:22 +02:00
/* 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>
2012-09-19 12:50:59 +02:00
#include "compiler.h"
2003-09-18 08:09:22 +02:00
int errors;
#define panic(args...) \
{ ++errors; fprintf (stderr, args); return -1; }
static int
2012-09-19 12:50:59 +02:00
find_proc_info (unw_addr_space_t as UNUSED,
unw_word_t ip UNUSED,
unw_proc_info_t *pip UNUSED,
int need_unwind_info UNUSED,
void *arg UNUSED)
2003-09-18 08:09:22 +02:00
{
return -UNW_ESTOPUNWIND;
}
static int
2012-09-19 12:50:59 +02:00
access_mem (unw_addr_space_t as UNUSED,
unw_word_t addr UNUSED,
unw_word_t *valp, int write,
2012-09-19 12:50:59 +02:00
void *arg UNUSED)
2003-09-18 08:09:22 +02:00
{
if (!write)
*valp = 0;
return 0;
}
static int
2012-09-19 12:50:59 +02:00
access_reg (unw_addr_space_t as UNUSED,
unw_regnum_t regnum UNUSED,
unw_word_t *valp, int write,
2012-09-19 12:50:59 +02:00
void *arg UNUSED)
2003-09-18 08:09:22 +02:00
{
if (!write)
*valp = 32;
return 0;
}
static int
2012-09-19 12:50:59 +02:00
access_fpreg (unw_addr_space_t as UNUSED,
unw_regnum_t regnum UNUSED,
unw_fpreg_t *valp, int write,
2012-09-19 12:50:59 +02:00
void *arg UNUSED)
2003-09-18 08:09:22 +02:00
{
if (!write)
memset (valp, 0, sizeof (*valp));
2003-09-18 08:09:22 +02:00
return 0;
}
static int
2012-09-19 12:50:59 +02:00
get_dyn_info_list_addr (unw_addr_space_t as UNUSED,
unw_word_t *dilap UNUSED,
void *arg UNUSED)
2003-09-18 08:09:22 +02:00
{
return -UNW_ENOINFO;
}
static void
2012-09-19 12:50:59 +02:00
put_unwind_info (unw_addr_space_t as UNUSED,
unw_proc_info_t *pi UNUSED,
void *arg UNUSED)
{
++errors;
fprintf (stderr, "%s() got called!\n", __FUNCTION__);
}
static int
2012-09-19 12:50:59 +02:00
resume (unw_addr_space_t as UNUSED,
unw_cursor_t *reg UNUSED,
void *arg UNUSED)
{
panic ("%s() got called!\n", __FUNCTION__);
}
2003-09-18 08:09:22 +02:00
static int
2012-09-19 12:50:59 +02:00
get_proc_name (unw_addr_space_t as UNUSED,
unw_word_t ip UNUSED,
char *buf UNUSED,
size_t buf_len UNUSED,
unw_word_t *offp UNUSED,
void *arg UNUSED)
2003-09-18 08:09:22 +02:00
{
panic ("%s() got called!\n", __FUNCTION__);
2003-09-18 08:09:22 +02:00
}
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)
2003-09-18 08:09:22 +02:00
verbose = 1;
memset (&acc, 0, sizeof (acc));
acc.find_proc_info = find_proc_info;
acc.put_unwind_info = put_unwind_info;
2003-09-18 08:09:22 +02:00
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;
2003-09-18 08:09:22 +02:00
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);
2003-09-18 08:09:22 +02:00
if (verbose)
printf ("SUCCESS\n");
return 0;
}