Skip to content

Commit

Permalink
Some bytecode debugging, fixing typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasWM committed Feb 19, 2024
1 parent e2c4892 commit eb85864
Show file tree
Hide file tree
Showing 8 changed files with 701 additions and 219 deletions.
823 changes: 643 additions & 180 deletions Monitor/TFLMonitor.cpp

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions Monitor/TFLMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
#include <K/Defines/KDefinitions.h>
#include "Monitor/TMonitor.h"

class TFLTerminal;
class Fl_Window;
class Fl_Terminal;
class Fl_Button;
class Fl_Input;
class Fl_Box;

class TFLMonitor : public TMonitor
{
Expand Down Expand Up @@ -63,6 +64,10 @@ class TFLMonitor : public TMonitor
///
// void PrintLine(const char* inLine, int type) override;

const char* FormatNSCallArgs(char* buffer, size_t size, int nArgs, int nNames);
const char* FormatNSValueStack(char* buffer, size_t size, int nArgs);
const char* FormatNSLiteral(char* buffer, size_t size, int index);

private:
///
/// Draw screen when the emulator is halted.
Expand All @@ -75,14 +80,16 @@ class TFLMonitor : public TMonitor
void DrawScreenRunning(void);

Fl_Window* mwWindow = nullptr;
Fl_Terminal* mwTerminal = nullptr;
TFLTerminal* mwTerminal = nullptr;
Fl_Button* mwPause = nullptr;
Fl_Button* mwRun = nullptr;
Fl_Button* mwStepOver = nullptr;
Fl_Button* mwStep = nullptr;
Fl_Button* mwLeave = nullptr;
Fl_Input* mwInput = nullptr;
Fl_Box* mwBox = nullptr;
Fl_Button* mwHelp = nullptr;
Fl_Button* mwBCPause = nullptr;
Fl_Button* mwBCRun = nullptr;
};

#endif // T_FL_MONITOR_H
23 changes: 17 additions & 6 deletions Monitor/TMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ TMonitor::TMonitor(
mProcessor(inEmulator->GetProcessor()),
mInterruptManager(inEmulator->GetInterruptManager()),
mLog(inLog),
mHalted(true),
mCommand(kNop),
mFilename(nullptr),
mLastScreenHalted(true),
mMonitorStartupScriptPath(strdup(inMonitorStartupScriptPath))
{
mMemory = inEmulator->GetMemory();
Expand Down Expand Up @@ -531,7 +527,7 @@ TMonitor::Stop()
ReleaseMutex();
}

// little helper to return the prinatble version of any character
// little helper to return the printable version of any character
static char
cc(unsigned int v)
{
Expand Down Expand Up @@ -1343,6 +1339,16 @@ TMonitor::ExecuteCommand(const char* inCommand)
} else if (::strcmp(inCommand, "cdr") == 0)
{
::chdir(mROMImageDir);
} else if (::strcmp(inCommand, ".stop") == 0)
{ // break before byte code grab in TInterpreter::FastRun1()
mMemory->SetBreakpoint(0x002EE1D8, kPermanentBP);
mCommand = kRun;
SignalCondVar();
} else if (::strcmp(inCommand, ".run") == 0)
{ // clear break before byte code grab in TInterpreter::FastRun1()
mMemory->ClearBreakpoint(0x002EE1D8);
mCommand = kRun;
SignalCondVar();
} else if (inCommand[0] == '!')
{
theResult = ExecuteScript(inCommand + 1);
Expand Down Expand Up @@ -1667,7 +1673,7 @@ TMonitor::DrawScreenHalted(void)

KUInt32 instruction;

// Write 5 lines.
// Write 5 lines in ARM code.
int indexLines;
for (indexLines = 0; indexLines < 20; indexLines += 4)
{
Expand Down Expand Up @@ -1959,6 +1965,9 @@ TMonitor::PrintNSRef(KUInt32 inRef)
int
TMonitor::FormatNSRef(char* buffer, size_t bufferSize, KUInt32 inRef, int indent, int maxDepth)
{
if (bufferSize <= 0)
return 0;

switch (inRef & 0x3)
{
case kTagInteger: {
Expand Down Expand Up @@ -2053,6 +2062,8 @@ TMonitor::FormatNSRef(char* buffer, size_t bufferSize, KUInt32 inRef, int indent
int
TMonitor::FormatNSFrame(char* buffer, size_t bufferSize, KUInt32 inAddr, unsigned int length, KUInt32 mapRef, int indent, int maxDepth)
{
if (bufferSize <= 0)
return 0;

KUInt32* flattenMap = (KUInt32*) ::malloc(length * sizeof(KUInt32));
int mapIndex = length;
Expand Down
40 changes: 21 additions & 19 deletions Monitor/TMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class TMonitor : public TMonitorCore
return mEmulator;
}

private:
protected:
///
/// Run the emulator (handle breakpoint if we're on a BP).
///
Expand Down Expand Up @@ -377,41 +377,43 @@ class TMonitor : public TMonitorCore
///
int FormatNSBinary(char* buffer, size_t bufferSize, KUInt32 addr, unsigned int length, KUInt32 classRef, int indent, int maxDepth);

private:
///
/// Constructeur par copie volontairement indisponible.
///
/// \param inCopy objet à copier
///
TMonitor(const TMonitor& inCopy);
TMonitor(const TMonitor& inCopy) = delete;

///
/// Opérateur d'assignation volontairement indisponible.
///
/// \param inCopy objet à copier
///
TMonitor& operator=(const TMonitor& inCopy);
TMonitor& operator=(const TMonitor& inCopy) = delete;

protected:
/// \name Variables
TEmulator* mEmulator; ///< Emulator.
TARMProcessor* mProcessor; ///< CPU.
TInterruptManager* mInterruptManager; ///< Interrupt manager.
TBufferLog* mLog; ///< Interface to the log.
Boolean mHalted; ///< If the emulator is halted.
TCondVar* mCondVar = nullptr;
TMutex* mMutex = nullptr;
ECommand mCommand; ///< Next command for the
///< monitor thread.
char* mFilename; ///< Argument for next command.
TEmulator* mEmulator { nullptr }; ///< Emulator.
TARMProcessor* mProcessor { nullptr }; ///< CPU.
TInterruptManager* mInterruptManager { nullptr }; ///< Interrupt manager.
TBufferLog* mLog { nullptr }; ///< Interface to the log.
Boolean mHalted { false }; ///< If the emulator is halted.
TCondVar* mCondVar { nullptr };
TMutex* mMutex { nullptr };
ECommand mCommand { kNop }; ///< Next command for the
///< monitor thread.
char* mFilename { nullptr }; ///< Argument for next command.
#if TARGET_UI_FLTK
// no signalling between monitor and log yet
// no signaling between monitor and log yet
#else
int mSocketPair[2]; ///< Socket pair for monitor state changes.
int mSocketPair[2] { -1, -1 }; ///< Socket pair for monitor state changes.
#endif
Boolean mLastScreenHalted; ///< If last screen was halted.
char* mMonitorStartupScriptPath; ///< path to monitor startup script file
char* mROMImageDir; /// < path to the ROM file directory
Boolean mLastScreenHalted { true }; ///< If last screen was halted.
char* mMonitorStartupScriptPath { nullptr }; ///< path to monitor startup script file
char* mROMImageDir { nullptr }; /// < path to the ROM file directory

Boolean mRunOnStartup = false; ///< Run the emulation as soon as the monitor starts
Boolean mRunOnStartup { false }; ///< Run the emulation as soon as the monitor starts
};

#endif
Expand Down
4 changes: 1 addition & 3 deletions Monitor/TMonitorCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
#include "Emulator/JIT/JIT.h"

TMonitorCore::TMonitorCore(TSymbolList* inSymbolList) :
mMemory(0L),
mSymbolList(inSymbolList),
mDisasm(nullptr)
mSymbolList(inSymbolList)
{
}

Expand Down
6 changes: 3 additions & 3 deletions Monitor/TMonitorCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class TMonitorCore
virtual Boolean ExecuteCommand(const char* inCommand);

/// \name Variables
TMemory* mMemory; ///< Memory.
TSymbolList* mSymbolList; ///< List of symbols.
UDisasm* mDisasm; ///< Disassembler
TMemory* mMemory { nullptr }; ///< Memory.
TSymbolList* mSymbolList { nullptr }; ///< List of symbols.
UDisasm* mDisasm { nullptr }; ///< Disassembler
};

#endif
Expand Down
9 changes: 5 additions & 4 deletions Toolkit/TToolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
containing an array named 'programCounter'. The array holds one frame per
breakpoint. Those frames have the fields:
'programCounter' : checks if the current instruction offset matches
'instrcutions' : points at the current instructions binary ref(?) and must match
'disabled' : is TRUE or NIL to disable or anable the breakpoint
'instructions' : points at the current instructions binary ref(?) and must match
'disabled' : is TRUE or NIL to disable or enable the breakpoint
'temporary' : the breakpoint is removed from the array when it is hit
If breakpoints are enabled, TInterpreter switches to Slow mode.
Expand Down Expand Up @@ -1097,7 +1097,8 @@ TToolkit::AppBuild()
const char* errStr = NewtRefToString(errRef);
PrintErr(errStr);
}
// PrintErr(mPkgPath);
::snprintf(buf, sizeof(buf), "Package saved to: %s\n", mPkgPath);
PrintStd(buf);

NewtCleanup();
}
Expand Down Expand Up @@ -1169,7 +1170,7 @@ TToolkit::AppStop()
}

/**
Send a NewtonScrippt line to Einstein and run it there.
Send a NewtonScript line to Einstein and run it there.
\note Running NewtonScript this way is limited to 256 characters.
Expand Down
2 changes: 1 addition & 1 deletion Toolkit/TToolkitScriptExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ RegisterToolkitScriptExtensions()
NewtObjSetSlot(fltk_obj, NSSYM(filechooser), NewtMakeNativeFunc0((void*) NsFltkFileChooser, 4, false, (char*) "Open a file chooser dialog (message, pattern, filename, relative) => filename or NIL"));
NcDefGlobalVar(NSSYM(fltk), fltk);

// the FILE namespace for reading and writing files on the hos machine
// the FILE namespace for reading and writing files on the host machine
auto file = NewtMakeFrame(kNewtRefNIL, 0);
newtObjRef file_obj = (newtObjRef) NewtRefToPointer(file);
NewtObjSetSlot(file_obj, NSSYM(new), NewtMakeNativeFunc0((void*) NsFileNew, 0, false, (char*) "Create a frame to access files on the host machine."));
Expand Down

0 comments on commit eb85864

Please sign in to comment.