mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-02 22:36:00 +02:00
Comptime debugging
This commit is contained in:
parent
bbb97d1490
commit
ff2e40e3bf
40 changed files with 6213 additions and 443 deletions
|
@ -225,6 +225,7 @@ namespace IDE
|
|||
Add("Comment Toggle", new => gApp.[Friend]CommentToggle, .Editor);
|
||||
Add("Compile File", new => gApp.Cmd_CompileFile);
|
||||
Add("Debug All Tests", new () => { gApp.[Friend]RunTests(true, true); });
|
||||
Add("Debug Comptime", new => gApp.DebugComptime);
|
||||
Add("Debug Normal Tests", new () => { gApp.[Friend]RunTests(false, true); });
|
||||
Add("Delete All Right", new => gApp.[Friend]DeleteAllRight);
|
||||
Add("Duplicate Line", new () => { gApp.[Friend]DuplicateLine(); });
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Threading.Tasks;
|
|||
using System.Diagnostics;
|
||||
using Beefy.utils;
|
||||
using IDE.util;
|
||||
using IDE.Compiler;
|
||||
|
||||
namespace IDE.Debugger
|
||||
{
|
||||
|
@ -80,7 +81,8 @@ namespace IDE.Debugger
|
|||
Optimized = 1,
|
||||
HasPendingDebugInfo = 2,
|
||||
CanLoadOldVersion = 4,
|
||||
WasHotReplaced = 8
|
||||
WasHotReplaced = 8,
|
||||
HadError = 0x10
|
||||
}
|
||||
|
||||
//[Flags]
|
||||
|
@ -142,6 +144,9 @@ namespace IDE.Debugger
|
|||
[CallingConvention(.Stdcall),CLink]
|
||||
static extern bool Debugger_OpenFile(char8* launchPath, char8* targetPath, char8* args, char8* workingDir, void* envBlockPtr, int32 envBlockLen, bool hotSwapEnabled);
|
||||
|
||||
[CallingConvention(.Stdcall),CLink]
|
||||
static extern bool Debugger_ComptimeAttach(void* bfCompiler);
|
||||
|
||||
[CallingConvention(.Stdcall),CLink]
|
||||
static extern bool Debugger_Attach(int32 processId, AttachFlags attachFlags);
|
||||
|
||||
|
@ -371,6 +376,7 @@ namespace IDE.Debugger
|
|||
public bool mIsRunning;
|
||||
public bool mIsRunningCompiled;
|
||||
public bool mIsRunningWithHotSwap;
|
||||
public bool mIsComptimeDebug;
|
||||
//public RunState mLastUpdatedRunState;
|
||||
public bool mCallStackDirty;
|
||||
public int32 mActiveCallStackIdx;
|
||||
|
@ -427,11 +433,21 @@ namespace IDE.Debugger
|
|||
DeleteAndNullify!(mRunningPath);
|
||||
mRunningPath = new String(launchPath);
|
||||
|
||||
mIsComptimeDebug = false;
|
||||
mIsRunningCompiled = isCompiled;
|
||||
mIsRunningWithHotSwap = hotSwapEnabled;
|
||||
return Debugger_OpenFile(launchPath, targetPath, args, workingDir, envBlock.Ptr, (int32)envBlock.Length, hotSwapEnabled);
|
||||
}
|
||||
|
||||
public bool ComptimeAttach(BfCompiler compiler)
|
||||
{
|
||||
mIsComptimeDebug = true;
|
||||
mIsRunningCompiled = false;
|
||||
mIsRunningWithHotSwap = false;
|
||||
mIsRunning = true;
|
||||
return Debugger_ComptimeAttach(compiler.mNativeBfCompiler);
|
||||
}
|
||||
|
||||
public void SetSymSrvOptions(String symCacheDir, String symSrvStr, SymSrvFlags symSrvFlags)
|
||||
{
|
||||
Debugger_SetSymSrvOptions(symCacheDir, symSrvStr, (int32)symSrvFlags);
|
||||
|
@ -439,7 +455,9 @@ namespace IDE.Debugger
|
|||
|
||||
public bool OpenMiniDump(String file)
|
||||
{
|
||||
mIsComptimeDebug = false;
|
||||
mIsRunningCompiled = false;
|
||||
mIsRunningWithHotSwap = false;
|
||||
return Debugger_OpenMiniDump(file);
|
||||
}
|
||||
|
||||
|
@ -482,6 +500,9 @@ namespace IDE.Debugger
|
|||
if (breakpoint.mThreadId != -1)
|
||||
breakpoint.mThreadId = 0;
|
||||
}
|
||||
|
||||
mIsComptimeDebug = false;
|
||||
mIsRunning = false;
|
||||
}
|
||||
|
||||
public RunState GetRunState()
|
||||
|
@ -1083,6 +1104,9 @@ namespace IDE.Debugger
|
|||
|
||||
public bool Attach(Process process, AttachFlags attachFlags)
|
||||
{
|
||||
mIsRunningCompiled = false;
|
||||
mIsComptimeDebug = false;
|
||||
mIsRunningWithHotSwap = false;
|
||||
return Debugger_Attach(process.Id, attachFlags);
|
||||
}
|
||||
|
||||
|
|
|
@ -862,7 +862,8 @@ namespace IDE
|
|||
let sourceViewPanel = GetActiveSourceViewPanel();
|
||||
if (sourceViewPanel != null)
|
||||
{
|
||||
Path.GetDirectoryPath(sourceViewPanel.mFilePath, fullDir);
|
||||
if (sourceViewPanel.mFilePath != null)
|
||||
Path.GetDirectoryPath(sourceViewPanel.mFilePath, fullDir);
|
||||
}
|
||||
else if ((gApp.mDebugger.mRunningPath != null) && (!mWorkspace.IsInitialized))
|
||||
{
|
||||
|
@ -4342,7 +4343,10 @@ namespace IDE
|
|||
if (mExecutionQueue.Count == 0)
|
||||
{
|
||||
mOutputPanel.Clear();
|
||||
OutputLine("Compiling...");
|
||||
if (mDebugger?.mIsComptimeDebug == true)
|
||||
OutputLine("Compiling with comptime debugging...");
|
||||
else
|
||||
OutputLine("Compiling...");
|
||||
Compile(.Normal, null);
|
||||
}
|
||||
}
|
||||
|
@ -4447,6 +4451,24 @@ namespace IDE
|
|||
}
|
||||
}
|
||||
|
||||
[IDECommand]
|
||||
public void DebugComptime()
|
||||
{
|
||||
if (mDebugger.mIsRunning)
|
||||
return;
|
||||
|
||||
if (IsCompiling)
|
||||
return;
|
||||
|
||||
CheckDebugVisualizers();
|
||||
mTargetDidInitBreak = true;
|
||||
mTargetStartWithStep = false;
|
||||
mDebugger.ComptimeAttach(mBfBuildCompiler);
|
||||
mDebugger.RehupBreakpoints(true);
|
||||
mBfBuildCompiler.ForceRebuild();
|
||||
Compile();
|
||||
}
|
||||
|
||||
[IDECommand]
|
||||
void RunWithoutCompiling()
|
||||
{
|
||||
|
@ -5622,6 +5644,7 @@ namespace IDE
|
|||
|
||||
subMenu = root.AddMenuItem("&Build");
|
||||
AddMenuItem(subMenu, "&Build Workspace", "Build Workspace", new => UpdateMenuItem_HasWorkspace);
|
||||
AddMenuItem(subMenu, "&Debug Comptime", "Debug Comptime", new => UpdateMenuItem_HasWorkspace);
|
||||
AddMenuItem(subMenu, "&Clean", "Clean", new => UpdateMenuItem_DebugStopped_HasWorkspace);
|
||||
AddMenuItem(subMenu, "Clean Beef", "Clean Beef", new => UpdateMenuItem_DebugStopped_HasWorkspace);
|
||||
//subMenu.AddMenuItem("Compile Current File", null, new (menu) => { CompileCurrentFile(); });
|
||||
|
@ -7211,7 +7234,7 @@ namespace IDE
|
|||
// No 'wrong hash' warnings
|
||||
}
|
||||
else if (((hash != .None) && (sourceViewPanel.mEditData != null) && (!sourceViewPanel.mEditData.CheckHash(hash))) ||
|
||||
(sourceViewPanel.mHasChangedSinceLastCompile))
|
||||
(sourceViewPanel.mHasChangedSinceLastCompile) && (mDebugger?.mIsComptimeDebug != true))
|
||||
{
|
||||
sourceViewPanel.ShowWrongHash();
|
||||
}
|
||||
|
@ -7695,6 +7718,11 @@ namespace IDE
|
|||
|
||||
void SysKeyDown(KeyDownEvent evt)
|
||||
{
|
||||
if (evt.mKeyCode != .Alt)
|
||||
{
|
||||
NOP!();
|
||||
}
|
||||
|
||||
if (evt.mHandled)
|
||||
return;
|
||||
|
||||
|
@ -8723,6 +8751,9 @@ namespace IDE
|
|||
if ((mVerbosity >= .Detailed) && (buildCompletedCmd.mStopwatch != null))
|
||||
OutputLine("Total build time: {0:0.00}s", buildCompletedCmd.mStopwatch.ElapsedMilliseconds / 1000.0f);
|
||||
|
||||
if (mDebugger?.mIsComptimeDebug == true)
|
||||
DebuggerComptimeStop();
|
||||
|
||||
CompileDone(!buildCompletedCmd.mFailed);
|
||||
|
||||
if (mTestManager != null)
|
||||
|
@ -9427,6 +9458,9 @@ namespace IDE
|
|||
|
||||
bool needsComptime = bfCompiler.GetLastHadComptimeRebuilds();
|
||||
|
||||
if (mDebugger?.mIsComptimeDebug == true)
|
||||
needsComptime = true;
|
||||
|
||||
if ((!workspaceOptions.mIncrementalBuild) && (!lastCompileHadMessages))
|
||||
{
|
||||
tryQueueFiles = false;
|
||||
|
@ -10376,6 +10410,9 @@ namespace IDE
|
|||
{
|
||||
Beep(MessageBeepType.Error);
|
||||
}
|
||||
|
||||
if (mDebugger?.mIsComptimeDebug == true)
|
||||
DebuggerComptimeStop();
|
||||
}
|
||||
|
||||
void DbgCopyChangedFiles(DateTime cmpTime, StringView srcDir, StringView destDir)
|
||||
|
@ -10767,6 +10804,9 @@ namespace IDE
|
|||
|
||||
if (mDebugger.mIsRunning)
|
||||
{
|
||||
if (mDebugger.mIsComptimeDebug)
|
||||
CancelBuild();
|
||||
|
||||
mDebugger.StopDebugging();
|
||||
}
|
||||
}
|
||||
|
@ -12104,6 +12144,12 @@ namespace IDE
|
|||
return .Normal;
|
||||
}
|
||||
|
||||
void DebuggerComptimeStop()
|
||||
{
|
||||
mDebugger.DisposeNativeBreakpoints();
|
||||
mDebugger.Detach();
|
||||
}
|
||||
|
||||
void DebuggerPaused()
|
||||
{
|
||||
mDebugger.mActiveCallStackIdx = 0;
|
||||
|
@ -14027,6 +14073,7 @@ namespace IDE
|
|||
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
|
||||
public static extern bool MessageBeep(MessageBeepType type);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static
|
||||
|
|
|
@ -787,6 +787,7 @@ namespace IDE
|
|||
Add("Comment Block", "Ctrl+K, Ctrl+C");
|
||||
Add("Comment Lines", "Ctrl+K, Ctrl+/");
|
||||
Add("Comment Toggle", "Ctrl+K, Ctrl+T");
|
||||
Add("Debug Comptime", "Alt+F7");
|
||||
Add("Duplicate Line", "Ctrl+D");
|
||||
Add("Find Class", "Alt+Shift+L");
|
||||
Add("Find in Document", "Ctrl+F");
|
||||
|
|
|
@ -539,6 +539,7 @@ namespace IDE.ui
|
|||
String sourceLineText = scope .(1024);
|
||||
|
||||
int32 maxLine = 0;
|
||||
int addrOffset = 0;
|
||||
|
||||
for (var lineStrView in codeData.Split('\n'))
|
||||
{
|
||||
|
@ -557,6 +558,9 @@ namespace IDE.ui
|
|||
|
||||
switch (line[0])
|
||||
{
|
||||
case 'A':
|
||||
addrOffset = (int)int64.Parse(StringView(line, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
continue;
|
||||
case 'O':
|
||||
isOptimized = true;
|
||||
addLineData = false;
|
||||
|
@ -612,7 +616,7 @@ namespace IDE.ui
|
|||
//int ptrSize = 8;
|
||||
var addrString = scope String(disasmLine, 0, parenPos);
|
||||
addrString.Replace("'", "");
|
||||
lineData.mAddr = (int)int64.Parse(addrString, System.Globalization.NumberStyles.HexNumber);
|
||||
lineData.mAddr = (int)int64.Parse(addrString, System.Globalization.NumberStyles.HexNumber) + addrOffset;
|
||||
lineData.mAddrEnd = lineData.mAddr + 1;
|
||||
|
||||
if (prevDisasmLineData != -1)
|
||||
|
@ -709,7 +713,7 @@ namespace IDE.ui
|
|||
addLineData = false;
|
||||
JumpEntry jumpEntry = new JumpEntry();
|
||||
int64 addrFrom = (int64)mLineDatas[mLineDatas.Count - 1].mAddr;
|
||||
int64 addrTo = int64.Parse(scope String(line, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
int64 addrTo = int64.Parse(scope String(line, 2), System.Globalization.NumberStyles.HexNumber) + addrOffset;
|
||||
jumpEntry.mAddrMin = (int)Math.Min(addrFrom, addrTo);
|
||||
jumpEntry.mAddrMax = (int)Math.Max(addrFrom, addrTo);
|
||||
jumpEntry.mIsReverse = jumpEntry.mAddrMin == (int)addrTo;
|
||||
|
@ -1193,6 +1197,7 @@ namespace IDE.ui
|
|||
|
||||
int leftIdx = -1;
|
||||
int rightIdx = -1;
|
||||
int commaIdx = -1;
|
||||
String debugExpr = null;
|
||||
|
||||
if ((cursorPos < content.mData.mTextLength) && (!((char8)content.mData.mText[cursorPos].mChar).IsWhiteSpace))
|
||||
|
@ -1208,59 +1213,94 @@ namespace IDE.ui
|
|||
content.ExtractString(lineStart, lineEnd - lineStart, lineStr);
|
||||
int strIdx = 0;
|
||||
|
||||
int colonPos = -1;
|
||||
int instrStartIdx = -1;
|
||||
int instrEndIdx = -1;
|
||||
int firstParamIdx = -1;
|
||||
int commaIdx = -1;
|
||||
bool isComptime = false;
|
||||
for (int i in 0..<lineStr.Length-1)
|
||||
{
|
||||
if ((lineStr[i] == '[') && (lineStr[i+1] == 'F'))
|
||||
isComptime = true;
|
||||
}
|
||||
|
||||
for (; strIdx < lineStr.Length; strIdx++)
|
||||
{
|
||||
char8 c = lineStr[strIdx];
|
||||
if (colonPos == -1)
|
||||
{
|
||||
if (c == ':')
|
||||
colonPos = strIdx;
|
||||
}
|
||||
else if (instrStartIdx == -1)
|
||||
{
|
||||
if (c.IsLower)
|
||||
instrStartIdx = strIdx;
|
||||
}
|
||||
else if (instrEndIdx == -1)
|
||||
{
|
||||
if (c.IsWhiteSpace)
|
||||
instrEndIdx = strIdx;
|
||||
}
|
||||
else if (firstParamIdx == -1)
|
||||
{
|
||||
if (!c.IsWhiteSpace)
|
||||
firstParamIdx = strIdx;
|
||||
}
|
||||
else if (commaIdx == -1)
|
||||
{
|
||||
if (c == ',')
|
||||
commaIdx = strIdx;
|
||||
}
|
||||
}
|
||||
if (isComptime)
|
||||
{
|
||||
int cursorStrIdx = cursorPos - lineStart;
|
||||
if ((cursorStrIdx >= 0) && (cursorStrIdx < lineStr.Length))
|
||||
{
|
||||
leftIdx = cursorStrIdx;
|
||||
rightIdx = cursorStrIdx;
|
||||
|
||||
int cursorStrIdx = cursorPos - lineStart;
|
||||
if (cursorStrIdx > commaIdx)
|
||||
{
|
||||
if (commaIdx != -1)
|
||||
leftIdx = lineStart + commaIdx + 1;
|
||||
else
|
||||
leftIdx = lineStart + firstParamIdx;
|
||||
rightIdx = lineEnd - 1;
|
||||
}
|
||||
else if (cursorStrIdx >= firstParamIdx)
|
||||
{
|
||||
leftIdx = lineStart + firstParamIdx;
|
||||
if (commaIdx != -1)
|
||||
rightIdx = lineStart + commaIdx - 1;
|
||||
else
|
||||
rightIdx = lineEnd - 1;
|
||||
}
|
||||
while (leftIdx > 0)
|
||||
{
|
||||
if (lineStr[leftIdx - 1].IsWhiteSpace)
|
||||
break;
|
||||
leftIdx--;
|
||||
}
|
||||
|
||||
while (rightIdx < lineStr.Length - 1)
|
||||
{
|
||||
if (lineStr[rightIdx + 1].IsWhiteSpace)
|
||||
break;
|
||||
rightIdx++;
|
||||
}
|
||||
|
||||
leftIdx += lineStart;
|
||||
rightIdx += lineStart;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int colonPos = -1;
|
||||
int instrStartIdx = -1;
|
||||
int instrEndIdx = -1;
|
||||
int firstParamIdx = -1;
|
||||
|
||||
for (; strIdx < lineStr.Length; strIdx++)
|
||||
{
|
||||
char8 c = lineStr[strIdx];
|
||||
if (colonPos == -1)
|
||||
{
|
||||
if (c == ':')
|
||||
colonPos = strIdx;
|
||||
}
|
||||
else if (instrStartIdx == -1)
|
||||
{
|
||||
if (c.IsLower)
|
||||
instrStartIdx = strIdx;
|
||||
}
|
||||
else if (instrEndIdx == -1)
|
||||
{
|
||||
if (c.IsWhiteSpace)
|
||||
instrEndIdx = strIdx;
|
||||
}
|
||||
else if (firstParamIdx == -1)
|
||||
{
|
||||
if (!c.IsWhiteSpace)
|
||||
firstParamIdx = strIdx;
|
||||
}
|
||||
else if (commaIdx == -1)
|
||||
{
|
||||
if (c == ',')
|
||||
commaIdx = strIdx;
|
||||
}
|
||||
}
|
||||
|
||||
int cursorStrIdx = cursorPos - lineStart;
|
||||
if (cursorStrIdx > commaIdx)
|
||||
{
|
||||
if (commaIdx != -1)
|
||||
leftIdx = lineStart + commaIdx + 1;
|
||||
else
|
||||
leftIdx = lineStart + firstParamIdx;
|
||||
rightIdx = lineEnd - 1;
|
||||
}
|
||||
else if (cursorStrIdx >= firstParamIdx)
|
||||
{
|
||||
leftIdx = lineStart + firstParamIdx;
|
||||
if (commaIdx != -1)
|
||||
rightIdx = lineStart + commaIdx - 1;
|
||||
else
|
||||
rightIdx = lineEnd - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (leftIdx != -1)
|
||||
{
|
||||
|
@ -1273,6 +1313,11 @@ namespace IDE.ui
|
|||
int32 semiPos = (int32)debugExpr.IndexOf(';');
|
||||
if (semiPos != -1)
|
||||
debugExpr.RemoveToEnd(semiPos);
|
||||
debugExpr.Trim();
|
||||
|
||||
int atPos = debugExpr.IndexOf('@');
|
||||
if (atPos != -1)
|
||||
debugExpr.RemoveToEnd(atPos);
|
||||
|
||||
debugExpr.Replace('[', '(');
|
||||
debugExpr.Replace(']', ')');
|
||||
|
@ -1282,6 +1327,13 @@ namespace IDE.ui
|
|||
debugExpr.Replace("word ptr", "(int16*)");
|
||||
debugExpr.Replace("byte ptr", "(int8*)");
|
||||
|
||||
if ((debugExpr.Contains('(')) && (debugExpr[0].IsLetter))
|
||||
{
|
||||
int parenPos = debugExpr.IndexOf('(');
|
||||
debugExpr.Insert(parenPos, "*)");
|
||||
debugExpr.Insert(0, "*(");
|
||||
}
|
||||
|
||||
if (line < mLineDatas.Count - 1)
|
||||
{
|
||||
if (mLineDatas[line].mAddrEnd != (int)0)
|
||||
|
|
|
@ -321,6 +321,11 @@ namespace IDE.ui
|
|||
|
||||
float statusLabelPos = (int)GS!(-1.3f);
|
||||
|
||||
if ((gApp.mDebugger?.mIsComptimeDebug == true) && (gApp.mDebugger.IsPaused()))
|
||||
{
|
||||
completionPct = null;
|
||||
}
|
||||
|
||||
//completionPct = 0.4f;
|
||||
if (completionPct.HasValue)
|
||||
{
|
||||
|
@ -331,6 +336,10 @@ namespace IDE.ui
|
|||
using (g.PushColor(0xFF00FF00))
|
||||
g.FillRect(completionRect.mX, completionRect.mY, completionRect.mWidth * completionPct.Value, completionRect.mHeight);
|
||||
}
|
||||
else if ((gApp.mDebugger?.mIsComptimeDebug == true) && (gApp.mDebugger.IsPaused()))
|
||||
{
|
||||
g.DrawString("Debugging Comptime", GS!(200), statusLabelPos, FontAlign.Centered, GS!(120));
|
||||
}
|
||||
else if ((gApp.mDebugger.mIsRunning) && (gApp.HaveSourcesChanged()))
|
||||
{
|
||||
Rect completionRect = Rect(GS!(200), GS!(1), GS!(120), GS!(17));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue