Home | History | Annotate | Download | only in tests
      1 /* libunwind - a platform-independent unwind library
      2    Copyright (C) 2004 Hewlett-Packard Co
      3 	Contributed by David Mosberger-Tang <davidm (at) hpl.hp.com>
      4 
      5 This file is part of libunwind.
      6 
      7 Copyright (c) 2003 Hewlett-Packard Co.
      8 
      9 Permission is hereby granted, free of charge, to any person obtaining
     10 a copy of this software and associated documentation files (the
     11 "Software"), to deal in the Software without restriction, including
     12 without limitation the rights to use, copy, modify, merge, publish,
     13 distribute, sublicense, and/or sell copies of the Software, and to
     14 permit persons to whom the Software is furnished to do so, subject to
     15 the following conditions:
     16 
     17 The above copyright notice and this permission notice shall be
     18 included in all copies or substantial portions of the Software.
     19 
     20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
     27 
     28 /* The purpose of this program is simply to link in all libunwind-API
     29    functions both in their local-only and generic variants and to make
     30    sure that the final result can be linked statically.  */
     31 
     32 #include <stdio.h>
     33 
     34 #define UNW_LOCAL_ONLY
     35 #include <libunwind.h>
     36 #include "compiler.h"
     37 
     38 extern int test_generic (void);
     39 
     40 int verbose;
     41 
     42 #ifdef UNW_REMOTE_ONLY
     43 
     44 int
     45 test_local (void)
     46 {
     47   return 0;
     48 }
     49 
     50 #else /* !UNW_REMOTE_ONLY */
     51 
     52 static void *funcs[] =
     53   {
     54     (void *) &unw_get_reg,
     55     (void *) &unw_get_fpreg,
     56     (void *) &unw_set_reg,
     57     (void *) &unw_set_fpreg,
     58     (void *) &unw_resume,
     59     (void *) &unw_create_addr_space,
     60     (void *) &unw_destroy_addr_space,
     61     (void *) &unw_get_accessors,
     62     (void *) &unw_flush_cache,
     63     (void *) &unw_set_caching_policy,
     64     (void *) &unw_regname,
     65     (void *) &unw_get_proc_info,
     66     (void *) &unw_get_save_loc,
     67     (void *) &unw_is_signal_frame,
     68     (void *) &unw_get_proc_name,
     69     (void *) &_U_dyn_register,
     70     (void *) &_U_dyn_cancel
     71   };
     72 
     73 int
     74 test_local (void)
     75 {
     76   unw_context_t uc;
     77   unw_cursor_t c;
     78 
     79   if (verbose)
     80     printf (__FILE__": funcs[0]=%p\n", funcs[0]);
     81 
     82   unw_getcontext (&uc);
     83   unw_init_local (&c, &uc);
     84   unw_init_remote (&c, unw_local_addr_space, &uc);
     85   return unw_step (&c);
     86 }
     87 
     88 #endif /* !UNW_REMOTE_ONLY */
     89 
     90 int
     91 main (int argc, char **argv UNUSED)
     92 {
     93   if (argc > 1)
     94     verbose = 1;
     95 
     96   if (test_local () < 0)
     97     return -1;
     98   if (test_generic () < 0)
     99     return -1;
    100   return 0;
    101 }
    102