Skip to content

Commit

Permalink
Merge pull request #549 from metaeducation/break
Browse files Browse the repository at this point in the history
Add a native to set C break point
  • Loading branch information
zsx committed Jun 15, 2017
2 parents ddc0d9f + 0e7fee6 commit 535df3f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/core/b-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,32 @@ static void Init_Contexts_Object(void)
Init_Object(Get_System(SYS_CONTEXTS, CTX_USER), Lib_Context);
}

#ifndef NDEBUG
//
// Init_Break_Point: C
//
// This initializes the break point from env in the debug build
//
static void Init_Break_Point(void)
{
TG_Break_At = 0;

const char *env_break_at = getenv("R3_BREAK_AT");
if (env_break_at != NULL) {
i64 break_at = CHR_TO_INT(cb_cast(env_break_at));;
if(break_at > 0) {
Debug_Str(
"**\n"
"** R3_ALWAYS_MALLOC is TRUE in environment variable!\n"
"** Memory allocations aren't pooled, expect slowness...\n"
"**\n"
);
TG_Break_At = cast(REBUPT, break_at);
}
}
}
#endif


//
// Startup_Task: C
Expand Down Expand Up @@ -1098,6 +1124,11 @@ void Startup_Core(void)
Assert_Basics();
PG_Boot_Time = OS_DELTA_TIME(0, 0);

#ifndef NDEBUG
// This might call Debug_Str, which depends on StdIO, and must be called after Start_StdIO;
Init_Break_Point();
#endif

//==//////////////////////////////////////////////////////////////////////==//
//
// INITIALIZE MEMORY AND ALLOCATORS
Expand Down
2 changes: 1 addition & 1 deletion src/core/c-eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static inline REBOOL Start_New_Expression_Throws(REBFRM *f) {
do { \
START_NEW_EXPRESSION_MAY_THROW_COMMON(f, g); \
do_count = Do_Core_Expression_Checks_Debug(f); \
if (do_count == DO_COUNT_BREAKPOINT) { \
if (do_count == TG_Break_At || do_count == DO_COUNT_BREAKPOINT) { \
Debug_Fmt("DO_COUNT_BREAKPOINT at %d", f->do_count_debug); \
Dump_Frame_Location(f); \
debug_break(); /* see %debug_break.h */ \
Expand Down
33 changes: 33 additions & 0 deletions src/core/n-system.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,36 @@ REBNATIVE(check)
return R_TRUE;
#endif
}

//
// c-break-debug: native [
//
// "Break at next evaluation point, use ONLY when running under a C debugger"
// return: [<opt>]
// /skip
// points [integer!]
// {points to skip before breaking: 0 being next point}
// /at
// point [integer!]
// {Break at a certain point}
// ]
//
REBNATIVE(c_break_debug)
{
#ifndef NDEBUG
INCLUDE_PARAMS_OF_C_BREAK_DEBUG;

if (REF(skip) && REF(at)) {
fail (Error_Bad_Refines_Raw());
} else if (REF(skip)) {
TG_Break_At = frame_->do_count_debug + 1 + VAL_INT64(ARG(points));
} else if (REF(at)) {
TG_Break_At = VAL_INT64(ARG(point));
} else {
TG_Break_At = frame_->do_count_debug + 1;
}
#else
UNUSED(frame_);
#endif
return R_VOID;
}
1 change: 1 addition & 0 deletions src/include/sys-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ TVAR REBUPT Stack_Limit; // Limit address for CPU stack.
// other than Do_Next that are contingent on a certain "tick" elapsing.
//
TVAR REBUPT TG_Do_Count;
TVAR REBUPT TG_Break_At; // The do_count to break

TVAR REBIPT TG_Num_Black_Series;
#endif
Expand Down

0 comments on commit 535df3f

Please sign in to comment.