HPCToolkit
debug-flag.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //*****************************************************************************
48 // File: debug-flag.c
49 //
50 // Description:
51 // debug flags management for hpcrun
52 //
53 // History:
54 // 23 July 2009 - John Mellor-Crummey
55 // created by splitting off from message-sync.c
56 //
57 //*****************************************************************************
58 
59 
60 
61 //*****************************************************************************
62 // global includes
63 //*****************************************************************************
64 
65 #include <stdlib.h>
66 #include <string.h>
67 #include <stdio.h>
68 
69 
70 
71 //*****************************************************************************
72 // local includes
73 //*****************************************************************************
74 
75 #include "messages/debug-flag.h"
76 #include "monitor.h"
77 #include <utilities/tokenize.h>
78 
79 extern void unlimit_msgs(void);
80 
81 //*****************************************************************************
82 // global variables
83 //*****************************************************************************
84 
85 static char *dbg_tbl[] = {
86 # undef E
87 # define E(s) #s
88 # include "messages.flag-defns"
89 # undef E
90 };
91 
92 
93 typedef struct flag_list_t {
94  int n_entries;
96 } flag_list_t;
97 
98 
100 #define E(s) DBG_PREFIX(s)
101  E(INIT),
102  E(FINI),
103  E(FIND),
104  E(INTV),
105  E(ITIMER_HANDLER),
106  E(ITIMER_CTL),
107  E(CPU_GPU_BLAME_CTL),
108  E(_TST_HANDLER),
109  E(_TST_CTL),
110  E(UNW),
111  // E(UW_RECIPE_MAP),
112  E(TRAMP),
113  E(SEGV),
114  E(MPI),
115  E(INTV2),
116  E(INTV_ERR),
117  E(TROLL),
118  E(DROP),
119  E(UNW_INIT),
120  E(BASIC_INIT),
121  E(SAMPLE),
122  E(SWIZZLE),
123  E(FINALIZE),
124  E(DATA_WRITE),
125  E(PAPI),
126  E(PAPI_SAMPLE),
127  E(PAPI_EVENT_NAME),
128  E(UPC),
129  E(DBG),
130  E(THREAD),
131  E(PROCESS),
132  E(LOADMAP),
133  E(HANDLING_SAMPLE),
134  // E(MEM),
135  // E(MEM2),
136  E(SAMPLE_FILTER),
137  // E(THREAD_SPECIFIC),
138  E(THREAD_CTXT),
139  E(DL_BOUND),
140  E(ADD_MODULE_BASE),
141  E(DL_ADD_MODULE),
142  E(OPTIONS),
143  // E(PRE_FORK),
144  // E(POST_FORK),
145  E(EVENTS),
146  // E(SYSTEM_SERVER),
147  // E(SYSTEM_COMMAND),
148  // E(AS_add_source),
149  // E(AS_started),
150  // E(AS_MAP),
151  // E(SS_COMMON),
152  E(METRICS),
153  E(UNW_CONFIG),
154  E(UNW_STRATEGY),
155  E(BACKTRACE),
156  E(SUSPENDED_SAMPLE),
157  // E(MMAP),
158  // E(MALLOC),
159  // E(CSP_MALLOC),
160  // E(MEM__ALLOC),
161  E(NORM_IP),
162  E(PARTIAL_UNW)
163 };
164 
165 
167  .n_entries = sizeof(all_list_entries)/sizeof(all_list_entries[0]),
168  .entries = all_list_entries
169 };
170 
171 
172 #define N_DBG_CATEGORIES sizeof(dbg_tbl)/sizeof(dbg_tbl[0])
174 
175 
176 
177 //*****************************************************************************
178 // forward declarations
179 //*****************************************************************************
180 
181 static void debug_flag_set_all(int v);
182 
183 static void debug_flag_process_string(char *in, int debug_initialization);
184 
185 static void debug_flag_process_env(int debug_initialization);
186 
187 static const char *debug_flag_name_get(int i);
188 
189 
190 //*****************************************************************************
191 // interface operations
192 //*****************************************************************************
193 
195 {
196  char *df_trace = getenv("HPCRUN_DEBUG_FLAGS_DEBUG");
197  int debug_mode_only = (df_trace == 0) ? 0 : 1;
198 
200  debug_flag_process_env(debug_mode_only);
201 
202  if (debug_mode_only){
203  monitor_real_exit(1);
204  }
205 }
206 
207 
208 void
210 {
211  dbg_flags[flag] = val;
212 }
213 
214 
215 int
217 {
218  return dbg_flags[flag];
219 }
220 
221 
222 void
224 {
225  for (int i=0; i < N_DBG_CATEGORIES; i++){
226  if (i < N_DBG_CATEGORIES){
227  fprintf(stderr,"debug flag %s = %d\n", debug_flag_name_get(i),
228  debug_flag_get(i));
229  } else {
230  fprintf(stderr,"debug flag (unknown) = %d\n", i);
231  }
232  }
233 }
234 
235 
236 
237 //*****************************************************************************
238 // private operations
239 //*****************************************************************************
240 
241 static void
243 {
244  for(int i=0; i < N_DBG_CATEGORIES; i++){
245  debug_flag_set(i, v);
246  }
247 }
248 
249 
250 static void
252 {
253  for (int i=0; i < flag_list->n_entries; i++){
254  debug_flag_set(flag_list->entries[i], v);
255  }
256 }
257 
258 
259 static const char *
261 {
262  const char *result = NULL;
263  if (i < N_DBG_CATEGORIES) {
264  result = dbg_tbl[i];
265  }
266  return result;
267 }
268 
269 
270 static int
272 {
273  for (int i = 0; i < N_DBG_CATEGORIES; i++){
274  if (strcmp(dbg_tbl[i],s) == 0){
275  return i;
276  }
277  }
278  return -1;
279 }
280 
281 
282 static void
283 debug_flag_process_string(char *in, int debug_initialization)
284 {
285  if (debug_initialization) {
286  fprintf(stderr, "debug flag input string = %s\n\n", in);
287  }
288 
289  for (char *f=start_tok(in); more_tok(); f = next_tok()){
290  unlimit_msgs();
291  if (strcmp(f,"ALL") == 0){
292  debug_flag_set_list(&all_list, 1);
293  continue;
294  }
295  if (debug_initialization) {
296  fprintf(stderr, "\tprocessing debug flag token %s\n", f);
297  }
298  int ii = debug_flag_name_lookup(f);
299  if (ii >= 0){
300  if (debug_initialization) {
301  fprintf(stderr, "\tdebug flag token value = %d\n\n", ii);
302  }
303  debug_flag_set(ii,1);
304  }
305  else {
306  fprintf(stderr, "\tdebug flag token %s not recognized\n\n", f);
307  }
308  }
309 }
310 
311 
312 static void
313 debug_flag_process_env(int debug_initialization)
314 {
315  char *s = getenv("HPCRUN_DEBUG_FLAGS");
316  if(s){
317  debug_flag_process_string(s, debug_initialization);
318  }
319 }
320 
#define N_DBG_CATEGORIES
Definition: debug-flag.c:172
void debug_flag_dump()
Definition: debug-flag.c:223
void debug_flag_set(pmsg_category flag, int val)
Definition: debug-flag.c:209
struct flag_list_t flag_list_t
#define E(s)
static void debug_flag_process_string(char *in, int debug_initialization)
Definition: debug-flag.c:283
static flag_list_t all_list
Definition: debug-flag.c:166
void debug_flag_init()
Definition: debug-flag.c:194
pmsg_category
Definition: debug-flag.h:89
static void debug_flag_set_list(flag_list_t *flag_list, int v)
Definition: debug-flag.c:251
#define DBG
Definition: VMAInterval.cpp:84
static char * dbg_tbl[]
Definition: debug-flag.c:85
static void debug_flag_process_env(int debug_initialization)
Definition: debug-flag.c:313
char * next_tok(void)
Definition: tokenize.c:87
static int debug_flag_name_lookup(const char *s)
Definition: debug-flag.c:271
void unlimit_msgs(void)
static const char * debug_flag_name_get(int i)
Definition: debug-flag.c:260
static int dbg_flags[N_DBG_CATEGORIES]
Definition: debug-flag.c:173
static void debug_flag_set_all(int v)
Definition: debug-flag.c:242
char * start_tok(char *lst)
Definition: tokenize.c:70
static pmsg_category all_list_entries[]
Definition: debug-flag.c:99
int debug_flag_get(pmsg_category flag)
Definition: debug-flag.c:216
#define NULL
Definition: ElfHelper.cpp:85
int n_entries
Definition: debug-flag.c:94
int more_tok(void)
Definition: tokenize.c:78
pmsg_category * entries
Definition: debug-flag.c:95