1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2003-2004 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of libunwind.
7 Copyright (c) 2003 Hewlett-Packard Co.
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:
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
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. */
30 #include <libunwind.h>
37 #include <sys/resource.h>
39 #define panic(args...) \
40 { fprintf (stderr, args); exit (-1); }
52 dwarf_reg_states_callback(void *token,
55 unw_word_t start_ip, unw_word_t end_ip)
57 struct cb_data *data = token;
58 if (start_ip <= data->ip && data->ip < end_ip)
60 data->reg_state = mmap(NULL, size, PROT_READ | PROT_WRITE,
61 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
62 memcpy(data->reg_state, rs, size);
77 if (unw_init_local (&cursor, &uc) < 0)
78 panic ("unw_init_local failed!\n");
82 unw_get_reg (&cursor, UNW_REG_IP, &ip);
83 unw_get_reg (&cursor, UNW_REG_SP, &sp);
86 printf ("%016lx (sp=%016lx)\n", (long) ip, (long) sp);
88 struct cb_data data = {.ip = ip, .reg_state = NULL};
89 ret = unw_reg_states_iterate(&cursor, dwarf_reg_states_callback, &data);
92 ret = unw_apply_reg_state (&cursor, data.reg_state);
93 munmap(data.reg_state, data.len);
97 unw_get_reg (&cursor, UNW_REG_IP, &ip);
98 panic ("FAILURE: unw_step() returned %d for ip=%lx\n",
106 consume_some_stack_space (void)
112 memset (&cursor, 0, sizeof (cursor));
113 memset (&uc, 0, sizeof (uc));
114 return sprintf (string, "hello %p %p\n", &cursor, &uc);
118 main (int argc, char **argv UNUSED)
124 if (consume_some_stack_space () > 9999)
125 exit (-1); /* can't happen, but don't let the compiler know... */
128 rlim.rlim_max = RLIM_INFINITY;
129 setrlimit (RLIMIT_DATA, &rlim);