backtrace.c revision 3eabce18b1e70c3b26975024e450977dfb4b84b9
114e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm/* libunwind - a platform-independent unwind library 214e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm Copyright (C) 2001-2002 Hewlett-Packard Co 314e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 414e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 514e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmThis file is part of libunwind. 614e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 714e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmPermission is hereby granted, free of charge, to any person obtaining 814e36a6a516875be61e02206c81c08a8750f340fhp.com!davidma copy of this software and associated documentation files (the 914e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm"Software"), to deal in the Software without restriction, including 1014e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmwithout limitation the rights to use, copy, modify, merge, publish, 1114e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmdistribute, sublicense, and/or sell copies of the Software, and to 1214e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmpermit persons to whom the Software is furnished to do so, subject to 1314e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmthe following conditions: 1414e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 1514e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmThe above copyright notice and this permission notice shall be 1614e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmincluded in all copies or substantial portions of the Software. 1714e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 1814e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1914e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2014e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 2114e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 2214e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 2314e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2414e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 2514e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 2614e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm#ifndef UNW_REMOTE_ONLY 2714e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm#define UNW_LOCAL_ONLY 283eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov 293eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov#ifdef HAVE_CONFIG_H 303eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov#include <config.h> 313eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov#endif 323eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov 333eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov#ifdef HAVE_SYS_TYPES_H 343eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov# include <sys/types.h> 353eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov#endif 363eabce18b1e70c3b26975024e450977dfb4b84b9Konstantin Belousov 3714e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm#include <libunwind.h> 3814e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 3914e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm/* See glibc manual for a description of this function. */ 4014e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 4114e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmint 4214e36a6a516875be61e02206c81c08a8750f340fhp.com!davidmbacktrace (void **buffer, int size) 4314e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm{ 4414e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm unw_cursor_t cursor; 4514e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm unw_context_t uc; 4614e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm unw_word_t ip; 4714e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm int n = 0; 4814e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 4914e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm unw_getcontext (&uc); 5014e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm if (unw_init_local (&cursor, &uc) < 0) 5114e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm return 0; 5214e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 5314e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm while (unw_step (&cursor) > 0) 5414e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm { 5514e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm if (n >= size) 5614e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm return n; 5714e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 5814e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm if (unw_get_reg (&cursor, UNW_REG_IP, &ip) < 0) 5914e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm return n; 603842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz buffer[n++] = (void *) (uintptr_t) ip; 6114e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm } 6214e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm return n; 6314e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm} 6414e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm 6514e36a6a516875be61e02206c81c08a8750f340fhp.com!davidm#endif /* !UNW_REMOTE_ONLY */ 66