summaryrefslogtreecommitdiffstats
path: root/src/Backtrace/backtrace.h
blob: 93897e935a190ed017e8f0d6d1e1d6c962cc94c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
    Copyright (C) 2009  RedHat inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef BACKTRACE_H
#define BACKTRACE_H

#include <stdio.h>
#include <stdbool.h>

struct frame
{
  /* Function name, or NULL. */
  char *function;
  /* Frame number. */
  int number;
  /* Name of the source file, or binary file, or NULL. */
  char *sourcefile;
  bool signal_handler_called;
  /* Sibling frame, or NULL if this is the last frame in a thread. */
  struct frame *next;
};

struct thread
{
  int number;
  struct frame *frames;
  /* Sibling thread, or NULL if this is the last thread in a backtrace. */
  struct thread *next;
};

struct backtrace
{
  struct thread *threads;
  /* 
   * The frame where the crash happened according to GDB. 
   * It might be that we can not tell to which thread this frame belongs,
   * because all threads end with mutually indistinguishable frames.
   */
  struct frame *crash;
};

extern struct frame *frame_new();
extern void frame_free(struct frame *f);
extern struct frame *frame_add_sibling(struct frame *a, struct frame *b);

extern struct thread *thread_new();
extern void thread_free(struct thread *t);
extern struct thread *thread_add_sibling(struct thread *a, struct thread *b);

extern struct backtrace *backtrace_new();
extern void backtrace_free(struct backtrace *bt);

/* Prints how internal backtrace representation looks to stdout. */
extern void backtrace_print_tree(struct backtrace *backtrace, bool verbose);

/* 
 * Frees all threads except the one provided as parameters. 
 * It does not check whether one is a member of backtrace.
 * Caller must know that.
 */
extern void backtrace_remove_threads_except_one(struct backtrace *backtrace, 
						struct thread *one);

/* 
 * Search all threads and tries to find the one that caused the crash. 
 * It might return NULL if the thread cannot be determined.
 */
extern struct thread *backtrace_find_crash_thread(struct backtrace *backtrace);

extern void backtrace_limit_frame_depth(struct backtrace *backtrace, int depth);

/*
 * Exit handlers are all stack frames above  __run_exit_handlers()
 */
extern void backtrace_remove_exit_handlers(struct backtrace *backtrace);

/*
 * Removes frames known as not causing crash, but that are often 
 * a part of a backtrace.
 */
extern void backtrace_remove_noncrash_frames(struct backtrace *backtrace);

/* Defined in parser.y. */
extern struct backtrace *do_parse(char *input, bool debug_parser, bool debug_scanner);

#endif