libevfibers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
trace.c
1 /********************************************************************
2 
3  Copyright 2012 Konstantin Olkhovskiy <lupus@oxnull.net>
4 
5  This file is part of libevfibers.
6 
7  libevfibers is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as
9  published by the Free Software Foundation, either version 3 of the
10  License, or any later version.
11 
12  libevfibers is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General
18  Public License along with libevfibers. If not, see
19  <http://www.gnu.org/licenses/>.
20 
21  ********************************************************************/
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <execinfo.h>
26 #include <evfibers_private/trace.h>
27 #include <evfibers_private/fiber.h>
28 
29 void fill_trace_info(FBR_P_ struct trace_info *info)
30 {
31  if (0 == fctx->__p->backtraces_enabled)
32  return;
33  info->size = backtrace(info->array, TRACE_SIZE);
34 }
35 
36 void print_trace_info(FBR_P_ struct trace_info *info, fbr_logutil_func_t log)
37 {
38  size_t i;
39  char **strings;
40  if (0 == fctx->__p->backtraces_enabled) {
41  (*log)(FBR_A_ "(No backtrace since they are disabled)");
42  return;
43  }
44  strings = backtrace_symbols(info->array, info->size);
45  for (i = 0; i < info->size; i++)
46  (*log)(FBR_A_ "%s", strings[i]);
47  free(strings);
48 }