build and install parseThat with cmake
[dyninst.git] / proccontrol / h / PCErrors.h
1 /*
2  * See the dyninst/COPYRIGHT file for copyright information.
3  *
4  * We provide the Paradyn Tools (below described as "Paradyn")
5  * on an AS IS basis, and do not warrant its validity or performance.
6  * We reserve the right to update, modify, or discontinue this
7  * software at any time.  We shall have no obligation to supply such
8  * updates or modifications or any other form of support to you.
9  *
10  * By your use of Paradyn, you understand and agree that we (or any
11  * other person or entity with proprietary rights in Paradyn) are
12  * under no obligation to provide either maintenance services,
13  * update services, notices of latent defects, or correction of
14  * defects for Paradyn.
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or (at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29  */
30
31 #if !defined(PCERRORS_H_)
32 #define PCERRORS_H_
33
34 // Only works on posix-compliant systems. IE not windows.
35 //#define PROCCTRL_PRINT_TIMINGS 1
36
37 // Will really change timings
38 //#define PROCCTRL_LOCK_PRINTS 1
39
40 #include <stdio.h>
41 #include <string.h>
42 #include "util.h"
43 #include "dyntypes.h"
44
45 PC_EXPORT extern void pc_print_lock();
46 PC_EXPORT extern void pc_print_unlock();
47 #if defined(PROCCTRL_LOCK_PRINTS)
48 #define PC_PRINT_LOCK pc_print_lock()
49 #define PC_PRINT_UNLOCK pc_print_unlock()
50 #else
51 #define PC_PRINT_LOCK
52 #define PC_PRINT_UNLOCK
53 #endif
54
55 #define pclean_printf(format, ...)                          \
56    do {                                                     \
57      if (dyninst_debug_proccontrol) {                       \
58         PC_PRINT_LOCK;                                      \
59         fprintf(pctrl_err_out, format, ## __VA_ARGS__);     \
60         PC_PRINT_UNLOCK;                                    \
61      }                                                      \
62   } while (0)
63
64 #if defined(PROCCTRL_PRINT_TIMINGS)
65
66 #define pthrd_printf(format, ...)                                       \
67    do {                                                                 \
68       if (dyninst_debug_proccontrol) {                                  \
69          PC_PRINT_LOCK;                                                 \
70          fprintf(pctrl_err_out, "[%s:%u-%s@%lu] - " format, FILE__, __LINE__, \
71                  thrdName(), gettod(), ## __VA_ARGS__);                 \
72          PC_PRINT_UNLOCK;                                               \
73       }                                                                 \
74    } while (0)
75
76 #define perr_printf(format, ...)                                        \
77    do {                                                                 \
78       if (dyninst_debug_proccontrol) {                                  \
79          PC_PRINT_LOCK;                                                 \
80          fprintf(pctrl_err_out, "[%s:%u-%s@%lu] - Error: " format, FILE__, __LINE__, thrdName(), gettod(), ## __VA_ARGS__); \
81          PC_PRINT_UNLOCK;                                               \
82       }                                                                 \
83    } while (0)
84
85 #else
86
87 #define pthrd_printf(format, ...)                                       \
88    do {                                                                 \
89       if (dyninst_debug_proccontrol) {                                  \
90          PC_PRINT_LOCK;                                                 \
91          fprintf(pctrl_err_out, "[%s:%u-%s] - " format, FILE__, __LINE__, thrdName(), ## __VA_ARGS__); \
92          PC_PRINT_UNLOCK;                                               \
93       }                                                                 \
94    } while (0)
95
96 #define perr_printf(format, ...)                \
97    do {                                                                 \
98       if (dyninst_debug_proccontrol) {                                  \
99          PC_PRINT_LOCK;                                                 \
100          fprintf(pctrl_err_out, "[%s:%u-%s] - Error: " format, FILE__, __LINE__, thrdName(), ## __VA_ARGS__); \
101          PC_PRINT_UNLOCK;                                               \
102       }                                                                 \
103    } while (0)
104
105 #define parmerr_printf(format, ...)                \
106    do {                                                                 \
107       if (dyninst_debug_proccontrol) {                                  \
108          PC_PRINT_LOCK;                                                 \
109          fprintf(pctrl_err_out, "[%s:%u-%s] - Error-ARM: " format, FILE__, __LINE__, thrdName(), ## __VA_ARGS__); \
110          PC_PRINT_UNLOCK;                                               \
111       }                                                                 \
112    } while (0)
113
114 #endif
115
116 PC_EXPORT extern bool dyninst_debug_proccontrol;
117 PC_EXPORT extern const char *thrdName();
118 PC_EXPORT extern FILE* pctrl_err_out;
119
120 PC_EXPORT extern unsigned long gettod();
121
122 namespace Dyninst {
123 namespace ProcControlAPI {
124
125 typedef unsigned err_t;
126
127 const err_t err_none           = 0x0;
128 const err_t err_badparam       = 0x10000;
129 const err_t err_procread       = 0x10001;
130 const err_t err_internal       = 0x10002;
131 const err_t err_prem           = 0x10003;
132 const err_t err_noproc         = 0x10004;
133 const err_t err_interrupt      = 0x10005;
134 const err_t err_exited         = 0x10006;
135 const err_t err_nofile         = 0x10007;
136 const err_t err_unsupported    = 0x10008;
137 const err_t err_symtab         = 0x10009;
138 const err_t err_nothrd         = 0x1000a;
139 const err_t err_notstopped     = 0x1000b;
140 const err_t err_notrunning     = 0x1000c;
141 const err_t err_noevents       = 0x1000d;
142 const err_t err_incallback     = 0x1000e;
143 const err_t err_nouserthrd     = 0x1000f;
144 const err_t err_detached       = 0x10010;
145 const err_t err_attached       = 0x10011;
146 const err_t err_pendingirpcs   = 0x10012;
147 const err_t err_bpfull         = 0x10013;
148 const err_t err_notfound       = 0x10014;
149 //Next seven are BGQ errors.  They usually indicates a problem
150 // on the system, not with user programs
151 const err_t err_cauthority     = 0x10100;
152 const err_t err_dsigstop       = 0x10101;
153 const err_t err_dthrdquery     = 0x10102;
154 const err_t err_dthrdstop      = 0x10103;
155 const err_t err_dattachack     = 0x10104;
156 const err_t err_dcaack         = 0x10105;
157 const err_t err_dstep          = 0x10106;
158 const err_t err_dstack         = 0x10107;
159 const err_t err_eof            = 0x10108;
160
161 PC_EXPORT err_t getLastError();
162 PC_EXPORT void clearLastError();
163 PC_EXPORT const char* getLastErrorMsg();
164 PC_EXPORT void globalSetLastError(err_t err, const char *msg = NULL);
165 PC_EXPORT void setDebugChannel(FILE *f);
166 PC_EXPORT void setDebug(bool enable);
167 PC_EXPORT const char *getGenericErrorMsg(err_t e);
168 PC_EXPORT FILE *getDebugChannel();
169
170 }
171 }
172
173 #endif