Predator
[unstable] git snapshot
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
trap.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2010 Kamil Dudka <kdudka@redhat.com>
3
*
4
* This file is part of predator.
5
*
6
* predator is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* any later version.
10
*
11
* predator is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with predator. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#include <stdio.h>
/* needed for TRAP ... fprintf(stderr, ...) */
21
22
/**
23
* defined in version.c to avoid rebuild of all modules on git-commit
24
*/
25
extern
const
char
*
GIT_SHA1
;
26
27
#ifdef USE_INT3_AS_BRK
28
# define _CL_BREAK __asm__("int3")
29
# define _CL_BREAK_MECH "INT3"
30
#else
31
# include <signal.h>
32
# define _CL_BREAK raise(SIGTRAP)
33
# define _CL_BREAK_MECH "SIGTRAP"
34
#endif
35
36
/**
37
* jump to debugger by default in case anything interesting happens
38
* @note this behavior may be subject for change in the future
39
* @note for comfortable source code browsing, it's recommended to tweak your
40
* editor, in order to highlight CL_TRAP as as keyword, as well as CL_BREAK_IF
41
*/
42
#define CL_TRAP do { \
43
fprintf(stderr, "%s:%d: killing self by %s [SHA1 %s]\n", \
44
__FILE__, __LINE__, _CL_BREAK_MECH, GIT_SHA1); \
45
\
46
_CL_BREAK; \
47
} while (0)
48
49
#ifndef NDEBUG
50
/**
51
* conditional variant of CL_TRAP, do nothing as long as cond is not satisfied
52
* @attention the macro suffer from the same flaw as std::assert - the given
53
* expression is not evaluated at all unless you're running a debug build
54
* @note the macro has exactly opposite semantic than std::assert
55
* @note for comfortable source code browsing, it's recommended to tweak your
56
* editor, in order to highlight CL_BREAK_IF as as keyword, as well as CL_TRAP
57
*/
58
# define CL_BREAK_IF(cond) do { \
59
if (!(cond)) \
60
break; \
61
\
62
fprintf(stderr, "%s:%d: conditional breakpoint fired: " \
63
"CL_BREAK_IF(%s)\n", __FILE__, __LINE__, #cond); \
64
\
65
CL_TRAP; \
66
} while (0)
67
68
#else
/* NDEBUG */
69
# define CL_BREAK_IF(cond) do { } while (0)
70
#endif
Generated on Mon Nov 9 2015 14:51:59 for Predator by
1.8.1.2