Skip to content

Commit 175f737

Browse files
committed
Add some DEBUG_DISABLE checks
1 parent 8b15a89 commit 175f737

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

backends/brkdebug.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ int AsmDebug_CodeGen(AST *ast, BackendDebugEval evalFunc, void *evalArg) {
161161
AST *exprbase;
162162
int regNum = 0;
163163
bool do_cogn = false;
164-
164+
165+
/* check for DEBUG_DISABLE */
166+
if (const_or_default(current, "DEBUG_DISABLE", 0) != 0) {
167+
return -1;
168+
}
169+
/* sanity check on codes */
165170
if (brkCode >= MAX_BRK) {
166171
ERROR(ast,"MAX_BRK exceeded!");
167172
return -1;
@@ -329,16 +334,6 @@ static void patch_long(char *where,int32_t val) {
329334
*where++ = (val>>24)&255;
330335
}
331336

332-
static int32_t const_or_default(Module *M,const char *name,int32_t defaultval) {
333-
Symbol *sym = FindSymbol(&M->objsyms,name);
334-
if (sym && sym->kind == SYM_CONSTANT) {
335-
return EvalConstExpr((AST *)sym->v.ptr);
336-
} else {
337-
return defaultval;
338-
}
339-
}
340-
341-
342337

343338
Flexbuf CompileBrkDebugger(size_t appsize) {
344339
Flexbuf f;

expr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,3 +4137,11 @@ AST *DerefType(AST *typ) {
41374137
return typ;
41384138
}
41394139

4140+
int32_t const_or_default(Module *M, const char *name, int32_t defaultval) {
4141+
Symbol *sym = FindSymbol(&M->objsyms,name);
4142+
if (sym && sym->kind == SYM_CONSTANT) {
4143+
return EvalConstExpr((AST *)sym->v.ptr);
4144+
} else {
4145+
return defaultval;
4146+
}
4147+
}

expr.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ AST *BuildExprlistFromObject(AST *expr, AST *typ);
186186
// handles designators like .x = n, and adds any missing 0's
187187
AST *FixupInitList(AST *typ, AST *initval);
188188

189+
/* get a const value as either a constant or a default value */
190+
int32_t const_or_default(Module *M, const char *name, int32_t defaultval);
191+
189192
/* type name */
190193
const char *TypeName(AST *typ);
191194

frontends/printdebug.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ CreatePrintfDebug(AST *exprlist)
130130
struct flexbuf fb;
131131
const char *fmtstr;
132132
int needcomma = 0;
133-
133+
134+
if (0 != const_or_default(current, "DEBUG_DISABLE", 0)) {
135+
return NULL;
136+
}
134137
flexbuf_init(&fb, 1024);
135138

136139
if (exprlist && exprlist->left && exprlist->left->kind == AST_LABEL) {

0 commit comments

Comments
 (0)