-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.cc
More file actions
78 lines (64 loc) · 1.74 KB
/
debug.cc
File metadata and controls
78 lines (64 loc) · 1.74 KB
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
#include "debug.h"
#include <stdexcept>
#include <string>
#include "argpc.h"
#include "argpcoption.h"
static bool debug_settings[DEBUG_LEVEL_MAX] = { 0 };
struct {
const char *name;
DebugLevel val;
} static debugLabels[] = {
{ "dependencies", DEBUG_DEPENDENCIES },
{ "subprocess", DEBUG_SUBPROCESS },
{ "reason", DEBUG_REASON },
{ "1", DEBUG_LEVEL_1 },
{ "2", DEBUG_LEVEL_2 },
};
static void debug_mode( std::string option )
{
unsigned int i;
for( i = 0; i< sizeof(debugLabels)/sizeof(debugLabels[0]); i ++ ) {
if( option == debugLabels[ i ].name ) {
enable_debug( debugLabels[ i ].val );
return;
}
}
}
void debug_init()
{
unsigned int i;
ArgpcOption debugOption( "debug", 'd', "debuglevel", "Ouput debugging information", debug_mode );
for( i = 0; i< sizeof(debugLabels)/sizeof(debugLabels[0]); i ++ ) {
debugOption.addValue( debugLabels[ i ].name );
}
Argpc::getInstance()->addOption( debugOption );
}
static void debug_set_to_level(DebugLevel level)
{
int i;
for( i = 0; i < level; i ++ ) {
debug_settings[ i ] = true;
}
for( ; i < DEBUG_LEVEL_MAX; i ++ ) {
debug_settings[ i ] = false;
}
}
bool enable_debug(DebugLevel level)
{
if( level >= DEBUG_LEVEL_MAX ) throw std::runtime_error( "Invalid debug level" );
switch(level) {
case DEBUG_LEVEL_1:
case DEBUG_LEVEL_2:
debug_set_to_level( level );
break;
default:
debug_settings[ level ] = true;
break;
}
return true;
}
bool get_debug_level(DebugLevel level)
{
if( level >= DEBUG_LEVEL_MAX ) throw std::runtime_error( "Invalid debug level" );
return debug_settings[ level ];
}