extern char * strrchr(const char * s, int c);
#define uint _uint
+#define strlen _strlen
#include <stdarg.h>
#include <unistd.h>
#include <sys/time.h> // Required on Apple...
#endif
#undef uint
-
+#undef strlen
public char * StripQuotes2(char * string, char * output)
{
enum DebuggerState { none, prompt, loaded, running, stopped, terminated };
enum DebuggerEvent { none, hit, breakEvent, signal, stepEnd, functionEnd, exit };
enum DebuggerAction { none, internal, restart, stop, selectFrame }; //, bpValidation
-enum BreakpointType { none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor };
+enum BreakpointType { none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor, internalModuleLoad };
enum DebuggerEvaluationError { none, symbolNotFound, memoryCantBeRead, unknown };
FileDialog debuggerFileDialog { type = selectDir };
CompilerConfig currentCompiler;
ProjectConfig prjConfig;
+ int bitDepth;
CodeEditor codeEditor;
{
case restart:
breakType = none;
- Restart(currentCompiler, prjConfig);
+ Restart(currentCompiler, prjConfig, bitDepth);
break;
case stop:
breakType = none;
bpHit = bp;
if(!(!userBreakOnInternBreak &&
- bp && (bp.type == internalMain || bp.type == internalWinMain || bp.type == internalModulesLoaded)))
+ bp && (bp.type == internalMain || bp.type == internalWinMain ||
+ bp.type == internalModulesLoaded || bp.type == internalModuleLoad)))
monitor = true;
hitThread = stopItem.threadid;
}
sysBPs.Add(Breakpoint { type = internalWinMain, enabled = true, level = -1 });
#endif
sysBPs.Add(Breakpoint { type = internalModulesLoaded, enabled = true, level = -1 });
-
+ sysBPs.Add(Breakpoint { type = internalModuleLoad, enabled = true, level = -1 });
}
~Debugger()
}
}
- void Restart(CompilerConfig compiler, ProjectConfig config)
+ void Restart(CompilerConfig compiler, ProjectConfig config, int bitDepth)
{
switch(state)
{
GdbAbortExec();
case none:
case terminated:
- if(!GdbInit(compiler, config))
+ if(!GdbInit(compiler, config, bitDepth))
break;
case loaded:
GdbExecRun();
codloc = CodeLocation::ParseCodeLocation(location);
if(codloc)
{
- CodeEditor editor = (CodeEditor)ide.OpenFile(codloc.absoluteFile, normal, true, null, no, normal);
+ CodeEditor editor = (CodeEditor)ide.OpenFile(codloc.absoluteFile, normal, true, null, no, normal, false);
if(editor)
{
EditBox editBox = editor.editBox;
}
}
if(frame.absoluteFile)
- editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal);
+ editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
ide.Update(null);
if(editor && frame.line)
{
ide.Update(null);
}
- void Start(CompilerConfig compiler, ProjectConfig config)
+ void Start(CompilerConfig compiler, ProjectConfig config, int bitDepth)
{
ide.outputView.debugBox.Clear();
switch(state)
{
case none:
case terminated:
- if(!GdbInit(compiler, config))
+ if(!GdbInit(compiler, config, bitDepth))
break;
case loaded:
GdbExecRun();
}
}
- void StepInto(CompilerConfig compiler, ProjectConfig config)
+ void StepInto(CompilerConfig compiler, ProjectConfig config, int bitDepth)
{
switch(state)
{
case none:
case terminated:
- if(!GdbInit(compiler, config))
+ if(!GdbInit(compiler, config, bitDepth))
break;
case loaded:
ide.outputView.ShowClearSelectTab(debug);
}
}
- void StepOver(CompilerConfig compiler, ProjectConfig config, bool ignoreBkpts)
+ void StepOver(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool ignoreBkpts)
{
switch(state)
{
case none:
case terminated:
- if(!GdbInit(compiler, config))
+ if(!GdbInit(compiler, config, bitDepth))
break;
case loaded:
ide.outputView.ShowClearSelectTab(debug);
}
}
- void RunToCursor(CompilerConfig compiler, ProjectConfig config, char * absoluteFilePath, int lineNumber, bool ignoreBkpts)
+ void RunToCursor(CompilerConfig compiler, ProjectConfig config, int bitDepth, char * absoluteFilePath, int lineNumber, bool ignoreBkpts, bool atSameLevel)
{
char relativeFilePath[MAX_LOCATION];
DebuggerState oldState = state;
{
case none:
case terminated:
- Start(compiler, config);
+ Start(compiler, config, bitDepth);
case stopped:
case loaded:
if(symbols)
ide.outputView.ShowClearSelectTab(debug);
ide.outputView.debugBox.Logf($"Starting debug mode\n");
}
- RunToCursorPrepare(absoluteFilePath, relativeFilePath, lineNumber);
+ RunToCursorPrepare(absoluteFilePath, relativeFilePath, lineNumber, atSameLevel);
sentBreakInsert = true;
GdbCommand(false, "-break-insert %s:%d", relativeFilePath, lineNumber);
bpRunToCursor.bp = bpItem;
else
{
*error = signalOn && activeThread == signalThread;
- *lineCursor = activeFrameLevel + 1;
+ *lineCursor = activeFrameLevel - ((frameCount > 192 && activeFrameLevel > 191) ? frameCount - 192 - 1 : 0) + 1;
*lineTopFrame = activeFrameLevel ? 1 : 0;
}
}
else if(expression)
{
wh = Watch { };
- row.tag = (int)wh;
+ row.tag = (int64)wh;
ide.workspace.watches.Add(wh);
wh.row = row;
wh.expression = CopyString(expression);
if(gdbHandle)
{
// TODO: Improve this limit
- static char string[MAX_F_STRING*3];
+ static char string[MAX_F_STRING*4];
va_list args;
va_start(args, format);
vsnprintf(string, sizeof(string), format, args);
return true;
}
- static void GdbInsertInternalBreakpoint()
+ static void GdbInsertInternalBreakpoints()
{
if(symbols)
{
//if(!breakpointsInserted)
{
- DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig);
+ DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig, bitDepth);
for(bp : sysBPs)
{
if(!bp.inserted)
bp.bp = bpItem;
bpItem = null;
bp.inserted = (bp.bp && bp.bp.number != 0);
- ValidateBreakpoint(bp);
}
delete f;
}
- break;
+ }
+ else if(bp.type == internalModuleLoad && modules)
+ {
+ Project ecerePrj = null;
+ for(p : ide.workspace.projects)
+ {
+ if(!strcmp(p.topNode.name, "ecere.epj"))
+ {
+ ecerePrj = p;
+ break;
+ }
+ }
+ if(ecerePrj)
+ {
+ ProjectNode node = ecerePrj.topNode.Find("instance.c", false);
+ if(node)
+ {
+ char path[MAX_LOCATION];
+ char relative[MAX_LOCATION];
+ node.GetFullFilePath(path);
+ bp.absoluteFilePath = CopyString(path);
+ MakePathRelative(path, ecerePrj.topNode.path, relative);
+ delete bp.relativeFilePath;
+ bp.relativeFilePath = CopyString(relative);
+ sentBreakInsert = true;
+ GdbCommand(false, "-break-insert %s:InternalModuleLoadBreakpoint", bp.relativeFilePath);
+ bp.bp = bpItem;
+ bpItem = null;
+ bp.inserted = (bp.bp && bp.bp.number != 0);
+ }
+ }
}
}
}
//breakpointsInserted = false;
if(symbols)
{
+ for(bp : sysBPs)
+ {
+ if(bp.bp)
+ GdbCommand(false, "-break-delete %d", bp.bp.number);
+ bp.inserted = false;
+ bp.bp = bpItem;
+ //check here (reply form -break-delete, returns bpitem?)
+ bpItem = null;
+ }
for(bp : ide.workspace.breakpoints)
{
if(bp.bp)
GdbCommand(false, "-environment-directory \"%s\"", dir);
//GdbCommand(false, ""); // why this empty GDB command
}
- GdbInsertInternalBreakpoint();
+ GdbInsertInternalBreakpoints();
targeted = true;
}
return true;
void GdbExecCommon()
{
ClearBreakDisplay();
+ GdbInsertInternalBreakpoints();
GdbBreakpointsInsert();
}
return true;
}
- bool GdbInit(CompilerConfig compiler, ProjectConfig config)
+ bool GdbInit(CompilerConfig compiler, ProjectConfig config, int bitDepth)
{
bool result = true;
char oldDirectory[MAX_LOCATION];
char tempPath[MAX_LOCATION];
char command[MAX_LOCATION];
Project project = ide.project;
- DirExpression targetDirExp = project.GetTargetDir(compiler, config);
+ DirExpression targetDirExp = project.GetTargetDir(compiler, config, bitDepth);
PathBackup pathBackup { };
if(currentCompiler != compiler)
incref currentCompiler;
}
prjConfig = config;
+ this.bitDepth = bitDepth;
ChangeState(loaded);
sentKill = false;
else
ChangeWorkingDir(ide.workspace.projectDir);
- ide.SetPath(true, compiler, config);
+ ide.SetPath(true, compiler, config, bitDepth);
// TODO: This pollutes the environment, but at least it works
// It shouldn't really affect the IDE as the PATH gets restored and other variables set for testing will unlikely cause problems
SetEnvironment(e.name, e.string);
}
- strcpy(command, "gdb -n -silent --interpreter=mi2"); //-async //\"%s\"
+ strcpy(command,
+ (compiler.targetPlatform == win32 && bitDepth == 64) ? "x86_64-w64-mingw32-gdb" :
+ (compiler.targetPlatform == win32 && bitDepth == 32) ? "i686-w64-mingw32-gdb" :
+ "gdb");
+ strcat(command, " -n -silent --interpreter=mi2"); //-async //\"%s\"
gdbTimer.Start();
gdbHandle = DualPipeOpen(PipeOpenMode { output = 1, error = 2, input = 1 }, command);
if(!gdbHandle)
strcpy(path, ide.workspace.projectDir);
PathCat(path, tempPath);
- codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no);
+ codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no, normal, false);
if(!codeEditor)
{
for(srcDir : ide.workspace.sourceDirs)
{
strcpy(path, srcDir);
PathCat(path, tempPath);
- codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no);
+ codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no, normal, false);
if(codeEditor) break;
}
}
if(!activeFrame || !activeFrame.absoluteFile)
codeEditor = null;
else
- codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, normal, false, null, no, normal);
+ codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, normal, false, null, no, normal, false);
if(codeEditor)
{
codeEditor.inUseDebug = true;
{
char string[256] = "";
Symbol classSym;
- PrintType(type, string, false, true);
+ PrintTypeNoConst(type, string, false, true);
classSym = FindClass(string);
_class = classSym ? classSym.registered : null;
}
if(exp.expType.kind != arrayType || exp.hasAddress)
{
- uint address;
+ uint64 address;
char * string;
char value[4196];
int len;
sprintf(temp, "(char*)%s", exp.constant);*/
//evaluation = Debugger::EvaluateExpression(temp, &evalError);
- address = strtoul(exp.constant, null, 0);
+ // address = strtoul(exp.constant, null, 0);
+ address = _strtoui64(exp.constant, null, 0);
//printf("%x\n", address);
- snprintf(value, sizeof(value), "0x%08x ", address);
+ // snprintf(value, sizeof(value), "0x%08x ", address);
+
+ if(address > 0xFFFFFFFFLL)
+ snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%016I64x " : "0x%016llx ", address);
+ else
+ snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%08I64x " : "0x%08llx ", address);
value[sizeof(value)-1] = 0;
if(!address)
}
else
{
- value = strtoul(exp.constant, null, 0);
+ value = (uint)strtoul(exp.constant, null, 0);
signedValue = (int)value;
}
}
default:
if(exp.hasAddress)
{
- wh.value = PrintHexUInt(exp.address);
+ wh.value = PrintHexUInt64(exp.address);
result = (bool)exp.address;
}
else
}
// to be removed... use GdbReadMemory that returns a byte array instead
- char * ::GdbReadMemoryString(uint address, int size, char format, int rows, int cols)
+ char * ::GdbReadMemoryString(uint64 address, int size, char format, int rows, int cols)
{
eval.active = true;
eval.error = none;
if(!size)
printf("GdbReadMemoryString called with size = 0!\n");
#endif
- GdbCommand(false, "-data-read-memory 0x%08x %c, %d, %d, %d", address, format, size, rows, cols);
+ // GdbCommand(false, "-data-read-memory 0x%08x %c, %d, %d, %d", address, format, size, rows, cols);
+ if(GetRuntimePlatform() == win32)
+ GdbCommand(false, "-data-read-memory 0x%016I64x %c, %d, %d, %d", address, format, size, rows, cols);
+ else
+ GdbCommand(false, "-data-read-memory 0x%016llx %c, %d, %d, %d", address, format, size, rows, cols);
if(eval.active)
ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemoryString\n");
return eval.result;
}
- byte * ::GdbReadMemory(uint address, int bytes)
+ byte * ::GdbReadMemory(uint64 address, int bytes)
{
eval.active = true;
eval.error = none;
- GdbCommand(false, "-data-read-memory 0x%08x %c, 1, 1, %d", address, 'u', bytes);
+ //GdbCommand(false, "-data-read-memory 0x%08x %c, 1, 1, %d", address, 'u', bytes);
+ if(GetRuntimePlatform() == win32)
+ GdbCommand(false, "-data-read-memory 0x%016I64x %c, 1, 1, %d", address, 'u', bytes);
+ else
+ GdbCommand(false, "-data-read-memory 0x%016llx %c, 1, 1, %d", address, 'u', bytes);
#ifdef _DEBUG
if(!bytes)
printf("GdbReadMemory called with bytes = 0!\n");
Breakpoint bp = bpHit;
if(!bp && bpRunToCursor)
- {
bp = bpRunToCursor;
- if(symbols)
- GdbCommand(false, "-break-delete %d", bp.bp.number);
- }
if(bp)
{
break;
case internalModulesLoaded:
modules = true;
+ GdbInsertInternalBreakpoints();
+ GdbBreakpointsInsert();
+ GdbExecContinue(false);
+ break;
+ case internalModuleLoad:
GdbBreakpointsInsert();
GdbExecContinue(false);
break;
GoToStackFrameLine(activeFrameLevel, true);
ideMainFrame.Activate(); // TOFIX: ide.Activate() is not reliable (app inactive)
ide.Update(null);
- if(bp.type == BreakpointType::runToCursor)
- {
- delete bpRunToCursor;
- bpRunToCursor = null;
- }
}
else
{
}
else
ide.outputView.debugBox.Logf("Debugger Error: Breakpoint hit could not match breakpoint instance\n");
+
+ if(bpRunToCursor)
+ {
+ if(symbols && bpRunToCursor.inserted)
+ GdbCommand(false, "-break-delete %d", bpRunToCursor.bp.number);
+ delete bpRunToCursor;
+ }
}
void GdbThreadExit()
else if(!strcmp(item.name, "next-row"))
{
StripQuotes(item.value, item.value);
- eval.nextBlockAddress = strtoul(item.value, null, 0);
+ eval.nextBlockAddress = _strtoui64(item.value, null, 0);
}
else if(!strcmp(item.name, "memory"))
{
delete item2;
}
- void RunToCursorPrepare(char * absoluteFilePath, char * relativeFilePath, int lineNumber)
+ void RunToCursorPrepare(char * absoluteFilePath, char * relativeFilePath, int lineNumber, bool atSameLevel)
{
if(bpRunToCursor)
{
bpRunToCursor.enabled = true;
bpRunToCursor.condition = null;
bpRunToCursor.ignore = 0;
- bpRunToCursor.level = -1;
+ bpRunToCursor.level = atSameLevel ? frameCount - activeFrameLevel -1 : -1;
}
ExpressionType ::DebugEvalExpTypeError(char * result)
return result;
}
- char * ::ReadMemory(uint address, int size, char format, ExpressionType * error)
+ char * ::ReadMemory(uint64 address, int size, char format, ExpressionType * error)
{
// check for state
char * result = GdbReadMemoryString(address, size, format, 1, 1);
selectResult = select(fd + 1, &rs, null, null, &time);
if(FD_ISSET(fd, &rs))
{
- int result = read(fd, output, sizeof(output)-1);
+ int result = (int)read(fd, output, sizeof(output)-1);
if(!result || (result < 0 && errno != EAGAIN))
break;
if(result > 0)
bool active;
char * result;
int bytes;
- uint nextBlockAddress;
+ uint64 nextBlockAddress;
DebuggerEvaluationError error;
};