make the watchpoint (optionally) conditional

This commit is contained in:
Bill Currie 2007-05-08 02:25:01 +00:00 committed by Jeff Teunissen
parent fe4a4a9e55
commit 57bd43fc52
3 changed files with 26 additions and 5 deletions

View File

@ -1454,6 +1454,8 @@ struct progs_s {
struct pr_lineno_s *linenos; struct pr_lineno_s *linenos;
ddef_t *local_defs; ddef_t *local_defs;
pr_type_t *watch; pr_type_t *watch;
int wp_conditional;
pr_type_t wp_val;
//@} //@}
/// required globals (for OP_STATE) /// required globals (for OP_STATE)

View File

@ -137,6 +137,9 @@ PR_Debug_Watch (progs_t *pr, const char *expr)
if (pr->watch) { if (pr->watch) {
Sys_Printf (" watching [%d]\n", Sys_Printf (" watching [%d]\n",
(int) (intptr_t) (pr->watch - pr->pr_globals)); (int) (intptr_t) (pr->watch - pr->pr_globals));
if (pr->wp_conditional)
Sys_Printf (" if new val == %d\n",
pr->wp_val.integer_var);
} else { } else {
Sys_Printf (" none active\n"); Sys_Printf (" none active\n");
} }
@ -165,8 +168,6 @@ PR_Debug_Watch (progs_t *pr, const char *expr)
field = PR_FindField (pr, ws->token->str); field = PR_FindField (pr, ws->token->str);
if (!field) if (!field)
goto error; goto error;
if (Script_TokenAvailable (ws, 1))
Sys_Printf ("ignoring tail\n");
pr->watch = &ent->v[field->ofs]; pr->watch = &ent->v[field->ofs];
} else { } else {
ddef_t *global = PR_FindGlobal (pr, ws->token->str); ddef_t *global = PR_FindGlobal (pr, ws->token->str);
@ -174,12 +175,28 @@ PR_Debug_Watch (progs_t *pr, const char *expr)
goto error; goto error;
pr->watch = PR_GetPointer (pr, global->ofs); pr->watch = PR_GetPointer (pr, global->ofs);
} }
pr->wp_conditional = 0;
if (Script_TokenAvailable (ws, 1)) {
if (!Script_GetToken (ws, 1) && !strequal (ws->token->str, "==" ))
goto error;
if (!Script_GetToken (ws, 1))
goto error;
pr->wp_val.integer_var = strtol (ws->token->str, &e, 0);
if (e == ws->token->str)
goto error;
pr->wp_conditional = 1;
}
if (Script_TokenAvailable (ws, 1))
Sys_Printf ("ignoring tail\n");
} }
error: error:
if (pr->watch) if (pr->watch) {
Sys_Printf ("watchpoint set to [%d]\n", PR_SetPointer (pr, pr->watch)); Sys_Printf ("watchpoint set to [%d]\n", PR_SetPointer (pr, pr->watch));
else if (pr->wp_conditional)
Sys_Printf (" if new val == %d\n", pr->wp_val.integer_var);
} else {
Sys_Printf ("watchpoint cleared\n"); Sys_Printf ("watchpoint cleared\n");
}
} }
void void

View File

@ -1020,7 +1020,9 @@ op_call:
default: default:
PR_RunError (pr, "Bad opcode %i", st->op); PR_RunError (pr, "Bad opcode %i", st->op);
} }
if (watch && watch->integer_var != old_val.integer_var) if (watch && watch->integer_var != old_val.integer_var
&& (!pr->wp_conditional
|| watch->integer_var == pr->wp_val.integer_var))
PR_RunError (pr, "watchpoint hit: %d -> %d", old_val.integer_var, PR_RunError (pr, "watchpoint hit: %d -> %d", old_val.integer_var,
watch->integer_var); watch->integer_var);
} }