17ec681f3Smrg/**************************************************************************
27ec681f3Smrg *
37ec681f3Smrg * Copyright 2009 VMware, Inc.
47ec681f3Smrg * All Rights Reserved.
57ec681f3Smrg *
67ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
77ec681f3Smrg * copy of this software and associated documentation files (the
87ec681f3Smrg * "Software"), to deal in the Software without restriction, including
97ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish,
107ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to
117ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to
127ec681f3Smrg * the following conditions:
137ec681f3Smrg *
147ec681f3Smrg * The above copyright notice and this permission notice (including the
157ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions
167ec681f3Smrg * of the Software.
177ec681f3Smrg *
187ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
197ec681f3Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
207ec681f3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
217ec681f3Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
227ec681f3Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
237ec681f3Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
247ec681f3Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
257ec681f3Smrg *
267ec681f3Smrg **************************************************************************/
277ec681f3Smrg
287ec681f3Smrg#ifndef U_DEBUG_STACK_H_
297ec681f3Smrg#define U_DEBUG_STACK_H_
307ec681f3Smrg
317ec681f3Smrg#include <stdio.h>
327ec681f3Smrg
337ec681f3Smrg#ifdef HAVE_LIBUNWIND
347ec681f3Smrg#define UNW_LOCAL_ONLY
357ec681f3Smrg#include <libunwind.h>
367ec681f3Smrg#endif
377ec681f3Smrg
387ec681f3Smrg/**
397ec681f3Smrg * @file
407ec681f3Smrg * Stack backtracing.
417ec681f3Smrg *
427ec681f3Smrg * @author Jose Fonseca <jfonseca@vmware.com>
437ec681f3Smrg */
447ec681f3Smrg
457ec681f3Smrg
467ec681f3Smrg#ifdef	__cplusplus
477ec681f3Smrgextern "C" {
487ec681f3Smrg#endif
497ec681f3Smrg
507ec681f3Smrg
517ec681f3Smrg/**
527ec681f3Smrg * Represent a frame from a stack backtrace.
537ec681f3Smrg *
547ec681f3Smrg#if defined(PIPE_OS_WINDOWS) && !defined(HAVE_LIBUNWIND)
557ec681f3Smrg * XXX: Do not change this. (passed to Windows' CaptureStackBackTrace())
567ec681f3Smrg#endif
577ec681f3Smrg *
587ec681f3Smrg * TODO: This should be refactored as a void * typedef.
597ec681f3Smrg */
607ec681f3Smrgstruct debug_stack_frame
617ec681f3Smrg{
627ec681f3Smrg#if defined(HAVE_ANDROID_PLATFORM) || defined(HAVE_LIBUNWIND)
637ec681f3Smrg   const char *procname;
647ec681f3Smrg   uint64_t start_ip;
657ec681f3Smrg   unsigned off;
667ec681f3Smrg   const char *map;
677ec681f3Smrg   unsigned int map_off;
687ec681f3Smrg#else
697ec681f3Smrg   const void *function;
707ec681f3Smrg#endif
717ec681f3Smrg};
727ec681f3Smrg
737ec681f3Smrg
747ec681f3Smrgvoid
757ec681f3Smrgdebug_backtrace_capture(struct debug_stack_frame *backtrace,
767ec681f3Smrg                        unsigned start_frame,
777ec681f3Smrg                        unsigned nr_frames);
787ec681f3Smrg
797ec681f3Smrgvoid
807ec681f3Smrgdebug_backtrace_dump(const struct debug_stack_frame *backtrace,
817ec681f3Smrg                     unsigned nr_frames);
827ec681f3Smrg
837ec681f3Smrgvoid
847ec681f3Smrgdebug_backtrace_print(FILE *f,
857ec681f3Smrg                      const struct debug_stack_frame *backtrace,
867ec681f3Smrg                      unsigned nr_frames);
877ec681f3Smrg
887ec681f3Smrg#ifdef	__cplusplus
897ec681f3Smrg}
907ec681f3Smrg#endif
917ec681f3Smrg
927ec681f3Smrg#endif /* U_DEBUG_STACK_H_ */
93