Skip to content

Commit

Permalink
Initial code for breakpoint support.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 28, 2007
1 parent b8c1e2f commit e54186a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 12 deletions.
63 changes: 61 additions & 2 deletions src/toby_app.c
Expand Up @@ -901,11 +901,56 @@ static int luahook_stackwalk(lua_State *L)
} /* luahook_stackwalk */


static int *breakpointLines = NULL;
static int breakpointLineCount = 0;

void TOBY_clearAllBreakpoints(void)
{
free(breakpointLines);
breakpointLines = NULL;
breakpointLineCount = 0;
} /* TOBY_clearAllBreakpoints */


int TOBY_addBreakpointLine(int line)
{
const size_t newSize = sizeof (int) * (breakpointLineCount + 1);
void *ptr = realloc(breakpointLines, newSize);
if (ptr == NULL)
return -1;

/* !!! FIXME: sort into array, don't append. */
/* !!! FIXME: make sure it's not already in the array. */
breakpointLines = (int *) ptr;
breakpointLines[breakpointLineCount++] = line;
return breakpointLineCount-1;
} /* TOBY_addBreakpointLine */


static int isBreakpointLine(int line)
{
int retval = -1;
if (breakpointLines != NULL)
{
int i; /* !!! FIXME: don't do a linear search here... */
for (i = 0; i < breakpointLineCount; i++)
{
if (breakpointLines[i] == line)
return i;
} /* for */
} /* if */

return retval;
} /* isBreakpointLine */


static void luaDebugHook(lua_State *L, lua_Debug *ar)
{
const int hook = ar->event;
const int line = ar->currentline;
const long startTicks = TOBY_getTicks();
long pauseTicks = -1;
int breakpoint = -1;
int shouldRedraw = (startTicks >= nextPumpTicks);

/*
Expand All @@ -918,15 +963,29 @@ static void luaDebugHook(lua_State *L, lua_Debug *ar)
if (hook == LUA_HOOKLINE)
{
const long mustDelay = TOBY_getDelayTicksPerLine();
/*printf("Now on line #%d\n", ar->currentline);*/
/*printf("Now on line #%d\n", line);*/
if (mustDelay > 0)
pauseTicks = startTicks + mustDelay;
if (TOBY_isStepping()) /* single stepping? Break here. */
execState = EXEC_PAUSED;
if ((breakpoint = isBreakpointLine(line)) != -1)
execState = EXEC_PAUSED;
} /* if */

/* !!! FIXME: maybe later. */
#if 0
if (hook == LUA_HOOKCALL)
{
if (breakpoint == -1)
{
if ((breakpoint = isBreakpointFunc(ar)) != -1)
execState = EXEC_PAUSED;
} /* if */
} /* if */
#endif

if ((TOBY_isPaused()) || (pauseTicks > 0))
TOBY_pauseReached(ar->currentline, TOBY_isPaused(), pauseTicks);
TOBY_pauseReached(line, TOBY_isPaused(), breakpoint, pauseTicks);

while ( (TOBY_isPaused()) || (pauseTicks > 0) || (shouldRedraw) )
{
Expand Down
8 changes: 6 additions & 2 deletions src/toby_app.h
Expand Up @@ -115,8 +115,12 @@ int TOBY_delay(long ms);
*/
void TOBY_runProgram(const char *source_code, int run_for_printing);

/* !!! FIXME: comment me. */
void TOBY_pauseReached(int currentline, int breakpoint, int pauseTicks);

/* !!! FIXME: comment these. */
/* !!! FIXME: breakpoint API isn't robust, but it's all I need right now. */
void TOBY_clearAllBreakpoints(void);
int TOBY_addBreakpointLine(int line);
void TOBY_pauseReached(int line, int fullstop, int breakpoint, int pauseTicks);


/*
Expand Down
2 changes: 1 addition & 1 deletion src/toby_sdl.c
Expand Up @@ -105,7 +105,7 @@ void TOBY_messageBox(const char *msg)
} /* TOBY_messageBox */


void TOBY_pauseReached(int currentline, int breakpoint, int pauseTicks)
void TOBY_pauseReached(int line, int fullstop, int breakpoint, int pauseTicks)
{
/* no-op in this implementation: no debugging facilities. */
} /* TOBY_pauseReached */
Expand Down
22 changes: 15 additions & 7 deletions src/toby_wxwidgets.cpp
Expand Up @@ -144,7 +144,7 @@ class TobyFrame : public wxFrame
inline bool isQuitting() const { return this->quitting; }

// subclasses fill in these.
virtual void pauseReached(int curLine, int breakpoint, int pauseTicks) {}
virtual void pauseReached(int line, int stopped, int bp, int ticks) {}
virtual void toggleWidgetsRunnableImpl(bool enable) {}
virtual bool shouldVetoClose() { return false; }
virtual void openFileImpl(char *buf) = 0;
Expand Down Expand Up @@ -240,7 +240,7 @@ class TobyIDEFrame : public TobyFrame
virtual char *getProgramImpl();
virtual bool shouldVetoClose();
virtual void toggleWidgetsRunnableImpl(bool enable);
virtual void pauseReached(int curLine, int breakpoint, int pauseTicks);
virtual void pauseReached(int line, int stopped, int bp, int ticks);

// wxWidgets event handlers...
void onMenuOpen(wxCommandEvent &evt);
Expand Down Expand Up @@ -371,9 +371,9 @@ void TOBY_drawTurtle(const Turtle *turtle, void *data)
} // TOBY_drawTurtle


void TOBY_pauseReached(int curLine, int breakpoint, int pauseTicks)
void TOBY_pauseReached(int line, int fullstop, int breakpoint, int ticks)
{
wxGetApp().getTobyFrame()->pauseReached(curLine, breakpoint, pauseTicks);
wxGetApp().getTobyFrame()->pauseReached(line, fullstop, breakpoint, ticks);
} // TOBY_pauseReached


Expand Down Expand Up @@ -1336,11 +1336,15 @@ bool TobyIDEFrame::shouldVetoClose()
} // TobyIDEFrame::shouldVetoClose


void TobyIDEFrame::pauseReached(int curLine, int breakpoint, int pauseTicks)
void TobyIDEFrame::pauseReached(int line, int fullstop,
int breakpoint, int pauseTicks)
{
if ((breakpoint) || (pauseTicks >= 300))
if ((fullstop) || (pauseTicks >= 300))
{
this->SetStatusText(wxString::Format(wxT("Now on line #%d"), curLine));
if (breakpoint != -1)
printf("Hit breakpoint #%d\n", breakpoint);

this->SetStatusText(wxString::Format(wxT("Now on line #%d"), line));
int csElems = 0;
const TobyDebugInfo *cs = TOBY_getCallstack(&csElems);
printf("Callstack (%d frames):\n", csElems);
Expand Down Expand Up @@ -1379,6 +1383,10 @@ void TobyIDEFrame::openFileImpl(char *prog)
delete[] prog; // don't need this anymore.
this->toggleWidgetsRunnable(true);
this->textCtrl->SetFocus();

// !!! FIXME: remove this.
//TOBY_clearAllBreakpoints();
//printf("test breakpoint: %d\n", TOBY_addBreakpointLine(18));
} // TobyIDEFrame::openFileImpl


Expand Down

0 comments on commit e54186a

Please sign in to comment.