Imported Upstream version 1.3.1
[platform/upstream/libunwind.git] / tests / test-static-link-loc.c
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2004 Hewlett-Packard Co
3         Contributed by David Mosberger-Tang <davidm@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_set_cache_size,
65     (void *) &unw_regname,
66     (void *) &unw_get_proc_info,
67     (void *) &unw_get_save_loc,
68     (void *) &unw_is_signal_frame,
69     (void *) &unw_get_proc_name,
70     (void *) &_U_dyn_register,
71     (void *) &_U_dyn_cancel
72   };
73
74 int
75 test_local (void)
76 {
77   unw_context_t uc;
78   unw_cursor_t c;
79
80   if (verbose)
81     printf (__FILE__": funcs[0]=%p\n", funcs[0]);
82
83   unw_getcontext (&uc);
84   unw_init_local (&c, &uc);
85   unw_init_remote (&c, unw_local_addr_space, &uc);
86   return unw_step (&c);
87 }
88
89 #endif /* !UNW_REMOTE_ONLY */
90
91 int
92 main (int argc, char **argv UNUSED)
93 {
94   if (argc > 1)
95     verbose = 1;
96
97   if (test_local () < 0)
98     return -1;
99   if (test_generic () < 0)
100     return -1;
101   return 0;
102 }