+#ifdef ECERE_STATIC
+public import static "ecere"
+public import static "ec"
+#else
+public import "ecere"
+public import "ec"
+#endif
+
import "ide"
import "process"
import "debugFindCtx"
import "debugTools"
-//#define GDB_DEBUG_CONSOLE
+#ifdef _DEBUG
+#define GDB_DEBUG_CONSOLE
+#define _DEBUG_INST
+#endif
-extern char * strrchr(char * s, char c);
+extern char * strrchr(const char * s, int c);
#define uint _uint
+#define strlen _strlen
#include <stdarg.h>
#include <unistd.h>
+#include <ctype.h>
#ifdef __APPLE__
#define __unix__
#include <sys/time.h> // Required on Apple...
#endif
#undef uint
+#undef strlen
-//bool eString_PathInsidePath(char * to, char * path)
-bool eString_PathInsideOf(char * path, char * of)
+char * PrintNow()
{
- if(!path[0] || !of[0])
- return false; // What to do here? Ever used?
- else
+ int c;
+ char * s[6];
+ char * time;
+ DateTime now;
+ now.GetLocalTime();
+ for(c=0; c<6; c++)
+ s[c] = new char[8];
+ sprintf(s[0], "%04d", now.year);
+ sprintf(s[1], "%02d", now.month+1);
+ sprintf(s[2], "%02d", now.day);
+ sprintf(s[3], "%02d", now.hour);
+ sprintf(s[4], "%02d", now.minute);
+ sprintf(s[5], "%02d", now.second);
+ time = PrintString("*", s[0], s[1], s[2], "-", s[3], s[4], s[5], "*");
+ for(c=0; c<6; c++)
+ delete s[c];
+ return time;
+}
+
+// use =0 to disable printing of specific channels
+#ifdef _DEBUG_INST
+static enum dplchan { none, gdbProtoIgnored=0/*1*/, gdbProtoUnknown=2, gdbOutput=3/*3*/, gdbCommand=4/*4*/, debuggerCall=0/*5*/, debuggerProblem=6,
+ debuggerUserAction=7,debuggerState=8, debuggerBreakpoints=9, debuggerWatches=0/*10*/, debuggerTemp=0 };
+#else
+static enum dplchan { none, gdbProtoIgnored=0, gdbProtoUnknown=0, gdbOutput=0, gdbCommand=0, debuggerCall=0, debuggerProblem=0,
+ debuggerUserAction=0,debuggerState=0, debuggerBreakpoints=0, debuggerWatches=0, debuggerTemp=0 };
+#endif
+static char * _dpct[] = {
+ null,
+ "GDB Protocol Ignored",
+ "GDB Protocol ***Unknown***",
+ "GDB Output",
+ "GDB Command",
+ ""/*Debugger Call*/,
+ "Debugger ***Problem***",
+ "Debugger::ChangeUserAction",
+ "Debugger::ChangeState",
+ "Breakpoints",
+ "Watches",
+ "-----> Temporary Message",
+ null
+};
+
+// TODO if(strlen(item.value) < MAX_F_STRING)
+
+// Debug Print Line
+#ifdef _DEBUG_INST
+#define _dpl2(...) __dpl2(__FILE__, __LINE__, ##__VA_ARGS__)
+#else
+#define _dpl2(...)
+#endif
+static void __dpl2(char * file, int line, char ** channels, int channel, int indent, typed_object object, ...)
+{
+ bool chan = channel && channels && channels[channel];
+ if(chan || !channels)
{
- char ofPart[MAX_FILENAME], ofRest[MAX_LOCATION];
- char pathPart[MAX_FILENAME], pathRest[MAX_LOCATION];
- strcpy(ofRest, of);
- strcpy(pathRest, path);
- for(; ofRest[0] && pathRest[0];)
- {
- SplitDirectory(ofRest, ofPart, ofRest);
- SplitDirectory(pathRest, pathPart, pathRest);
- if(fstrcmp(pathPart, ofPart))
- return false;
- }
- if(!ofRest[0] && !pathRest[0]) // paths are identical - should return false or true? (changed to false)
- return false;
- else if(!pathRest[0]) // not inside of, it's the other way around
- return false;
- return true;
+ char string[MAX_F_STRING];
+ int len;
+ char * time = PrintNow();
+ va_list args;
+ //ide.outputView.debugBox.Logf();
+ Logf("%s %s:% 5d: %s%s", time, file, line, chan ? channels[channel] : "", chan && channels[channel][0] ? ": " : "");
+ va_start(args, object);
+ len = PrintStdArgsToBuffer(string, sizeof(string), object, args);
+ Log(string);
+ va_end(args);
+ Log("\n");
+ delete time;
}
}
+#define _dpl(...) __dpl(__FILE__, __LINE__, ##__VA_ARGS__)
+static void __dpl(char * file, int line, int indent, char * format, ...)
+{
+ va_list args;
+ char string[MAX_F_STRING];
+ int c;
+ char * time = PrintNow();
+ //static File f = null;
+ va_start(args, format);
+ vsnprintf(string, sizeof(string), format, args);
+ string[sizeof(string)-1] = 0;
+ /*if(!f)
+ {
+ char * time = PrintNow();
+ char * logName;
+ logName = PrintString(time, ".log");
+ delete time;
+ f = FileOpen(logName, write);
+ delete logName;
+ }*/
+ /*f.Printf("%s %s:% 5d: ", time, file, line);
+ for(c = 0; c<indent; c++)
+ f.Putc(' ');
+ f.Printf("%s\n", string);*/
+ Logf("%s %s:% 5d: ", time, file, line);
+ for(c = 0; c<indent; c++)
+ Log(" ");
+ Logf("%s\n", string);
+ va_end(args);
+ delete time;
+}
+
public char * StripQuotes2(char * string, char * output)
{
int c;
if(escaped || ch != '\"')
{
output[d++] = ch;
- if(ch == '\\')
- escaped ^= true;
+ escaped = !escaped && ch == '\\';
}
else
quoted = false;
// String Escape Copy
static void strescpy(char * d, char * s)
{
- int j, k;
- j = k = 0;
- while(s[j])
+ int j = 0, k = 0;
+ char ch;
+ while((ch = s[j]))
{
- switch(s[j])
+ switch(ch)
{
- case '\n':
- d[k] = '\\';
- d[++k] = 'n';
- break;
- case '\t':
- d[k] = '\\';
- d[++k] = 't';
- break;
- case '\a':
- d[k] = '\\';
- d[++k] = 'a';
- break;
- case '\b':
- d[k] = '\\';
- d[++k] = 'b';
- break;
- case '\f':
- d[k] = '\\';
- d[++k] = 'f';
- break;
- case '\r':
- d[k] = '\\';
- d[++k] = 'r';
- break;
- case '\v':
- d[k] = '\\';
- d[++k] = 'v';
- break;
- case '\\':
- d[k] = '\\';
- d[++k] = '\\';
- break;
- case '\"':
- d[k] = '\\';
- d[++k] = '\"';
- break;
- default:
- d[k] = s[j];
+ case '\n': d[k] = '\\'; d[++k] = 'n'; break;
+ case '\t': d[k] = '\\'; d[++k] = 't'; break;
+ case '\a': d[k] = '\\'; d[++k] = 'a'; break;
+ case '\b': d[k] = '\\'; d[++k] = 'b'; break;
+ case '\f': d[k] = '\\'; d[++k] = 'f'; break;
+ case '\r': d[k] = '\\'; d[++k] = 'r'; break;
+ case '\v': d[k] = '\\'; d[++k] = 'v'; break;
+ case '\\': d[k] = '\\'; d[++k] = '\\'; break;
+ case '\"': d[k] = '\\'; d[++k] = '\"'; break;
+ default: d[k] = s[j];
}
- ++j;
- ++k;
+ j++, k++;
}
- d[k] = s[j];
+ d[k] = '\0';
}
static char * CopyUnescapedSystemPath(char * p)
static void struscpy(char * d, char * s)
{
- int j, k;
- j = k = 0;
- while(s[j])
+ int j = 0, k = 0;
+ char ch;
+ while((ch = s[j]))
{
- switch(s[j])
+ switch(ch)
{
case '\\':
switch(s[++j])
{
- case 'n':
- d[k] = '\n';
- break;
- case 't':
- d[k] = '\t';
- break;
- case 'a':
- d[k] = '\a';
- break;
- case 'b':
- d[k] = '\b';
- break;
- case 'f':
- d[k] = '\f';
- break;
- case 'r':
- d[k] = '\r';
- break;
- case 'v':
- d[k] = '\v';
- break;
- case '\\':
- d[k] = '\\';
- break;
- case '\"':
- d[k] = '\"';
- break;
- default:
- d[k] = '\\';
- d[++k] = s[j];
+ case 'n': d[k] = '\n'; break;
+ case 't': d[k] = '\t'; break;
+ case 'a': d[k] = '\a'; break;
+ case 'b': d[k] = '\b'; break;
+ case 'f': d[k] = '\f'; break;
+ case 'r': d[k] = '\r'; break;
+ case 'v': d[k] = '\v'; break;
+ case '\\': d[k] = '\\'; break;
+ case '\"': d[k] = '\"'; break;
+ default: d[k] = '\\'; d[++k] = s[j];
}
break;
default:
d[k] = s[j];
}
- ++j;
- ++k;
+ j++, k++;
}
- d[k] = s[j];
+ d[k] = '\0';
}
static char * StripBrackets(char * string)
static int TokenizeList(char * string, const char seperator, Array<char *> tokens)
{
uint level = 0;
-
- bool quoted = false; //bool escaped = false;
- char * start = string;
-
- for(; *string; string++)
+
+ bool quoted = false, escaped = false;
+ char * start = string, ch;
+
+ for(; (ch = *string); string++)
{
if(!start)
start = string;
+
if(quoted)
{
- if(*string == '\"')
+ if(escaped || ch != '\"')
+ escaped = !escaped && ch == '\\';
+ else
quoted = false;
}
- else if(*string == '\"')
+ else if(ch == '\"')
quoted = true;
- else if(*string == '{' || *string == '[' || *string == '(' || *string == '<')
+ else if(ch == '{' || ch == '[' || ch == '(' || ch == '<')
level++;
- else if(*string == '}' || *string == ']' || *string == ')' || *string == '>')
+ else if(ch == '}' || ch == ']' || ch == ')' || ch == '>')
level--;
- else if(*string == seperator && !level)
+ else if(ch == seperator && !level)
{
tokens.Add(start);
*string = '\0';
*equal = '\0';
equal++;
item.value = equal;
- equal = null;
return true;
}
- else
- return false;
+ return false;
}
-static void DebuggerProtocolUnknown(char * message, char * gdbOutput)
+static bool CheckCommandAvailable(const char * command)
{
-#ifdef _DEBUG_GDB_PROTOCOL
- ide.outputView.debugBox.Logf("Debugger Protocol Error: %s (%s)\n", message, gdbOutput);
+ bool available = false;
+ int c, count;
+ char * name = new char[MAX_FILENAME];
+ char * pathVar = new char[maxPathLen];
+ char * paths[128];
+ GetEnvironment("PATH", pathVar, maxPathLen);
+ count = TokenizeWith(pathVar, sizeof(paths) / sizeof(char *), paths, pathListSep, false);
+ strcpy(name, command);
+#ifdef __WIN32__
+ {
+ int e;
+ const char * extensions[] = { "exe", "com", "bat", null };
+ for(e=0; extensions[e]; e++)
+ {
+ ChangeExtension(name, extensions[e], name);
+#endif
+ for(c=0; c<count; c++)
+ {
+ FileListing fl { paths[c] };
+ while(fl.Find())
+ {
+ if(fl.stats.attribs.isFile && !fstrcmp(fl.name, name))
+ {
+ available = true;
+ fl.Stop();
+ break;
+ }
+ }
+ if(available) break;
+ }
+#ifdef __WIN32__
+ if(available) break;
+ }
+ }
#endif
+ delete name;
+ delete pathVar;
+ return available;
}
// define GdbGetLineSize = 1638400;
char progFifoDir[MAX_LOCATION];
#endif
-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 DebuggerState { none, prompt, loaded, running, stopped, terminated, error };
+enum DebuggerEvent
+{
+ none, hit, breakEvent, signal, stepEnd, functionEnd, exit, valgrindStartPause, locationReached;
+
+ property bool canBeMonitored { get { return (this == hit || this == breakEvent || this == signal || this == stepEnd || this == functionEnd || this == locationReached); } };
+};
+enum DebuggerAction { none, internal, restart, stop, selectFrame, advance }; //, bpValidation
+enum DebuggerReason
+{
+ unknown, endSteppingRange, functionFinished, signalReceived, breakpointHit, locationReached
+ //watchpointTrigger, readWatchpointTrigger, accessWatchpointTrigger, watchpointScope,
+ //exited, exitedNormally, exitedSignalled;
+};
+enum BreakpointType
+{
+ none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor, internalModuleLoad, internalEntry;
+
+ property bool isInternal { get { return (this == internalMain || this == internalWinMain || this == internalModulesLoaded || this == internalModuleLoad || this == internalEntry); } };
+ property bool isUser { get { return (this == user || this == runToCursor); } };
+};
enum DebuggerEvaluationError { none, symbolNotFound, memoryCantBeRead, unknown };
+enum DebuggerUserAction
+{
+ none, start, resume, _break, stop, restart, selectThread, selectFrame, stepInto, stepOver, stepUntil, stepOut, runToCursor;
+ property bool breaksOnInternalBreakpoint { get { return (this == stepInto || this == stepOver || this == stepUntil); } };
+};
+enum GdbExecution
+{
+ none, run, _continue, next, until, advance, step, finish;
+ property bool suspendInternalBreakpoints { get { return (this == until || this == advance || this == step || this == finish); } };
+};
FileDialog debuggerFileDialog { type = selectDir };
+static DualPipe vgTargetHandle;
+static File vgLogFile;
+static char vgLogPath[MAX_LOCATION];
static DualPipe gdbHandle;
static DebugEvaluationData eval { };
static int targetProcessId;
static bool gdbReady;
+static bool breakpointError;
class Debugger
{
bool targeted;
bool symbols;
bool modules;
- //bool breakpointsInserted;
bool sentKill;
bool sentBreakInsert;
bool ignoreBreakpoints;
- bool userBreakOnInternBreak;
bool signalOn;
- //bool watchesInit;
+ bool needReset;
+ bool usingValgrind;
int ideProcessId;
int gdbProcessId;
char * targetDir;
char * targetFile;
-
+
+ GdbExecution gdbExecution;
+ DebuggerUserAction userAction;
DebuggerState state;
DebuggerEvent event;
DebuggerAction breakType;
+ char * breakString;
//DebuggerCommand lastCommand; // THE COMPILER COMPILES STUFF THAT DOES NOT EXIST???
GdbDataStop stopItem;
GdbDataBreakpoint bpItem;
Frame activeFrame;
-
+
List<Breakpoint> sysBPs { };
Breakpoint bpRunToCursor;
- //Breakpoint bpStep;
- Breakpoint bpHit;
+ Breakpoint intBpEntry;
+ Breakpoint intBpMain;
+ Breakpoint intBpWinMain;
OldList stackFrames;
CompilerConfig currentCompiler;
ProjectConfig prjConfig;
+ int bitDepth;
CodeEditor codeEditor;
+ ValgrindLogThread vgLogThread { debugger = this };
+ ValgrindTargetThread vgTargetThread { debugger = this };
GdbThread gdbThread { debugger = this };
+
+ bool entryPoint;
+ Map<String, bool> projectsLibraryLoaded { };
+
Timer gdbTimer
{
delay = 0.0, userData = this;
bool monitor = false;
DebuggerEvent curEvent = event;
GdbDataStop stopItem = this.stopItem;
+ Breakpoint bpUser = null;
+ Breakpoint bpInternal = null;
+
if(!gdbReady)
return false;
-
+
event = none;
if(this.stopItem)
+ {
this.stopItem = null;
+#ifdef _DEBUG_INST
+ {
+ char * s;
+ DynamicString bpReport { };
+
+ for(bp : sysBPs; bp.inserted)
+ {
+ bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
+ delete s;
+ }
+ if(bpRunToCursor && bpRunToCursor.inserted)
+ {
+ Breakpoint bp = bpRunToCursor;
+ bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
+ delete s;
+ }
+ for(bp : ide.workspace.breakpoints; bp.inserted)
+ {
+ bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
+ delete s;
+ }
+ s = bpReport;
+ _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "gdbTimer::DelayExpired: ", s+1);
+
+ if(stopItem.bkptno)
+ {
+ bool isInternal;
+ Breakpoint bp = GetBreakpointById(stopItem.bkptno, &isInternal);
+ if(bp)
+ _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "gdb stopped by a breakpoint: ", bp.type, "(", s=bp.CopyLocationString(false), ")"); delete s;
+ }
+ delete bpReport;
+ }
+#endif
+ }
+#ifdef _DEBUG_INST
else
{
if(curEvent && curEvent != exit)
{
-#ifdef _DEBUG
- printf("No stop item\n");
-#endif
+ _dpl(0, "No stop item");
}
}
-
+#endif
switch(breakType)
{
case restart:
breakType = none;
- Restart(currentCompiler, prjConfig);
+ Restart(currentCompiler, prjConfig, bitDepth, usingValgrind);
break;
case stop:
breakType = none;
}
//case bpValidation:
// breakType = none;
- // GdbCommand(false, "-break-info %d", bpItem.number);
+ // GdbCommand(false, "-break-info %s", bpItem.number);
// break;
}
-
+
if(curEvent == none)
return false;
-
- switch (curEvent)
+
+ switch(curEvent)
{
- case breakEvent:
- activeThread = stopItem.threadid;
- GdbCommand(false, "-thread-list-ids");
- GdbGetStack();
- break;
case hit:
{
- Breakpoint bp = null;
-
- for(i : ide.workspace.breakpoints; i.bp && i.bp.number == stopItem.bkptno)
- {
- bp = i;
- break;
- }
- if(!bp)
- {
- for(i : sysBPs; i.bp && i.bp.number == stopItem.bkptno)
- {
- bp = i;
- break;
- }
- }
- if(bp && bp.type != user && stopItem && stopItem.frame)
+ bool isInternal;
+ Breakpoint bp = stopItem ? GetBreakpointById(stopItem.bkptno, &isInternal) : null;
+ if(bp && bp.inserted && bp.bp.addr)
{
- // In case the user put a breakpoint where an internal breakpoint is, avoid the confusion...
- for(i : ide.workspace.breakpoints)
+ if(bp.type.isInternal)
+ bpInternal = bp;
+ else
+ bpUser = bp;
+ if(stopItem && stopItem.frame)
{
- if(i.bp && i.line == stopItem.frame.line && !fstrcmp(i.absoluteFilePath, stopItem.frame.absoluteFile))
- bp = i;
- break;
+ if(bpInternal && bpRunToCursor && bpRunToCursor.inserted && !strcmp(bpRunToCursor.bp.addr, bp.bp.addr))
+ bpUser = bpRunToCursor;
+ else
+ {
+ for(item : (bpInternal ? ide.workspace.breakpoints : sysBPs); item.inserted)
+ {
+ if(item.bp && item.bp.addr && !strcmp(item.bp.addr, bp.bp.addr))
+ {
+ if(bpInternal)
+ bpUser = item;
+ else
+ bpInternal = item;
+ break;
+ }
+ }
+ }
}
+ else
+ _dpl2(_dpct, dplchan::debuggerProblem, 0, "Invalid stopItem!");
+ if(bpUser && strcmp(stopItem.frame.addr, bpUser.bp.addr))
+ _dpl2(_dpct, dplchan::debuggerProblem, 0, "Breakpoint bkptno(", stopItem.bkptno, ") address missmatch!");
}
- bpHit = bp;
-
- if(!(!userBreakOnInternBreak &&
- bp && (bp.type == internalMain || bp.type == internalWinMain || bp.type == internalModulesLoaded)))
+ else
+ _dpl2(_dpct, dplchan::debuggerProblem, 0, "Breakpoint bkptno(", stopItem.bkptno, ") invalid or not found!");
+ if((bpUser && !ignoreBreakpoints) || (bpInternal && userAction.breaksOnInternalBreakpoint))
monitor = true;
hitThread = stopItem.threadid;
}
break;
case signal:
signalThread = stopItem.threadid;
+ case breakEvent:
case stepEnd:
case functionEnd:
+ case locationReached:
monitor = true;
+ ignoreBreakpoints = false;
+ break;
+ case valgrindStartPause:
+ GdbExecContinue(true);
+ monitor = false;
break;
case exit:
HideDebuggerViews();
break;
}
-
- if(monitor)
- {
- activeThread = stopItem.threadid;
- GdbCommand(false, "-thread-list-ids");
- GdbGetStack();
- if(activeFrameLevel > 0)
- GdbCommand(false, "-stack-select-frame %d", activeFrameLevel);
- WatchesCodeEditorLinkInit();
- EvaluateWatches();
+ if(curEvent == signal)
+ {
+ char * s;
+ signalOn = true;
+ ide.outputView.debugBox.Logf($"Signal received: %s - %s\n", stopItem.name, stopItem.meaning);
+ ide.outputView.debugBox.Logf(" %s:%d\n", (s = CopySystemPath(stopItem.frame.file)), stopItem.frame.line);
+ ide.outputView.Show();
+ ide.callStackView.Show();
+ delete s;
}
-
- switch(curEvent)
+ else if(curEvent == breakEvent)
{
- case signal:
+ ide.threadsView.Show();
+ ide.callStackView.Show();
+ ide.callStackView.Activate();
+ }
+ else if(curEvent == hit)
+ {
+ if(BreakpointHit(stopItem, bpInternal, bpUser))
{
- char * s;
- signalOn = true;
- ide.outputView.debugBox.Logf($"Signal received: %s - %s\n", stopItem.name, stopItem.meaning);
- ide.outputView.debugBox.Logf(" %s:%d\n", (s = CopySystemPath(stopItem.frame.file)), stopItem.frame.line);
- delete s;
+ ide.AdjustDebugMenus();
+ if(bpUser && bpUser.type == runToCursor)
+ {
+ ignoreBreakpoints = false;
+ UnsetBreakpoint(bpUser);
+ delete bpRunToCursor;
+ }
}
- case stepEnd:
- case functionEnd:
- case breakEvent:
- // Why was SelectFrame missing here?
- SelectFrame(activeFrameLevel);
- GoToStackFrameLine(activeFrameLevel, curEvent == signal || curEvent == stepEnd /*false*/);
- ide.Activate();
- ide.Update(null);
- if(curEvent == signal)
- ide.outputView.Show();
- if(curEvent == signal || curEvent == breakEvent)
+ else
+ {
+ if(breakType == advance && bpInternal && (bpInternal.type == internalMain || bpInternal.type == internalEntry))
{
- if(curEvent == breakEvent)
- ide.threadsView.Show();
- ide.callStackView.Show();
+ breakType = none;
+ GdbExecAdvance(breakString, 0);
+ delete breakString;
}
- ide.ShowCodeEditor();
- if(curEvent == breakEvent)
- ide.callStackView.Activate();
- break;
- case hit:
- EventHit(stopItem);
- break;
+ else
+ {
+ GdbExecContinue(false);
+ monitor = false;
+ }
+ }
+ }
+
+ if(monitor && curEvent.canBeMonitored)
+ {
+ GdbGetStack();
+ activeThread = stopItem.threadid;
+ GdbCommand(false, "-thread-list-ids");
+ InternalSelectFrame(activeFrameLevel);
+ GoToStackFrameLine(activeFrameLevel, true, false);
+ EvaluateWatches();
+ ide.ShowCodeEditor();
+ ide.AdjustDebugMenus();
+ ideMainFrame.Activate(); // TOFIX: ide.Activate() is not reliable (app inactive)
+ ide.Update(null);
}
-
- if(curEvent != hit)
- ignoreBreakpoints = false;
-
+
if(stopItem)
{
stopItem.Free();
ProgramThread progThread { };
#endif
+#ifdef _DEBUG_INST
+#define _ChangeUserAction(value) ChangeUserAction(__FILE__, __LINE__, value)
+ void ChangeUserAction(char * file, int line, DebuggerUserAction value)
+ {
+ bool same = value == userAction;
+ __dpl2(file, line, _dpct, dplchan::debuggerUserAction, 0, userAction, /*same ? " *** == *** " : */" -> ", value);
+ userAction = value;
+ }
+#else
+#define _ChangeUserAction(value) userAction = value
+#endif
+
+#ifdef _DEBUG_INST
+#define _ChangeState(value) ChangeState(__FILE__, __LINE__, value)
+ void ChangeState(char * file, int line, DebuggerState value)
+#else
+#define _ChangeState(value) ChangeState(value)
void ChangeState(DebuggerState value)
+#endif
{
bool same = value == state;
- // if(same) PrintLn("Debugger::ChangeState -- changing to same state");
+#ifdef _DEBUG_INST
+ __dpl2(file, line, _dpct, dplchan::debuggerState, 0, state, same ? " *** == *** " : " -> ", value);
+#endif
state = value;
- if(!same && ide) ide.AdjustDebugMenus();
+ if(!same) ide.AdjustDebugMenus();
}
void CleanUp()
{
- // Stop(); // Don't need to call Stop here, because ~ProjectView() will call it explicitly.
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::CleanUp");
stackFrames.Free(Frame::Free);
sentKill = false;
sentBreakInsert = false;
ignoreBreakpoints = false;
- userBreakOnInternBreak = false;
signalOn = false;
activeFrameLevel = 0;
targetDir = null;
targetFile = null;
-
- ChangeState(none);
+
+ _ChangeState(none);
event = none;
breakType = none;
- stopItem = null;
- bpItem = null;
+ delete stopItem;
+ delete bpItem;
activeFrame = 0;
-
+
bpRunToCursor = null;
- bpHit = null;
delete currentCompiler;
prjConfig = null;
- codeEditor = null;
+
+ WatchesReleaseCodeEditor();
+
+ entryPoint = false;
+ projectsLibraryLoaded.Free();
/*GdbThread gdbThread
Timer gdbTimer*/
}
-
+
Debugger()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::constructor");
ideProcessId = Process_GetCurrentProcessId();
- sysBPs.Add(Breakpoint { type = internalMain, enabled = true, level = -1 });
+ sysBPs.Add((intBpEntry = Breakpoint { type = internalEntry, enabled = false, level = -1 }));
+ sysBPs.Add((intBpMain = Breakpoint { type = internalMain, function = "main", enabled = true, level = -1 }));
#if defined(__WIN32__)
- sysBPs.Add(Breakpoint { type = internalWinMain, enabled = true, level = -1 });
+ sysBPs.Add((intBpWinMain = Breakpoint { type = internalWinMain, function = "WinMain", enabled = true, level = -1 }));
#endif
sysBPs.Add(Breakpoint { type = internalModulesLoaded, enabled = true, level = -1 });
-
+ sysBPs.Add(Breakpoint { type = internalModuleLoad, function = "InternalModuleLoadBreakpoint", enabled = true, level = -1 });
}
~Debugger()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::destructor");
sysBPs.Free();
Stop();
CleanUp();
void Resume()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Resume");
+ _ChangeUserAction(resume);
GdbExecContinue(true);
}
void Break()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Break");
+ _ChangeUserAction(_break);
if(state == running)
{
if(targetProcessId)
void Stop()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Stop");
+ _ChangeUserAction(stop);
switch(state)
{
case running:
break;
case stopped:
GdbAbortExec();
+ HideDebuggerViews();
+ GdbExit();
+ break;
case loaded:
GdbExit();
break;
}
}
- void Restart(CompilerConfig compiler, ProjectConfig config)
+ void Restart(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
{
- switch(state)
- {
- case running:
- if(targetProcessId)
- {
- breakType = restart;
- GdbDebugBreak(false);
- }
- break;
- case stopped:
- GdbAbortExec();
- case none:
- case terminated:
- if(!GdbInit(compiler, config))
- break;
- case loaded:
- GdbExecRun();
- break;
- }
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Restart");
+ _ChangeUserAction(restart);
+ if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
+ GdbExecRun();
}
bool GoToCodeLine(char * location)
{
CodeLocation codloc;
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToCodeLine(", location, ")");
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;
return false;
}
- bool GoToStackFrameLine(int stackLevel, bool askForLocation)
+ bool GoToStackFrameLine(int stackLevel, bool askForLocation, bool fromCallStack)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToStackFrameLine(", stackLevel, ", ", askForLocation, ")");
if(ide)
{
char filePath[MAX_LOCATION];
break;
if(frame)
{
- ide.callStackView.Show();
+ if(!fromCallStack)
+ ide.callStackView.Show();
- if(!frame.absoluteFile && frame.file)
+ if(frame.absoluteFile)
+ editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
+ if(!editor && frame.file)
frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
if(!frame.absoluteFile && askForLocation && frame.file)
{
char * s;
char title[MAX_LOCATION];
-
- sprintf(title, $"Provide source file location for %s", (s = CopySystemPath(frame.file)));
+ snprintf(title, sizeof(title), $"Provide source file location for %s", (s = CopySystemPath(frame.file)));
+ title[sizeof(title)-1] = 0;
delete s;
if(SourceDirDialog(title, ide.workspace.projectDir, frame.file, sourceDir))
{
frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
}
}
- if(frame.absoluteFile)
- editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal);
+ if(!editor && frame.absoluteFile)
+ editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
+ if(editor)
+ ide.RepositionWindows(false);
ide.Update(null);
if(editor && frame.line)
{
void SelectThread(int thread)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectThread(", thread, ")");
+ _ChangeUserAction(selectThread);
if(state == stopped)
{
if(thread != activeThread)
ide.callStackView.Clear();
GdbCommand(false, "-thread-select %d", thread);
GdbGetStack();
- // Why was SelectFrame missing here?
- SelectFrame(activeFrameLevel);
- GoToStackFrameLine(activeFrameLevel, true);
- WatchesCodeEditorLinkRelease();
- WatchesCodeEditorLinkInit();
+ InternalSelectFrame(activeFrameLevel);
+ GoToStackFrameLine(activeFrameLevel, true, false);
EvaluateWatches();
ide.Update(null);
}
void SelectFrame(int frame)
{
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectFrame(", frame, ")");
+ _ChangeUserAction(selectFrame);
if(state == stopped)
{
- if(frame != activeFrameLevel || !codeEditor || !codeEditor.visible)
+ if(frame != activeFrameLevel)
{
- activeFrameLevel = frame; // there is no active frame number in the gdb reply
- GdbCommand(false, "-stack-select-frame %d", activeFrameLevel);
- for(activeFrame = stackFrames.first; activeFrame; activeFrame = activeFrame.next)
- if(activeFrame.level == activeFrameLevel)
- break;
-
- WatchesCodeEditorLinkRelease();
- WatchesCodeEditorLinkInit();
+ InternalSelectFrame(frame);
EvaluateWatches();
ide.Update(null);
}
}
}
+ void InternalSelectFrame(int frame)
+ {
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::InternalSelectFrame(", frame, ")");
+ activeFrameLevel = frame; // there is no active frame number in the gdb reply
+ GdbCommand(false, "-stack-select-frame %d", activeFrameLevel);
+ for(activeFrame = stackFrames.first; activeFrame; activeFrame = activeFrame.next)
+ if(activeFrame.level == activeFrameLevel)
+ break;
+ }
+
void HandleExit(char * reason, char * code)
{
bool returnedExitCode = false;
char verboseExitCode[128];
-
- ChangeState(loaded); // this state change seems to be superfluous, might be in case of gdb crash
+
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::HandleExit(", reason, ", ", code, ")");
+ _ChangeState(loaded); // this state change seems to be superfluous, might be in case of gdb crash
targetProcessId = 0;
if(code)
- sprintf(verboseExitCode, $" with exit code %s", code);
+ {
+ snprintf(verboseExitCode, sizeof(verboseExitCode), $" with exit code %s", code);
+ verboseExitCode[sizeof(verboseExitCode)-1] = 0;
+ }
else
verboseExitCode[0] = '\0';
-
+
event = exit;
// ClearBreakDisplay();
}
#if defined(__unix__)
- progThread.terminate = true;
- if(fifoFile)
+ if(!usingValgrind)
{
- fifoFile.CloseInput();
- app.Unlock();
- progThread.Wait();
- app.Lock();
- delete fifoFile;
- }
+ progThread.terminate = true;
+ if(fifoFile)
+ {
+ fifoFile.CloseInput();
+ app.Unlock();
+ progThread.Wait();
+ app.Lock();
+ delete fifoFile;
+ }
+ }
#endif
{
}
ide.Update(null);
}
-
- void Start(CompilerConfig compiler, ProjectConfig config)
+
+ DebuggerState StartSession(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool restart, bool ignoreBreakpoints)
{
- ide.outputView.debugBox.Clear();
- switch(state)
+ DebuggerState result = none;
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StartSession(restart(", restart, "), ignoreBreakpoints(", ignoreBreakpoints, ")");
+ if(restart && state == running && targetProcessId)
{
- case none:
- case terminated:
- if(!GdbInit(compiler, config))
- break;
- case loaded:
- GdbExecRun();
- break;
+ breakType = DebuggerAction::restart;
+ GdbDebugBreak(false);
}
- }
-
- void StepInto(CompilerConfig compiler, ProjectConfig config)
- {
- switch(state)
+ else
{
- case none:
- case terminated:
- if(!GdbInit(compiler, config))
- break;
- case loaded:
+ if(restart && state == stopped)
+ GdbAbortExec();
+ if(needReset && state == loaded)
+ GdbExit(); // this reset is to get a clean state with all the breakpoints until a better state can be maintained on program exit
+ result = state;
+ if(result == none || result == terminated)
+ {
ide.outputView.ShowClearSelectTab(debug);
ide.outputView.debugBox.Logf($"Starting debug mode\n");
- userBreakOnInternBreak = true;
- GdbExecRun();
- break;
- case stopped:
- GdbExecStep();
- break;
- }
- }
- void StepOver(CompilerConfig compiler, ProjectConfig config, bool ignoreBkpts)
- {
- switch(state)
+ for(bp : sysBPs)
+ {
+ bp.hits = 0;
+ bp.breaks = 0;
+ }
+ for(bp : ide.workspace.breakpoints)
+ {
+ bp.hits = 0;
+ bp.breaks = 0;
+ }
+
+ if(GdbInit(compiler, config, bitDepth, useValgrind))
+ result = state;
+ else
+ result = error;
+ }
+ this.ignoreBreakpoints = ignoreBreakpoints;
+ }
+ return result;
+ }
+
+ void Start(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
+ {
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Start()");
+ _ChangeUserAction(start);
+ if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
+ GdbExecRun();
+ }
+
+ void StepInto(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
+ {
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepInto()");
+ _ChangeUserAction(stepInto);
+ switch(StartSession(compiler, config, bitDepth, useValgrind, false, false))
{
- case none:
- case terminated:
- if(!GdbInit(compiler, config))
- break;
- case loaded:
- ide.outputView.ShowClearSelectTab(debug);
- ide.outputView.debugBox.Logf($"Starting debug mode\n");
- ignoreBreakpoints = ignoreBkpts;
- userBreakOnInternBreak = true;
- GdbExecRun();
- break;
- case stopped:
- ignoreBreakpoints = ignoreBkpts;
- if(ignoreBreakpoints)
- GdbBreakpointsDelete(true);
- GdbExecNext();
- break;
+ case loaded: GdbExecRun(); break;
+ case stopped: GdbExecStep(); break;
+ }
+ }
+
+ void StepOver(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
+ {
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOver()");
+ _ChangeUserAction(stepOver);
+ switch(StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints))
+ {
+ case loaded: GdbExecRun(); break;
+ case stopped: GdbExecNext(); break;
+ }
+ }
+
+ void StepUntil(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
+ {
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepUntil()");
+ _ChangeUserAction(stepUntil);
+ switch(StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints))
+ {
+ case loaded: GdbExecRun(); break;
+ case stopped: GdbExecUntil(null, 0); break;
}
}
- void StepOut(bool ignoreBkpts)
+ void StepOut(bool ignoreBreakpoints)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOut()");
+ _ChangeUserAction(stepOut);
if(state == stopped)
{
- ignoreBreakpoints = ignoreBkpts;
- if(ignoreBreakpoints)
- GdbBreakpointsDelete(true);
- GdbExecFinish();
+ this.ignoreBreakpoints = ignoreBreakpoints;
+ if(frameCount > 1)
+ GdbExecFinish();
+ else
+ GdbExecContinue(true);
}
}
- void RunToCursor(CompilerConfig compiler, ProjectConfig config, char * absoluteFilePath, int lineNumber, bool ignoreBkpts)
+ void RunToCursor(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, char * absoluteFilePath, int lineNumber, bool ignoreBreakpoints, bool atSameLevel, bool oldImplementation)
{
char relativeFilePath[MAX_LOCATION];
- DebuggerState oldState = state;
- ignoreBreakpoints = ignoreBkpts;
- if(!ide.projectView.GetRelativePath(absoluteFilePath, relativeFilePath))
- strcpy(relativeFilePath, absoluteFilePath);
- switch(state)
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::RunToCursor()");
+ _ChangeUserAction(runToCursor);
+ WorkspaceGetRelativePath(absoluteFilePath, relativeFilePath, null);
+
+ if(bpRunToCursor && bpRunToCursor.inserted && symbols)
{
- case none:
- case terminated:
- Start(compiler, config);
- case stopped:
- case loaded:
- if(symbols)
- {
- if(state == loaded)
- {
- ide.outputView.ShowClearSelectTab(debug);
- ide.outputView.debugBox.Logf($"Starting debug mode\n");
- }
- RunToCursorPrepare(absoluteFilePath, relativeFilePath, lineNumber);
- sentBreakInsert = true;
- GdbCommand(false, "-break-insert %s:%d", relativeFilePath, lineNumber);
- bpRunToCursor.bp = bpItem;
- bpItem = null;
- bpRunToCursor.inserted = (bpRunToCursor.bp.number != 0);
- ValidateBreakpoint(bpRunToCursor);
- }
- break;
+ UnsetBreakpoint(bpRunToCursor);
+ delete bpRunToCursor;
+ }
+
+ StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints);
+
+#if 0
+ if(oldImplementation)
+ {
+ bpRunToCursor = Breakpoint { };
+ bpRunToCursor.absoluteFilePath = absoluteFilePath;
+ bpRunToCursor.relativeFilePath = relativeFilePath;
+ bpRunToCursor.line = lineNumber;
+ bpRunToCursor.type = runToCursor;
+ bpRunToCursor.enabled = true;
+ bpRunToCursor.level = atSameLevel ? frameCount - activeFrameLevel -1 : -1;
}
- switch(oldState)
+#endif
+ if(state == loaded)
{
- case loaded:
- if(ignoreBreakpoints)
- GdbBreakpointsDelete(false);
- GdbExecRun();
- break;
- case stopped:
- if(ignoreBreakpoints)
- GdbBreakpointsDelete(false);
+ breakType = advance;
+ breakString = PrintString(relativeFilePath, ":", lineNumber);
+ GdbExecRun();
+ }
+ else if(state == stopped)
+ {
+ if(oldImplementation)
GdbExecContinue(true);
- break;
+ else
+ {
+ if(atSameLevel)
+ GdbExecUntil(absoluteFilePath, lineNumber);
+ else
+ GdbExecAdvance(absoluteFilePath, lineNumber);
+ }
}
-
}
void GetCallStackCursorLine(bool * error, int * lineCursor, int * lineTopFrame)
{
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetCallStackCursorLine()");
if(activeFrameLevel == -1)
{
*error = false;
else
{
*error = signalOn && activeThread == signalThread;
- *lineCursor = activeFrameLevel + 1;
+ *lineCursor = activeFrameLevel - ((frameCount > 192 && activeFrameLevel > 191) ? frameCount - 192 - 1 : 0) + 1;
*lineTopFrame = activeFrameLevel ? 1 : 0;
}
}
char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
int count = 0;
Iterator<Breakpoint> it { ide.workspace.breakpoints };
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetMarginIconsLineNumbers()");
while(it.Next() && count < max)
{
Breakpoint bp = it.data;
*lineTopFrame = stopItem.frame.line;
else
*lineTopFrame = 0;
-
+
if(*lineTopFrame == *lineCursor && *lineTopFrame)
*lineTopFrame = 0;
}
void ChangeWatch(DataRow row, char * expression)
{
Watch wh = (Watch)row.tag;
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ChangeWatch(", expression, ")");
if(wh)
{
delete wh.expression;
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);
char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
Link bpLink, next;
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::MoveIcons()");
for(bpLink = ide.workspace.breakpoints.first; bpLink; bpLink = next)
{
Breakpoint bp = (Breakpoint)bpLink.data;
}
}
}
-
+
// moving code cursors is futile, on next step, stop, hit, cursors will be offset anyways
}
bool retry;
String srcDir = null;
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SourceDirDialog()");
debuggerFileDialog.text = title;
debuggerFileDialog.currentDirectory = startDir;
debuggerFileDialog.master = ide;
while(debuggerFileDialog.Modal())
{
strcpy(sourceDir, debuggerFileDialog.filePath);
- if(!fstrcmp(ide.workspace.projectDir, sourceDir) &&
- MessageBox { type = yesNo, master = ide,
- contents = $"This is the project directory.\nWould you like to try again?",
+ if(!fstrcmp(ide.workspace.projectDir, sourceDir) &&
+ MessageBox { type = yesNo, master = ide,
+ contents = $"This is the project directory.\nWould you like to try again?",
text = $"Invalid Source Directory" }.Modal() == no)
return false;
else
break;
}
}
-
- if(srcDir &&
- MessageBox { type = yesNo, master = ide,
- contents = $"This source directory is already specified.\nWould you like to try again?",
+
+ if(srcDir &&
+ MessageBox { type = yesNo, master = ide,
+ contents = $"This source directory is already specified.\nWould you like to try again?",
text = $"Invalid Source Directory" }.Modal() == no)
return false;
else
strcpy(file, sourceDir);
PathCat(file, test);
result = FileExists(file);
- if(!result &&
- MessageBox { type = yesNo, master = ide,
- contents = $"Unable to locate source file.\nWould you like to try again?",
+ if(!result &&
+ MessageBox { type = yesNo, master = ide,
+ contents = $"Unable to locate source file.\nWould you like to try again?",
text = $"Invalid Source Directory" }.Modal() == no)
return false;
}
else
result = true;
-
+
if(result)
return true;
}
void AddSourceDir(char * sourceDir)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::AddSourceDir(", sourceDir, ")");
ide.workspace.sourceDirs.Add(CopyString(sourceDir));
ide.workspace.Save();
-
+
if(targeted)
{
DebuggerState oldState = state;
}
}
- void ToggleBreakpoint(char * fileName, int lineNumber, Project prj)
+ void ToggleBreakpoint(char * fileName, int lineNumber)
{
- char winFilePath[MAX_LOCATION];
- char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
char absolutePath[MAX_LOCATION];
- char relativePath[MAX_LOCATION];
- char sourceDir[MAX_LOCATION];
Breakpoint bp = null;
- strcpy(absolutePath, absoluteFilePath);
+ _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::ToggleBreakpoint(", fileName, ":", lineNumber, ")");
+
+ GetSlashPathBuffer(absolutePath, fileName);
for(i : ide.workspace.breakpoints; i.type == user && i.absoluteFilePath && !fstrcmp(i.absoluteFilePath, absolutePath) && i.line == lineNumber)
{
bp = i;
}
else
{
- // FIXED: This is how it should have been... Source locations are only for files not in project
- // if(eString_PathInsideOf(absolutePath, ide.workspace.projectDir))
- // MakePathRelative(absolutePath, ide.workspace.projectDir, relativePath);
- bool result = false;
- if(prj)
- result = prj.GetRelativePath(absolutePath, relativePath);
- else
- ide.projectView.GetRelativePath(absolutePath, relativePath);
- //if(ide.projectView.GetRelativePath(absolutePath, relativePath));
- //else
- if(!result)
+ Project owner;
+ char relativePath[MAX_LOCATION];
+
+ WorkspaceGetRelativePath(absolutePath, relativePath, &owner);
+
+ if(!owner && !FileExists(absolutePath))
{
char title[MAX_LOCATION];
char directory[MAX_LOCATION];
+ char sourceDir[MAX_LOCATION];
StripLastDirectory(absolutePath, directory);
- sprintf(title, $"Provide source files location directory for %s", absolutePath);
+ snprintf(title, sizeof(title), $"Provide source files location directory for %s", relativePath);
+ title[sizeof(title)-1] = 0;
while(true)
{
String srcDir = null;
for(dir : ide.workspace.sourceDirs)
{
- if(eString_PathInsideOf(absolutePath, dir))
+ if(IsPathInsideOf(absolutePath, dir))
{
- MakePathRelative(absoluteFilePath, dir, relativePath);
+ MakePathRelative(absolutePath, dir, relativePath);
srcDir = dir;
break;
}
}
if(srcDir)
break;
-
+
if(SourceDirDialog(title, directory, null, sourceDir))
{
- if(eString_PathInsideOf(absolutePath, sourceDir))
+ if(IsPathInsideOf(absolutePath, sourceDir))
{
AddSourceDir(sourceDir);
- MakePathRelative(absoluteFilePath, sourceDir, relativePath);
+ MakePathRelative(absolutePath, sourceDir, relativePath);
break;
}
- else if(MessageBox { type = yesNo, master = ide,
- contents = $"You must provide a valid source directory in order to place a breakpoint in this file.\nWould you like to try again?",
+ else if(MessageBox { type = yesNo, master = ide,
+ contents = $"You must provide a valid source directory in order to place a breakpoint in this file.\nWould you like to try again?",
text = $"Invalid Source Directory" }.Modal() == no)
return;
}
- else if(MessageBox { type = yesNo, master = ide,
- contents = $"You must provide a source directory in order to place a breakpoint in this file.\nWould you like to try again?",
- text = $"No Source Directory Provided" }.Modal() == no)
+ else
return;
}
}
ide.workspace.bpCount++;
- bp = { line = lineNumber, type = user, enabled = true, level = -1 };
+ bp = { line = lineNumber, type = user, enabled = true, level = -1, project = owner };
ide.workspace.breakpoints.Add(bp);
- bp.absoluteFilePath = CopyString(absolutePath);
- bp.relativeFilePath = CopyString(relativePath);
+ bp.absoluteFilePath = absolutePath;
+ bp.relativeFilePath = relativePath;
ide.breakpointsView.AddBreakpoint(bp);
}
GdbDebugBreak(true);
case stopped:
case loaded:
- if(symbols)
- {
- sentBreakInsert = true;
- GdbCommand(false, "-break-insert %s:%d", bp.relativeFilePath, bp.line);
- bp.bp = bpItem;
- bpItem = null;
- bp.inserted = (bp.bp && bp.bp.number != 0);
- ValidateBreakpoint(bp);
- }
+ SetBreakpoint(bp, false);
break;
}
if(oldState == running)
void UpdateRemovedBreakpoint(Breakpoint bp)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::UpdateRemovedBreakpoint()");
if(targeted && bp.inserted)
{
DebuggerState oldState = state;
GdbDebugBreak(true);
case stopped:
case loaded:
- if(symbols)
- GdbCommand(false, "-break-delete %d", bp.bp.number);
+ UnsetBreakpoint(bp);
break;
}
if(oldState == running)
Array<char *> argumentTokens { minAllocSize = 50 };
DebugListItem item { };
Argument arg;
-
+
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
TokenizeList(string, ',', frameTokens);
for(i = 0; i < frameTokens.count; i++)
{
if(!strcmp(item.name, "level"))
frame.level = atoi(item.value);
else if(!strcmp(item.name, "addr"))
- frame.addr = CopyString(item.value);
+ frame.addr = item.value;
else if(!strcmp(item.name, "func"))
- frame.func = CopyString(item.value);
+ frame.func = item.value;
else if(!strcmp(item.name, "args"))
{
if(!strcmp(item.value, "[]"))
if(!strcmp(item.name, "name"))
{
StripQuotes(item.value, item.value);
- arg.name = CopyString(item.value);
+ arg.name = item.value;
}
else if(!strcmp(item.name, "value"))
{
StripQuotes(item.value, item.value);
- arg.value = CopyString(item.value);
+ arg.val = item.value;
}
else
- DebuggerProtocolUnknown("Unknown frame args item name", item.name);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame args item (", item.name, "=", item.value, ") is unheard of");
}
- else
- DebuggerProtocolUnknown("Bad frame args item", "");
+ else
+ _dpl(0, "Bad frame args item");
}
argumentTokens.RemoveAll();
}
else if(!strcmp(item.name, "from"))
frame.from = item.value;
else if(!strcmp(item.name, "file"))
- {
frame.file = item.value;
- frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
- }
else if(!strcmp(item.name, "line"))
frame.line = atoi(item.value);
else if(!strcmp(item.name, "fullname"))
- {
- // New GDB is giving us a full name... Any reason why we coudln't figure it out ourselves?
- }
+ frame.absoluteFile = item.value;
+ /*{
+ // GDB 6.3 on OS X is giving "fullname" and "dir", all in absolute, but file name only in 'file'
+ String path = ide.workspace.GetPathWorkspaceRelativeOrAbsolute(item.value);
+ if(strcmp(frame.file, path))
+ {
+ frame.file = path;
+ frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
+ }
+ delete path;
+ }*/
else
- DebuggerProtocolUnknown("Unknown frame member name", item.name);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame member (", item.name, "=", item.value, ") is unheard of");
}
else
- DebuggerProtocolUnknown("Bad frame", "");
+ _dpl(0, "Bad frame");
}
-
+
delete frameTokens;
delete argsTokens;
delete argumentTokens;
delete item;
}
+ Breakpoint GetBreakpointById(int id, bool * isInternal)
+ {
+ Breakpoint bp = null;
+ //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::GetBreakpointById(", id, ")");
+ if(isInternal)
+ *isInternal = false;
+ if(id)
+ {
+ for(i : sysBPs; i.bp && i.bp.id == id)
+ {
+ if(isInternal)
+ *isInternal = true;
+ bp = i;
+ break;
+ }
+ if(!bp && bpRunToCursor && bpRunToCursor.bp && bpRunToCursor.bp.id == id)
+ bp = bpRunToCursor;
+ if(!bp)
+ {
+ for(i : ide.workspace.breakpoints; i.bp && i.bp.id == id)
+ {
+ bp = i;
+ break;
+ }
+ }
+ }
+ return bp;
+ }
+
+ GdbDataBreakpoint ParseBreakpoint(char * string, Array<char *> outTokens)
+ {
+ int i;
+ GdbDataBreakpoint bp { };
+ DebugListItem item { };
+ Array<char *> bpTokens { minAllocSize = 16 };
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseBreakpoint()");
+ string = StripCurlies(string);
+ TokenizeList(string, ',', bpTokens);
+ for(i = 0; i < bpTokens.count; i++)
+ {
+ if(TokenizeListItem(bpTokens[i], item))
+ {
+ StripQuotes(item.value, item.value);
+ if(!strcmp(item.name, "number"))
+ {
+ if(!strchr(item.value, '.'))
+ bp.id = atoi(item.value);
+ bp.number = item.value;
+ }
+ else if(!strcmp(item.name, "type"))
+ bp.type = item.value;
+ else if(!strcmp(item.name, "disp"))
+ bp.disp = item.value;
+ else if(!strcmp(item.name, "enabled"))
+ bp.enabled = (!strcmpi(item.value, "y"));
+ else if(!strcmp(item.name, "addr"))
+ {
+ if(outTokens && !strcmp(item.value, "<MULTIPLE>"))
+ {
+ int c = 1;
+ Array<GdbDataBreakpoint> bpArray = bp.multipleBPs = { };
+ while(outTokens.count > ++c)
+ {
+ GdbDataBreakpoint multBp = ParseBreakpoint(outTokens[c], null);
+ bpArray.Add(multBp);
+ }
+ }
+ else
+ bp.addr = item.value;
+ }
+ else if(!strcmp(item.name, "func"))
+ bp.func = item.value;
+ else if(!strcmp(item.name, "file"))
+ bp.file = item.value;
+ else if(!strcmp(item.name, "fullname"))
+ bp.fullname = item.value;
+ else if(!strcmp(item.name, "line"))
+ bp.line = atoi(item.value);
+ else if(!strcmp(item.name, "at"))
+ bp.at = item.value;
+ else if(!strcmp(item.name, "times"))
+ bp.times = atoi(item.value);
+ else if(!strcmp(item.name, "original-location") || !strcmp(item.name, "thread-groups"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "breakpoint member (", item.name, "=", item.value, ") is ignored");
+ else
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "breakpoint member (", item.name, "=", item.value, ") is unheard of");
+ }
+ }
+ delete bpTokens;
+ delete item;
+ return bp;
+ }
+
void ShowDebuggerViews()
{
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ShowDebuggerViews()");
ide.outputView.Show();
ide.outputView.SelectTab(debug);
ide.threadsView.Show();
void HideDebuggerViews()
{
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::HideDebuggerViews()");
ide.RepositionWindows(true);
}
{
if(gdbHandle)
{
- char string[MAX_F_STRING];
-
+ // TODO: Improve this limit
+ static char string[MAX_F_STRING*4];
va_list args;
va_start(args, format);
- vsprintf(string, format, args);
+ vsnprintf(string, sizeof(string), format, args);
+ string[sizeof(string)-1] = 0;
va_end(args);
-
+
gdbReady = false;
ide.debugger.serialSemaphore.TryWait();
-
#ifdef GDB_DEBUG_CONSOLE
- Log(string); Log("\n");
+ _dpl2(_dpct, dplchan::gdbCommand, 0, string);
#endif
#ifdef GDB_DEBUG_OUTPUT
ide.outputView.gdbBox.Logf("cmd: %s\n", string);
if(ide.gdbDialog)
ide.gdbDialog.AddCommand(string);
#endif
- gdbHandle.Printf("%s\n", string);
-
+
+ strcat(string,"\n");
+ gdbHandle.Puts(string);
+
if(focus)
Process_ShowWindows(targetProcessId);
app.Unlock();
ide.debugger.serialSemaphore.Wait();
app.Lock();
- }
+ }
}
bool ValidateBreakpoint(Breakpoint bp)
{
- if(modules)
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ValidateBreakpoint()");
+ if(modules && bp.line && bp.bp)
{
if(bp.bp.line != bp.line)
{
if(!bp.bp.line)
{
#ifdef _DEBUG
+ //here
ide.outputView.debugBox.Logf("WOULD HAVE -- Invalid breakpoint disabled: %s:%d\n", bp.relativeFilePath, bp.line);
#endif
- if(bp.inserted)
- {
- //GdbCommand(false, "-break-delete %d", bp.bp.number);
- //bp.inserted = false;
- }
+ //UnsetBreakpoint(bp);
//bp.enabled = false;
return false;
}
else
{
+ //here
ide.outputView.debugBox.Logf("Debugger Error: ValidateBreakpoint error\n");
bp.line = bp.bp.line;
}
return true;
}
- static void GdbInsertInternalBreakpoint()
+ void BreakpointsMaintenance()
{
+ //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::BreakpointsMaintenance()");
if(symbols)
{
- //if(!breakpointsInserted)
+ if(gdbExecution.suspendInternalBreakpoints)
{
- DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig);
- for(bp : sysBPs)
+ for(bp : sysBPs; bp.inserted)
+ UnsetBreakpoint(bp);
+ }
+ else
+ {
+ DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig, bitDepth);
+ for(bp : sysBPs; !bp.inserted)
{
- if(!bp.inserted)
+ bool insert = false;
+ if(bp.type == internalModulesLoaded)
{
- if(bp.type == internalMain)
- {
- sentBreakInsert = true;
- GdbCommand(false, "-break-insert main");
- bp.bp = bpItem;
- bpItem = null;
- bp.inserted = (bp.bp && bp.bp.number != 0);
- }
-#if defined(__WIN32__)
- else if(bp.type == internalWinMain)
+ char path[MAX_LOCATION];
+ char name[MAX_LOCATION];
+ char fixedModuleName[MAX_FILENAME];
+ char line[16384];
+ int lineNumber;
+ bool moduleLoadBlock = false;
+ File f;
+ ReplaceSpaces(fixedModuleName, ide.project.moduleName);
+ snprintf(name, sizeof(name),"%s.main.ec", fixedModuleName);
+ name[sizeof(name)-1] = 0;
+ strcpy(path, ide.workspace.projectDir);
+ PathCatSlash(path, objDir.dir);
+ PathCatSlash(path, name);
+ f = FileOpen(path, read);
+ if(f)
{
- sentBreakInsert = true;
- GdbCommand(false, "-break-insert WinMain");
- bp.bp = bpItem;
- bpItem = null;
- bp.inserted = (bp.bp && bp.bp.number != 0);
+ for(lineNumber = 1; !f.Eof(); lineNumber++)
+ {
+ if(f.GetLine(line, sizeof(line) - 1))
+ {
+ bool moduleLoadLine;
+ TrimLSpaces(line, line);
+ moduleLoadLine = !strncmp(line, "eModule_Load", strlen("eModule_Load"));
+ if(!moduleLoadBlock && moduleLoadLine)
+ moduleLoadBlock = true;
+ else if(moduleLoadBlock && !moduleLoadLine && strlen(line) > 0)
+ break;
+ }
+ }
+ if(!f.Eof())
+ {
+ char relative[MAX_LOCATION];
+ bp.absoluteFilePath = path;
+ MakePathRelative(path, ide.workspace.projectDir, relative);
+ bp.relativeFilePath = relative;
+ bp.line = lineNumber;
+ insert = true;
+ }
+ delete f;
}
-#endif
- else if(bp.type == internalModulesLoaded)
+ }
+ else if(bp.type == internalModuleLoad)
+ {
+ if(modules)
{
- char path[MAX_LOCATION];
- char name[MAX_LOCATION];
- char fixedModuleName[MAX_FILENAME];
- char line[16384];
- int lineNumber;
- bool moduleLoadBlock = false;
- File f;
- ReplaceSpaces(fixedModuleName, ide.project.moduleName);
- sprintf(name, "%s.main.ec", fixedModuleName);
- strcpy(path, ide.workspace.projectDir);
- PathCatSlash(path, objDir.dir);
- PathCatSlash(path, name);
- f = FileOpen(path, read);
- if(f)
+ for(prj : ide.workspace.projects)
{
- for(lineNumber = 1; !f.Eof(); lineNumber++)
+ if(!strcmp(prj.moduleName, "ecere"))
{
- if(f.GetLine(line, sizeof(line) - 1))
+ ProjectNode node = prj.topNode.Find("instance.c", false);
+ if(node)
{
- bool moduleLoadLine;
- TrimLSpaces(line, line);
- moduleLoadLine = !strncmp(line, "eModule_Load", strlen("eModule_Load"));
- if(!moduleLoadBlock && moduleLoadLine)
- moduleLoadBlock = true;
- else if(moduleLoadBlock && !moduleLoadLine && strlen(line) > 0)
- break;
+ char path[MAX_LOCATION];
+ char relative[MAX_LOCATION];
+ node.GetFullFilePath(path);
+ bp.absoluteFilePath = path;
+ MakePathRelative(path, prj.topNode.path, relative);
+ bp.relativeFilePath = relative;
+ insert = true;
+ break;
}
}
- if(!f.Eof())
- {
- char relative[MAX_LOCATION];
- bp.absoluteFilePath = CopyString(path);
- MakePathRelative(path, ide.workspace.projectDir, relative);
- delete bp.relativeFilePath;
- bp.relativeFilePath = CopyString(relative);
- bp.line = lineNumber;
- sentBreakInsert = true;
- GdbCommand(false, "-break-insert %s:%d", bp.relativeFilePath, lineNumber);
- bp.bp = bpItem;
- bpItem = null;
- bp.inserted = (bp.bp && bp.bp.number != 0);
- ValidateBreakpoint(bp);
- }
- delete f;
}
- break;
}
}
+ else
+ insert = true;
+ if(insert)
+ SetBreakpoint(bp, false);
}
delete objDir;
}
- }
- }
- void GdbBreakpointsInsert()
- {
- if(symbols)
- {
- //if(!breakpointsInserted)
+ if(userAction != runToCursor && bpRunToCursor && bpRunToCursor.inserted)
+ UnsetBreakpoint(bpRunToCursor);
+ if(bpRunToCursor && !bpRunToCursor.inserted)
+ SetBreakpoint(bpRunToCursor, false);
+
+ if(ignoreBreakpoints)
{
- //if(!ignoreBreakpoints)
- //breakpointsInserted = true;
- for(bp : ide.workspace.breakpoints)
+ for(bp : ide.workspace.breakpoints; bp.inserted)
+ UnsetBreakpoint(bp);
+ }
+ else
+ {
+ for(bp : ide.workspace.breakpoints; !bp.inserted && bp.type == user)
{
- if(!bp.inserted && bp.type == user)
+ if(bp.enabled)
+ {
+ if(!SetBreakpoint(bp, false))
+ SetBreakpoint(bp, true);
+ }
+ else
{
- if(!ignoreBreakpoints && bp.enabled)
- {
- sentBreakInsert = true;
- GdbCommand(false, "-break-insert %s:%d", bp.relativeFilePath, bp.line);
- bp.bp = bpItem;
- bpItem = null;
- bp.inserted = (bp.bp && bp.bp.number != 0);
- bp.hits = 0;
- bp.breaks = 0;
- ValidateBreakpoint(bp);
- }
- else
- {
#ifdef _DEBUG
- if(bp.bp)
- printf("problem\n");
+ if(bp.bp)
+ _dpl(0, "problem");
#endif
- bp.bp = GdbDataBreakpoint { };
- }
+ delete bp.bp;
+ bp.bp = GdbDataBreakpoint { };
}
}
- if(bpRunToCursor && !bpRunToCursor.inserted)
- {
- sentBreakInsert = true;
- GdbCommand(false, "-break-insert %s:%d", bpRunToCursor.relativeFilePath, bpRunToCursor.line);
- bpRunToCursor.bp = bpItem;
- bpItem = null;
- bpRunToCursor.inserted = (bpRunToCursor.bp && bpRunToCursor.bp.number != 0);
- ValidateBreakpoint(bpRunToCursor);
- }
}
}
}
- void GdbBreakpointsDelete(bool deleteRunToCursor)
+ void UnsetBreakpoint(Breakpoint bp)
{
- //breakpointsInserted = false;
- if(symbols)
+ char * s; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::UnsetBreakpoint(", s=bp.CopyLocationString(false), ") -- ", bp.type); delete s;
+ if(symbols && bp.inserted)
{
- for(bp : ide.workspace.breakpoints)
+ GdbCommand(false, "-break-delete %s", bp.bp.number);
+ bp.inserted = false;
+ delete bp.bp;
+ bp.bp = { };
+ }
+ }
+
+ bool SetBreakpoint(Breakpoint bp, bool removePath)
+ {
+ char * s; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::SetBreakpoint(", s=bp.CopyLocationString(false), ", ", removePath ? "**** removePath(true) ****" : "", ") -- ", bp.type); delete s;
+ breakpointError = false;
+ if(symbols && bp.enabled && (!bp.project || bp.project.GetTargetType(bp.project.config) == staticLibrary || bp.project == ide.project || projectsLibraryLoaded[bp.project.name]))
+ {
+ sentBreakInsert = true;
+ if(bp.address)
+ GdbCommand(false, "-break-insert *%s", bp.address);
+ else
{
- 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;
+ char * location = bp.CopyLocationString(removePath);
+ GdbCommand(false, "-break-insert %s", location);
+ delete location;
}
- if(deleteRunToCursor && bpRunToCursor)
+ if(!breakpointError)
{
- GdbCommand(false, "-break-delete %d", bpRunToCursor.bp.number);
- bpRunToCursor.inserted = false;
- bpRunToCursor.bp = bpItem;
- //check here (reply form -break-delete, returns bpitem?)
+ char * address = null;
+ if(bpItem && bpItem.multipleBPs && bpItem.multipleBPs.count)
+ {
+ int count = 0;
+ GdbDataBreakpoint first = null;
+ for(n : bpItem.multipleBPs)
+ {
+ if(!fstrcmp(n.fullname, bp.absoluteFilePath) && !first)
+ {
+ count++;
+ first = n;
+ break;
+ }
+ /*else
+ {
+ if(n.enabled)
+ {
+ GdbCommand(false, "-break-disable %s", n.number);
+ n.enabled = false;
+ }
+ else
+ _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error breakpoint already disabled.");
+ }*/
+ }
+ if(first)
+ {
+ address = CopyString(first.addr);
+ bpItem.addr = first.addr;
+ bpItem.func = first.func;
+ bpItem.file = first.file;
+ bpItem.fullname = first.fullname;
+ bpItem.line = first.line;
+ //bpItem.thread-groups = first.thread-groups;*/
+ }
+ else if(count == 0)
+ _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints all disabled.");
+ else
+ _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints in exact same file not supported.");
+ bpItem.multipleBPs.Free();
+ delete bpItem.multipleBPs;
+ }
+ delete bp.bp;
+ bp.bp = bpItem;
bpItem = null;
+ bp.inserted = (bp.bp && bp.bp.number && strcmp(bp.bp.number, "0"));
+ if(bp.inserted)
+ ValidateBreakpoint(bp);
+
+ if(address)
+ {
+ UnsetBreakpoint(bp);
+ bp.address = address;
+ delete address;
+ SetBreakpoint(bp, removePath);
+ }
}
}
+ return !breakpointError;
}
void GdbGetStack()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbGetStack()");
activeFrame = null;
stackFrames.Free(Frame::Free);
GdbCommand(false, "-stack-info-depth");
if(!frameCount)
GdbCommand(false, "-stack-info-depth 192");
if(frameCount && frameCount <= 192)
- GdbCommand(false, "-stack-list-frames 0 191");
+ GdbCommand(false, "-stack-list-frames 0 %d", Min(frameCount-1, 191));
else
{
- GdbCommand(false, "-stack-list-frames 0 95");
+ GdbCommand(false, "-stack-list-frames 0 %d", Min(frameCount-1, 95));
GdbCommand(false, "-stack-list-frames %d %d", Max(frameCount - 96, 96), frameCount - 1);
}
GdbCommand(false, "");
bool GdbTargetSet()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbTargetSet()");
if(!targeted)
{
char escaped[MAX_LOCATION];
strescpy(escaped, targetFile);
- GdbCommand(false, "file \"%s\"", escaped); //GDB/MI Missing Implementation -symbol-file, -target-attach
+ GdbCommand(false, "file \"%s\"", escaped); //GDB/MI Missing Implementation in 5.1.1 but we now have -file-exec-and-symbols / -file-exec-file / -file-symbol-file
if(!symbols)
return true;
- for(prj : ide.workspace.projects)
+ if(usingValgrind)
{
- if(prj == ide.workspace.projects.firstIterator.data)
- continue;
-
- //PrintLn("THIS: ", (String)prj.topNode.path);
- GdbCommand(false, "-environment-directory \"%s\"", prj.topNode.path);
- //GdbCommand(false, ""); // why this empty GDB command
+ const char *vgdbCommand = "/usr/bin/vgdb"; // TODO: vgdb command config option
+ //GdbCommand(false, "-target-select remote | %s --pid=%d", "vgdb", targetProcessId);
+ printf("target remote | %s --pid=%d\n", vgdbCommand, targetProcessId);
+ GdbCommand(false, "target remote | %s --pid=%d", vgdbCommand, targetProcessId); // TODO: vgdb command config option
}
+ else
+ GdbCommand(false, "info target"); //GDB/MI Missing Implementation -file-list-symbol-files and -file-list-exec-sections
- for(dir : ide.workspace.sourceDirs)
+ /*for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
+ GdbCommand(false, "-environment-directory \"%s\"", prj.topNode.path);*/
+
+ for(dir : ide.workspace.sourceDirs; dir && dir[0])
{
- GdbCommand(false, "-environment-directory \"%s\"", dir);
- //GdbCommand(false, ""); // why this empty GDB command
+ bool interference = false;
+ for(prj : ide.workspace.projects)
+ {
+ if(!fstrcmp(prj.topNode.path, dir))
+ {
+ interference = true;
+ break;
+ }
+ }
+ if(!interference && dir[0])
+ GdbCommand(false, "-environment-directory \"%s\"", dir);
}
- GdbInsertInternalBreakpoint();
+
targeted = true;
}
return true;
}
- void GdbTargetRelease()
+ /*void GdbTargetRelease()
{
if(targeted)
{
- GdbBreakpointsDelete(true);
+ BreakpointsDeleteAll();
GdbCommand(false, "file"); //GDB/MI Missing Implementation -target-detach
targeted = false;
symbols = true;
}
- }
+ }*/
void GdbDebugBreak(bool internal)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbDebugBreak()");
if(targetProcessId)
{
if(internal)
serialSemaphore.Wait();
else
{
- ChangeState(loaded);
+ _ChangeState(loaded);
targetProcessId = 0;
}
app.Lock();
void GdbExecRun()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecRun()");
GdbTargetSet();
+ if(!usingValgrind)
+ gdbExecution = run;
GdbExecCommon();
ShowDebuggerViews();
- GdbCommand(true, "-exec-run");
+ if(usingValgrind)
+ GdbExecContinue(true);
+ else
+ GdbCommand(true, "-exec-run");
}
void GdbExecContinue(bool focus)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecContinue()");
+ gdbExecution = run;
GdbExecCommon();
GdbCommand(focus, "-exec-continue");
}
void GdbExecNext()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecNext()");
+ gdbExecution = next;
GdbExecCommon();
GdbCommand(true, "-exec-next");
}
+ void GdbExecUntil(char * absoluteFilePath, int lineNumber)
+ {
+ char relativeFilePath[MAX_LOCATION];
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecUntil()");
+ gdbExecution = until;
+ GdbExecCommon();
+ if(absoluteFilePath)
+ {
+ WorkspaceGetRelativePath(absoluteFilePath, relativeFilePath, null);
+ GdbCommand(true, "-exec-until %s:%d", relativeFilePath, lineNumber);
+ }
+ else
+ GdbCommand(true, "-exec-until");
+ }
+
+ void GdbExecAdvance(char * absoluteFilePathOrLocation, int lineNumber)
+ {
+ char relativeFilePath[MAX_LOCATION];
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecAdvance()");
+ gdbExecution = advance;
+ GdbExecCommon();
+ if(lineNumber)
+ {
+ WorkspaceGetRelativePath(absoluteFilePathOrLocation, relativeFilePath, null);
+ GdbCommand(true, "advance %s:%d", relativeFilePath, lineNumber); // should use -exec-advance -- GDB/MI implementation missing
+ }
+ else
+ GdbCommand(true, "advance %s", absoluteFilePathOrLocation); // should use -exec-advance -- GDB/MI implementation missing
+ }
+
void GdbExecStep()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecStep()");
+ gdbExecution = step;
GdbExecCommon();
GdbCommand(true, "-exec-step");
}
void GdbExecFinish()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecFinish()");
+ gdbExecution = finish;
GdbExecCommon();
GdbCommand(true, "-exec-finish");
}
void GdbExecCommon()
{
- ClearBreakDisplay();
- GdbBreakpointsInsert();
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecCommon()");
+ BreakpointsMaintenance();
}
#ifdef GDB_DEBUG_GUI
void SendGDBCommand(char * command)
{
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SendGDBCommand()");
DebuggerState oldState = state;
switch(state)
{
void ClearBreakDisplay()
{
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ClearBreakDisplay()");
activeThread = 0;
activeFrameLevel = -1;
hitThread = 0;
- bpHit = null;
signalThread = 0;
signalOn = false;
frameCount = 0;
event = none;
activeFrame = null;
stackFrames.Free(Frame::Free);
- WatchesCodeEditorLinkRelease();
ide.callStackView.Clear();
ide.threadsView.Clear();
ide.Update(null);
bool GdbAbortExec()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbAbortExec()");
sentKill = true;
GdbCommand(false, "-interpreter-exec console \"kill\""); // should use -exec-abort -- GDB/MI implementation incomplete
return true;
}
- bool GdbInit(CompilerConfig compiler, ProjectConfig config)
+ bool GdbInit(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
{
bool result = true;
char oldDirectory[MAX_LOCATION];
char tempPath[MAX_LOCATION];
- char command[MAX_LOCATION];
+ char command[MAX_F_STRING*4];
Project project = ide.project;
- DirExpression targetDirExp = project.GetTargetDir(compiler, config);
+ DirExpression targetDirExp = project.GetTargetDir(compiler, config, bitDepth);
PathBackup pathBackup { };
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbInit()");
if(currentCompiler != compiler)
{
delete currentCompiler;
incref currentCompiler;
}
prjConfig = config;
+ this.bitDepth = bitDepth;
+ usingValgrind = useValgrind;
- ChangeState(loaded);
+ _ChangeState(loaded);
sentKill = false;
sentBreakInsert = false;
+ breakpointError = false;
+ ignoreBreakpoints = false;
symbols = true;
targeted = false;
modules = false;
- //breakpointsInserted = false;
-
+ needReset = false;
+ projectsLibraryLoaded.Free();
+
ide.outputView.ShowClearSelectTab(debug);
ide.outputView.debugBox.Logf($"Starting debug mode\n");
-#ifdef GDB_DEBUG_CONSOLE
- Log("Starting GDB"); Log("\n");
-#endif
#ifdef GDB_DEBUG_OUTPUT
ide.outputView.gdbBox.Logf("run: Starting GDB\n");
#endif
}
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);
}
- sprintf(command, "gdb -n -silent --interpreter=mi2"); //-async //\"%s\"
- gdbTimer.Start();
- gdbHandle = DualPipeOpen(PipeOpenMode { output = 1, error = 2, input = 1 }, command);
- if(!gdbHandle)
- {
- ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start GDB\n");
- result = false;
- }
- if(result)
+ if(usingValgrind)
{
- incref gdbHandle;
- gdbThread.Create();
-
- gdbProcessId = gdbHandle.GetProcessID();
- if(!gdbProcessId)
+ char * clArgs = ide.workspace.commandLineArgs;
+ const char *valgrindCommand = "valgrind"; // TODO: valgrind command config option //TODO: valgrind options
+ ValgrindLeakCheck vgLeakCheck = ide.workspace.vgLeakCheck;
+ int vgRedzoneSize = ide.workspace.vgRedzoneSize;
+ bool vgTrackOrigins = ide.workspace.vgTrackOrigins;
+ vgLogFile = CreateTemporaryFile(vgLogPath, "ecereidevglog");
+ if(vgLogFile)
{
- ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't get GDB process ID\n");
+ incref vgLogFile;
+ vgLogThread.Create();
+ }
+ else
+ {
+ ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't open temporary log file for Valgrind output\n");
result = false;
}
- if(result)
+ if(result && !CheckCommandAvailable(valgrindCommand))
{
- app.Unlock();
+ ide.outputView.debugBox.Logf($"Debugger Fatal Error: Command %s for Valgrind is not available.\n", valgrindCommand);
+ result = false;
+ }
+ if(result)
+ {
+ char * vgRedzoneSizeFlag = vgRedzoneSize == -1 ? "" : PrintString(" --redzone-size=", vgRedzoneSize);
+ sprintf(command, "%s --vgdb=yes --vgdb-error=0 --log-file=%s --leak-check=%s%s --track-origins=%s %s%s%s",
+ valgrindCommand, vgLogPath, (char*)vgLeakCheck, vgRedzoneSizeFlag, vgTrackOrigins ? "yes" : "no", targetFile, clArgs ? " " : "", clArgs ? clArgs : "");
+ if(vgRedzoneSize != -1)
+ delete vgRedzoneSizeFlag;
+ vgTargetHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
+ if(!vgTargetHandle)
+ {
+ ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start Valgrind\n");
+ result = false;
+ }
+ }
+ if(result)
+ {
+ incref vgTargetHandle;
+ vgTargetThread.Create();
+
+ targetProcessId = vgTargetHandle.GetProcessID();
+ waitingForPID = false;
+ if(!targetProcessId)
+ {
+ ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't get Valgrind process ID\n");
+ result = false;
+ }
+ }
+ if(result)
+ {
+ app.Unlock();
serialSemaphore.Wait();
app.Lock();
+ }
+ }
- if(!GdbTargetSet())
+ if(result)
+ {
+ strcpy(command,
+ (compiler.targetPlatform == win32 && bitDepth == 64) ? "x86_64-w64-mingw32-gdb" :
+ (compiler.targetPlatform == win32 && bitDepth == 32) ? "i686-w64-mingw32-gdb" :
+ "gdb");
+ if(!CheckCommandAvailable(command))
+ {
+ ide.outputView.debugBox.Logf($"Debugger Fatal Error: Command %s for GDB is not available.\n", command);
+ result = false;
+ }
+ else
+ {
+ strcat(command, " -n -silent --interpreter=mi2"); //-async //\"%s\"
+ gdbTimer.Start();
+ gdbHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
+ if(!gdbHandle)
{
- //ChangeState(terminated);
+ ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start GDB\n");
result = false;
}
+ }
+ }
+ if(result)
+ {
+ incref gdbHandle;
+ gdbThread.Create();
- if(result)
- {
+ gdbProcessId = gdbHandle.GetProcessID();
+ if(!gdbProcessId)
+ {
+ ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't get GDB process ID\n");
+ result = false;
+ }
+ }
+ if(result)
+ {
+ app.Unlock();
+ serialSemaphore.Wait();
+ app.Lock();
+
+ GdbCommand(false, "-gdb-set verbose off");
+ //GdbCommand(false, "-gdb-set exec-done-display on");
+ GdbCommand(false, "-gdb-set step-mode off");
+ GdbCommand(false, "-gdb-set unwindonsignal on");
+ //GdbCommand(false, "-gdb-set shell on");
+ GdbCommand(false, "set print elements 992");
+ GdbCommand(false, "-gdb-set backtrace limit 100000");
+
+ if(!GdbTargetSet())
+ {
+ //_ChangeState(terminated);
+ result = false;
+ }
+ }
+ if(result)
+ {
#if defined(__unix__)
- {
- CreateTemporaryDir(progFifoDir, "ecereide");
- strcpy(progFifoPath, progFifoDir);
- PathCat(progFifoPath, "ideprogfifo");
- if(!mkfifo(progFifoPath, 0600))
- {
- //fileCreated = true;
- }
- else
- {
- //app.Lock();
- ide.outputView.debugBox.Logf(createFIFOMsg, progFifoPath);
- //app.Unlock();
- }
- }
+ {
+ CreateTemporaryDir(progFifoDir, "ecereide");
+ strcpy(progFifoPath, progFifoDir);
+ PathCat(progFifoPath, "ideprogfifo");
+ if(!mkfifo(progFifoPath, 0600))
+ {
+ //fileCreated = true;
+ }
+ else
+ {
+ //app.Lock();
+ ide.outputView.debugBox.Logf(createFIFOMsg, progFifoPath);
+ //app.Unlock();
+ }
+ }
- progThread.terminate = false;
- progThread.Create();
+ if(!usingValgrind)
+ {
+ progThread.terminate = false;
+ progThread.Create();
+ }
#endif
-
+
#if defined(__WIN32__)
- GdbCommand(false, "-gdb-set new-console on");
+ GdbCommand(false, "-gdb-set new-console on");
#endif
-
- GdbCommand(false, "-gdb-set verbose off");
- //GdbCommand(false, "-gdb-set exec-done-display on");
- GdbCommand(false, "-gdb-set step-mode off");
- GdbCommand(false, "-gdb-set unwindonsignal on");
- //GdbCommand(false, "-gdb-set shell on");
- GdbCommand(false, "set print elements 992");
- GdbCommand(false, "-gdb-set backtrace limit 100000");
#if defined(__unix__)
- GdbCommand(false, "-inferior-tty-set %s", progFifoPath);
+ if(!usingValgrind)
+ GdbCommand(false, "-inferior-tty-set %s", progFifoPath);
#endif
- GdbCommand(false, "-gdb-set args %s", ide.workspace.commandLineArgs ? ide.workspace.commandLineArgs : "");
- /*
- for(e : ide.workspace.environmentVars)
- {
- GdbCommand(false, "set environment %s=%s", e.name, e.string);
- }
- */
- }
+ if(!usingValgrind)
+ GdbCommand(false, "-gdb-set args %s", ide.workspace.commandLineArgs ? ide.workspace.commandLineArgs : "");
+ /*
+ for(e : ide.workspace.environmentVars)
+ {
+ GdbCommand(false, "set environment %s=%s", e.name, e.string);
}
+ */
}
ChangeWorkingDir(oldDirectory);
void GdbExit()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExit()");
if(gdbHandle && gdbProcessId)
{
+ gdbTimer.Stop();
GdbCommand(false, "-gdb-exit");
if(gdbThread)
gdbThread.Wait();
app.Lock();
}
+ if(vgLogThread)
+ {
+ app.Unlock();
+ vgLogThread.Wait();
+ app.Lock();
+ }
+ if(vgTargetThread)
+ {
+ app.Unlock();
+ vgTargetThread.Wait();
+ app.Lock();
+ }
+
+ if(vgLogFile)
+ delete vgLogFile;
if(gdbHandle)
{
gdbHandle.Wait();
}
}
gdbTimer.Stop();
- ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
+ _ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
prjConfig = null;
+ needReset = false;
if(ide.workspace)
+ {
for(bp : ide.workspace.breakpoints)
- bp.inserted = false;
+ bp.Reset();
+ }
for(bp : sysBPs)
- bp.inserted = false;
+ bp.Reset();
if(bpRunToCursor)
- bpRunToCursor.inserted = false;
-
+ bpRunToCursor.Reset();
+
ide.outputView.debugBox.Logf($"Debugging stopped\n");
ClearBreakDisplay();
ide.Update(null);
#if defined(__unix__)
- if(FileExists(progFifoPath)) //fileCreated)
+ if(!usingValgrind && FileExists(progFifoPath)) //fileCreated)
{
progThread.terminate = true;
if(fifoFile)
progThread.Wait();
app.Lock();
delete fifoFile;
- }
+ }
DeleteFile(progFifoPath);
progFifoPath[0] = '\0';
rmdir(progFifoDir);
#endif
}
- void WatchesCodeEditorLinkInit()
+ bool WatchesLinkCodeEditor()
{
- /*
- char tempPath[MAX_LOCATION];
- char path[MAX_LOCATION];
-
- //void MakeFilePathProjectRelative(char * path, char * relativePath)
- if(!ide.projectView.GetRelativePath(activeFrame.file, tempPath))
- strcpy(tempPath, activeFrame.file);
-
- strcpy(path, ide.workspace.projectDir);
- PathCat(path, tempPath);
- codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no);
- if(!codeEditor)
+ bool goodFrame = activeFrame && activeFrame.absoluteFile;
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesLinkCodeEditor()");
+ if(codeEditor && (!goodFrame || fstrcmp(codeEditor.fileName, activeFrame.absoluteFile)))
+ WatchesReleaseCodeEditor();
+
+ if(!codeEditor && goodFrame)
{
- for(srcDir : ide.workspace.sourceDirs)
+ codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, normal, false, null, no, normal, false);
+ if(codeEditor)
{
- strcpy(path, srcDir);
- PathCat(path, tempPath);
- codeEditor = (CodeEditor)ide.OpenFile(path, Normal, false, null, no);
- if(codeEditor) break;
+ codeEditor.inUseDebug = true;
+ incref codeEditor;
}
}
- */
-
- if(activeFrame && !activeFrame.absoluteFile && activeFrame.file)
- activeFrame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(activeFrame.file);
- if(!activeFrame || !activeFrame.absoluteFile)
- codeEditor = null;
- else
- codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, normal, false, null, no, normal);
- if(codeEditor)
- {
- codeEditor.inUseDebug = true;
- incref codeEditor;
- }
- //watchesInit = true;
+ return codeEditor != null;
}
- void WatchesCodeEditorLinkRelease()
+ void WatchesReleaseCodeEditor()
{
- //if(watchesInit)
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesReleaseCodeEditor()");
+ if(codeEditor)
{
- if(codeEditor)
- {
- codeEditor.inUseDebug = false;
- if(!codeEditor.visible)
- codeEditor.Destroy(0);
- delete codeEditor;
- }
+ codeEditor.inUseDebug = false;
+ if(!codeEditor.visible)
+ codeEditor.Destroy(0);
+ delete codeEditor;
}
}
bool ResolveWatch(Watch wh)
{
bool result = false;
-
+
+ _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::ResolveWatch()");
wh.Reset();
/*delete wh.value;
- if(wh.type)
+ if(wh.type)
{
FreeType(wh.type);
wh.type = null;
SetGlobalContext(codeEditor.globalContext);
SetGlobalData(&codeEditor.globalData);
}
-
+
exp = ParseExpressionString(wh.expression);
-
+
if(exp && !parseError)
{
+ char expString[4096];
+ expString[0] = 0;
+ PrintExpression(exp, expString);
+
if(GetPrivateModule())
{
if(codeEditor)
if(wh.type)
wh.type.refCount++;
DebugComputeExpression(exp);
+ if(ExpressionIsError(exp))
+ {
+ GDBFallBack(exp, expString);
+ }
/*if(exp.hasAddress)
{
long v = (long)exp.val.f;
sprintf(temp, "%i", v);
break;
- }
+ }
case doubleType:
{
long v = (long)exp.val.d;
long v = (long)exp.val.f;
sprintf(temp, "0x%x", v);
break;
- }
+ }
case doubleType:
{
long v = (long)exp.val.d;
long v = (long)exp.val.f;
sprintf(temp, "0o%o", v);
break;
- }
+ }
case doubleType:
{
long v = (long)exp.val.d;
switch(exp.type)
{
case symbolErrorExp:
- sprintf(watchmsg, $"Symbol \"%s\" not found", exp.identifier.string);
+ snprintf(watchmsg, sizeof(watchmsg), $"Symbol \"%s\" not found", exp.identifier.string);
break;
case structMemberSymbolErrorExp:
// todo get info as in next case (ExpClassMemberSymbolError)
- sprintf(watchmsg, $"Error: Struct member not found for \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Error: Struct member not found for \"%s\"", wh.expression);
break;
case classMemberSymbolErrorExp:
{
{
char string[256] = "";
Symbol classSym;
- PrintType(type, string, false, true);
+ PrintTypeNoConst(type, string, false, true);
classSym = FindClass(string);
_class = classSym ? classSym.registered : null;
}
if(_class)
- sprintf(watchmsg, $"Member \"%s\" not found in class \"%s\"", memberID ? memberID.string : "", _class.name);
+ snprintf(watchmsg, sizeof(watchmsg), $"Member \"%s\" not found in class \"%s\"", memberID ? memberID.string : "", _class.name);
else
- sprintf(watchmsg, "Member \"%s\" not found in unregistered class? (Should never get this message)", memberID ? memberID.string : "");
+ snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in unregistered class? (Should never get this message)", memberID ? memberID.string : "");
}
else
- sprintf(watchmsg, "Member \"%s\" not found in no type? (Should never get this message)", memberID ? memberID.string : "");
+ snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in no type? (Should never get this message)", memberID ? memberID.string : "");
}
break;
case memoryErrorExp:
// Need to ensure when set to memoryErrorExp, constant is set
- sprintf(watchmsg, $"Memory can't be read at %s", /*(exp.type == constantExp) ? */exp.constant /*: null*/);
+ snprintf(watchmsg, sizeof(watchmsg), $"Memory can't be read at %s", /*(exp.type == constantExp) ? */exp.constant /*: null*/);
break;
case dereferenceErrorExp:
- sprintf(watchmsg, $"Dereference failure for \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Dereference failure for \"%s\"", wh.expression);
break;
case unknownErrorExp:
- sprintf(watchmsg, $"Unknown error for \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Unknown error for \"%s\"", wh.expression);
break;
case noDebuggerErrorExp:
- sprintf(watchmsg, $"Debugger required for symbol evaluation in \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Debugger required for symbol evaluation in \"%s\"", wh.expression);
break;
case debugStateErrorExp:
- sprintf(watchmsg, $"Incorrect debugger state for symbol evaluation in \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Incorrect debugger state for symbol evaluation in \"%s\"", wh.expression);
break;
case 0:
- sprintf(watchmsg, $"Null type for \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Null type for \"%s\"", wh.expression);
break;
case constantExp:
case stringExp:
// Temporary Code for displaying Strings
- if((exp.expType && ((exp.expType.kind == pointerType ||
- exp.expType.kind == arrayType) && exp.expType.type.kind == charType)) ||
- (wh.type && wh.type.kind == classType && wh.type._class &&
+ if((exp.expType && ((exp.expType.kind == pointerType ||
+ exp.expType.kind == arrayType) && exp.expType.type.kind == charType)) ||
+ (wh.type && wh.type.kind == classType && wh.type._class &&
wh.type._class.registered && wh.type._class.registered.type == normalClass &&
!strcmp(wh.type._class.registered.name, "String")))
{
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);
- //printf("%x\n", address);
- sprintf(value, "0x%08x ", address);
-
+ // address = strtoul(exp.constant, null, 0);
+ address = _strtoui64(exp.constant, null, 0);
+ //_dpl(0, "0x", 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)
strcat(value, $"Null string");
else
{
int c;
char ch;
-
+
for(c = 0; (ch = string[c]) && c<4096; c++)
- value[len++] = ch;
+ value[len++] = ch;
value[len++] = ')';
value[len++] = '\0';
-
+
}
else
{
wh.value = CopyString(value);
}
}
- else if(wh.type && wh.type.kind == classType && wh.type._class &&
+ else if(wh.type && wh.type.kind == classType && wh.type._class &&
wh.type._class.registered && wh.type._class.registered.type == enumClass)
{
uint64 value = strtoul(exp.constant, null, 0);
wh.value = CopyString(item.name);
else
wh.value = CopyString($"Invalid Enum Value");
- result = (bool)atoi(exp.constant);
+ result = true;
}
- else if(wh.type && (wh.type.kind == charType || (wh.type.kind == classType && wh.type._class &&
+ else if(wh.type && (wh.type.kind == charType || (wh.type.kind == classType && wh.type._class &&
wh.type._class.registered && !strcmp(wh.type._class.registered.fullName, "ecere::com::unichar"))) )
{
unichar value;
}
else
{
- value = strtoul(exp.constant, null, 0);
+ value = (uint)strtoul(exp.constant, null, 0);
signedValue = (int)value;
}
}
charString[0] = 0;
UTF32toUTF8Len(&value, 1, charString, 5);
if(value == '\0')
- sprintf(string, "\'\\0' (0)");
+ snprintf(string, sizeof(string), "\'\\0' (0)");
else if(value == '\t')
- sprintf(string, "\'\\t' (%d)", value);
+ snprintf(string, sizeof(string), "\'\\t' (%d)", value);
else if(value == '\n')
- sprintf(string, "\'\\n' (%d)", value);
+ snprintf(string, sizeof(string), "\'\\n' (%d)", value);
else if(value == '\r')
- sprintf(string, "\'\\r' (%d)", value);
+ snprintf(string, sizeof(string), "\'\\r' (%d)", value);
else if(wh.type.kind == charType && wh.type.isSigned)
- sprintf(string, "\'%s\' (%d)", charString, signedValue);
+ snprintf(string, sizeof(string), "\'%s\' (%d)", charString, signedValue);
else if(value > 256 || wh.type.kind != charType)
{
if(value > 0x10FFFF || !GetCharCategory(value))
- sprintf(string, $"Invalid Unicode Keypoint (0x%08X)", value);
+ snprintf(string, sizeof(string), $"Invalid Unicode Keypoint (0x%08X)", value);
else
- sprintf(string, "\'%s\' (U+%04X)", charString, value);
+ snprintf(string, sizeof(string), "\'%s\' (U+%04X)", charString, value);
}
else
- sprintf(string, "\'%s\' (%d)", charString, value);
-
+ snprintf(string, sizeof(string), "\'%s\' (%d)", charString, value);
+ string[sizeof(string)-1] = 0;
+
wh.value = CopyString(string);
result = true;
}
else
{
wh.value = CopyString(exp.constant);
- result = (bool)atoi(exp.constant);
+ result = true;
}
break;
default:
if(exp.hasAddress)
{
- wh.value = PrintHexUInt(exp.address);
- result = (bool)exp.address;
+ wh.value = PrintHexUInt64(exp.address);
+ result = true;
}
else
{
char tempString[256];
if(exp.member.memberType == propertyMember)
- sprintf(watchmsg, $"Missing property evaluation support for \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Missing property evaluation support for \"%s\"", wh.expression);
else
- sprintf(watchmsg, $"Evaluation failed for \"%s\" of type \"%s\"", wh.expression,
+ snprintf(watchmsg, sizeof(watchmsg), $"Evaluation failed for \"%s\" of type \"%s\"", wh.expression,
exp.type.OnGetString(tempString, null, null));
}
break;
}
}
else
- sprintf(watchmsg, $"Invalid expression: \"%s\"", wh.expression);
+ snprintf(watchmsg, sizeof(watchmsg), $"Invalid expression: \"%s\"", wh.expression);
if(exp) FreeExpression(exp);
-
+
SetPrivateModule(backupPrivateModule);
SetCurrentContext(backupContext);
SetTopContext(backupContext);
SetGlobalContext(backupContext);
SetThisClass(backupThisClass);
}
- //else
+ //else
// wh.value = CopyString("No source file found for selected frame");
-
+
+ watchmsg[sizeof(watchmsg)-1] = 0;
if(!wh.value)
wh.value = CopyString(watchmsg);
}
void EvaluateWatches()
{
- for(wh : ide.workspace.watches)
- ResolveWatch(wh);
+ _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateWatches()");
+ WatchesLinkCodeEditor();
+ if(state == stopped)
+ {
+ for(wh : ide.workspace.watches)
+ ResolveWatch(wh);
+ }
}
char * ::GdbEvaluateExpression(char * expression)
{
+ _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::GdbEvaluateExpression(", expression, ")");
eval.active = true;
eval.error = none;
GdbCommand(false, "-data-evaluate-expression \"%s\"", expression);
}
// 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)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemoryString(", address, ")");
eval.active = true;
eval.error = none;
#ifdef _DEBUG
if(!size)
- printf("GdbReadMemoryString called with size = 0!\n");
+ _dpl(0, "GdbReadMemoryString called with size = 0!");
#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)
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemory(", address, ")");
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");
+ _dpl(0, "GdbReadMemory called with bytes = 0!");
#endif
if(eval.active)
ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemory\n");
return null;
}
- void EventHit(GdbDataStop stopItem)
+ bool BreakpointHit(GdbDataStop stopItem, Breakpoint bpInternal, Breakpoint bpUser)
{
- bool conditionMet = true;
- Breakpoint bp = bpHit;
-
- if(!bp && bpRunToCursor)
+ bool result = true;
+ char * s1 = null; char * s2 = null;
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::BreakpointHit(",
+ "bpInternal(", bpInternal ? s1=bpInternal.CopyLocationString(false) : null, "), ",
+ "bpUser(", bpUser ? s2=bpUser.CopyLocationString(false) : null, ")) -- ",
+ "ignoreBreakpoints(", ignoreBreakpoints, "), ",
+ "hitCursorBreakpoint(", bpUser && bpUser.type == runToCursor, ")");
+ delete s1; delete s2;
+
+ if(bpUser)
{
- bp = bpRunToCursor;
- if(symbols)
- GdbCommand(false, "-break-delete %d", bp.bp.number);
+ bool conditionMet = true;
+ if(bpUser.condition)
+ {
+ if(WatchesLinkCodeEditor())
+ conditionMet = ResolveWatch(bpUser.condition);
+ else
+ conditionMet = false;
+ }
+ bpUser.hits++;
+ if(conditionMet)
+ {
+ if(!bpUser.ignore)
+ bpUser.breaks++;
+ else
+ {
+ bpUser.ignore--;
+ result = false;
+ }
+ }
+ else
+ result = false;
+ if(stopItem.frame.line && bpUser.line != stopItem.frame.line)
+ {
+ // updating user breakpoint on hit location difference
+ // todo, print something?
+ bpUser.line = stopItem.frame.line;
+ ide.breakpointsView.UpdateBreakpoint(bpUser.row);
+ ide.workspace.Save();
+ }
+ else
+ ide.breakpointsView.UpdateBreakpoint(bpUser.row);
}
-
- if(bp)
+ if(bpInternal)
{
- if(bp.type == user && bp.line != stopItem.frame.line)
+ bpInternal.hits++;
+ if(bpInternal.type == internalModulesLoaded)
+ modules = true;
+ if(userAction == stepOver)
{
- bp.line = stopItem.frame.line;
- ide.breakpointsView.UpdateBreakpoint(bp.row);
- ide.workspace.Save();
+ if((bpInternal.type == internalEntry && ((intBpMain && intBpMain.inserted) || (intBpWinMain && intBpWinMain.inserted))) ||
+ (bpInternal.type == internalMain && intBpWinMain && intBpWinMain.inserted))
+ result = false;
}
-
- switch(bp.type)
+ if(!bpUser && !userAction.breaksOnInternalBreakpoint)
{
- case internalMain:
- case internalWinMain:
- GdbBreakpointsInsert();
- if(userBreakOnInternBreak)
- {
- userBreakOnInternBreak = false;
- // Why was SelectFrame missing here?
- SelectFrame(activeFrameLevel);
- GoToStackFrameLine(activeFrameLevel, true);
- ide.Activate();
- ide.Update(null);
- }
- else
- GdbExecContinue(false);
- break;
- case internalModulesLoaded:
- modules = true;
- GdbBreakpointsInsert();
- GdbExecContinue(false);
- break;
- case user:
- case runToCursor:
- if(bp.condition)
- conditionMet = ResolveWatch(bp.condition);
- bp.hits++;
- if((bp.level == -1 || bp.level == frameCount-1) && conditionMet)
- {
- if(!bp.ignore)
- {
- bp.breaks++;
- ignoreBreakpoints = false;
- // Why was SelectFrame missing here?
- SelectFrame(activeFrameLevel);
- GoToStackFrameLine(activeFrameLevel, true);
- ide.Activate();
- ide.Update(null);
- if(bp.type == BreakpointType::runToCursor)
- {
- delete bpRunToCursor;
- bpRunToCursor = null;
- }
- }
- else
- {
- bp.ignore--;
- GdbExecContinue(false);
- }
- }
- else
- GdbExecContinue(false);
- ide.breakpointsView.UpdateBreakpoint(bp.row);
- break;
+ if(userAction == stepOut)
+ StepOut(ignoreBreakpoints);
+ else
+ result = false;
}
}
- else
- ide.outputView.debugBox.Logf("Debugger Error: Breakpoint hit could not match breakpoint instance\n");
+
+ if(!bpUser && !bpInternal)
+ result = false;
+
+ return result;
+ }
+
+ void ValgrindTargetThreadExit()
+ {
+ ide.outputView.debugBox.Logf($"ValgrindTargetThreadExit\n");
+ if(vgTargetHandle)
+ {
+ vgTargetHandle.Wait();
+ delete vgTargetHandle;
+ }
+ HandleExit(null, null);
}
void GdbThreadExit()
{
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbThreadExit()");
if(state != terminated)
{
- ChangeState(terminated);
+ _ChangeState(terminated);
targetProcessId = 0;
ClearBreakDisplay();
+ if(vgLogFile)
+ delete vgLogFile;
if(gdbHandle)
{
serialSemaphore.Release();
gdbTimer.Stop();
gdbHandle.Wait();
delete gdbHandle;
-
+
ide.outputView.debugBox.Logf($"Debugger Fatal Error: GDB lost\n");
ide.outputView.debugBox.Logf($"Debugging stopped\n");
ide.Update(null);
+ HideDebuggerViews();
}
- //ChangeState(terminated);
+ //_ChangeState(terminated);
}
}
void GdbThreadMain(char * output)
{
int i;
+ char * t;
Array<char *> outTokens { minAllocSize = 50 };
Array<char *> subTokens { minAllocSize = 50 };
DebugListItem item { };
DebugListItem item2 { };
bool setWaitingForPID = false;
-
+
#if defined(GDB_DEBUG_CONSOLE) || defined(GDB_DEBUG_GUI)
#ifdef GDB_DEBUG_CONSOLE
- Log(output); Log("\n");
+ // _dpl2(_dpct, dplchan::gdbOutput, 0, output);
+ puts(output);
#endif
#ifdef GDB_DEBUG_OUTPUT
{
if(ide.gdbDialog) ide.gdbDialog.AddOutput(output);
#endif
#endif
-
+
switch(output[0])
{
case '~':
ide.outputView.debugBox.Logf($"Target doesn't contain debug information!\n");
ide.Update(null);
}
+ if(!entryPoint && (t = strstr(output, "Entry point:")))
+ {
+ char * addr = t + strlen("Entry point:");
+ t = addr;
+ if(*t++ == ' ' && *t++ == '0' && *t == 'x')
+ {
+ *addr = '*';
+ while(isxdigit(*++t));
+ *t = '\0';
+ for(bp : sysBPs; bp.type == internalEntry)
+ {
+ bp.function = addr;
+ bp.enabled = entryPoint = true;
+ break;
+ }
+ }
+ }
break;
case '^':
gdbReady = false;
if(sentKill)
{
sentKill = false;
- ChangeState(loaded);
+ _ChangeState(loaded);
targetProcessId = 0;
if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
{
}
}
else
- DebuggerProtocolUnknown("Unknown kill reply", item.name);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "kill reply (", item.name, "=", item.value, ") is unheard of");
}
else
HandleExit(null, null);
sentBreakInsert = false;
#ifdef _DEBUG
if(bpItem)
- printf("problem\n");
+ _dpl(0, "problem");
#endif
- bpItem = GdbDataBreakpoint { };
- item.value = StripCurlies(item.value);
- TokenizeList(item.value, ',', subTokens);
- for(i = 0; i < subTokens.count; i++)
- {
- if(TokenizeListItem(subTokens[i], item))
- {
- StripQuotes(item.value, item.value);
- if(!strcmp(item.name, "number"))
- bpItem.number = atoi(item.value);
- else if(!strcmp(item.name, "type"))
- bpItem.type = CopyString(item.value);
- else if(!strcmp(item.name, "disp"))
- bpItem.disp = CopyString(item.value);
- else if(!strcmp(item.name, "enabled"))
- bpItem.enabled = (!strcmpi(item.value, "y"));
- else if(!strcmp(item.name, "addr"))
- bpItem.addr = CopyString(item.value);
- else if(!strcmp(item.name, "func"))
- bpItem.func = CopyString(item.value);
- else if(!strcmp(item.name, "file"))
- bpItem.file = item.value;
- else if(!strcmp(item.name, "line"))
- bpItem.line = atoi(item.value);
- else if(!strcmp(item.name, "at"))
- bpItem.at = CopyString(item.value);
- else if(!strcmp(item.name, "times"))
- bpItem.times = atoi(item.value);
- }
- }
+ delete bpItem;
+ bpItem = ParseBreakpoint(item.value, outTokens);
//breakType = bpValidation;
- //app.SignalEvent();
- subTokens.RemoveAll();
}
- else if(!strcmp(item.name, "BreakpointTable"))
- ide.outputView.debugBox.Logf("Debugger Error: Command reply BreakpointTable not handled\n");
else if(!strcmp(item.name, "depth"))
{
StripQuotes(item.value, item.value);
item.value = StripCurlies(item.value);
ParseFrame(frame, item.value);
if(frame.file && frame.from)
- DebuggerProtocolUnknown("Unexpected frame file and from members present", "");
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "unexpected frame file and from members present");
if(frame.file)
{
char * s;
}
}
else
- DebuggerProtocolUnknown("Unknown stack content", item.name);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "stack content (", item.name, "=", item.value, ") is unheard of");
}
}
if(activeFrameLevel == -1)
ide.threadsView.Logf("%3d \n", value);
}
else
- DebuggerProtocolUnknown("Unknown threads content", item.name);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "threads content (", item.name, "=", item.value, ") is unheard of");
}
if(!i)
break;
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"))
{
}
}
}
- else if(!strcmp(item.name, "source-path"))
- {
- }
+ else if(!strcmp(item.name, "source-path") || !strcmp(item.name, "BreakpointTable"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "command reply (", item.name, "=", item.value, ") is ignored");
else
- DebuggerProtocolUnknown("Unknown command reply", item.name);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "command reply (", item.name, "=", item.value, ") is unheard of");
}
}
else if(!strcmp(outTokens[0], "^running"))
{
waitingForPID = true;
setWaitingForPID = true;
+ ClearBreakDisplay();
}
else if(!strcmp(outTokens[0], "^exit"))
{
- ChangeState(terminated);
+ _ChangeState(terminated);
// ide.outputView.debugBox.Logf("Exit\n");
// ide.Update(null);
gdbReady = true;
if(sentBreakInsert)
{
sentBreakInsert = false;
-#ifdef _DEBUG
- if(bpItem)
- printf("problem\n");
-#endif
- bpItem = GdbDataBreakpoint { };
+ breakpointError = true;
}
if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
}
else if(!strcmp(item.value, "Cannot find bounds of current function"))
{
- ChangeState(stopped);
+ _ChangeState(stopped);
gdbHandle.Printf("-exec-continue\n");
}
else if(!strcmp(item.value, "ptrace: No such process."))
{
- ChangeState(loaded);
+ _ChangeState(loaded);
targetProcessId = 0;
}
else if(!strcmp(item.value, "Function \\\"WinMain\\\" not defined."))
}
else if(!strcmp(item.value, "You can't do that without a process to debug."))
{
- ChangeState(loaded);
+ _ChangeState(loaded);
targetProcessId = 0;
}
else if(strstr(item.value, "No such file or directory."))
{
- ChangeState(loaded);
+ _ChangeState(loaded);
targetProcessId = 0;
}
else if(strstr(item.value, "During startup program exited with code "))
{
- ChangeState(loaded);
+ _ChangeState(loaded);
targetProcessId = 0;
}
else
}
}
else
- DebuggerProtocolUnknown("Unknown error content", item.name);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "error content (", item.name, "=", item.value, ") is unheard of");
}
else
- DebuggerProtocolUnknown("Unknown result-record", outTokens[0]);
-
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "result-record: ", outTokens[0]);
outTokens.RemoveAll();
break;
case '+':
- DebuggerProtocolUnknown("Unknown status-async-output", outTokens[0]);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "status-async-output: ", outTokens[0]);
break;
case '=':
- if(TokenizeList(output, ',', outTokens) && !strcmp(outTokens[0], "=thread-group-created")) //=thread-group-created,id="7611"
- ;
- else if(!strcmp(outTokens[0], "=thread-created")) //=thread-created,id="1",group-id="7611"
- ;
- else if(!strcmp(outTokens[0], "=library-loaded")) //=library-loaded,id="/lib/ld-linux.so.2",target-name="/lib/ld-linux.so.2",host-name="/lib/ld-linux.so.2",symbols-loaded="0"
- ;
- else
- DebuggerProtocolUnknown("Unknown notify-async-output", outTokens[0]);
+ if(TokenizeList(output, ',', outTokens))
+ {
+ if(!strcmp(outTokens[0], "=library-loaded"))
+ FGODetectLoadedLibraryForAddedProjectIssues(outTokens);
+ else if(!strcmp(outTokens[0], "=thread-group-created") || !strcmp(outTokens[0], "=thread-group-added") ||
+ !strcmp(outTokens[0], "=thread-group-started") || !strcmp(outTokens[0], "=thread-group-exited") ||
+ !strcmp(outTokens[0], "=thread-created") || !strcmp(outTokens[0], "=thread-exited") ||
+ !strcmp(outTokens[0], "=cmd-param-changed") || !strcmp(outTokens[0], "=library-unloaded") ||
+ !strcmp(outTokens[0], "=breakpoint-modified"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, outTokens[0], outTokens.count>1 ? outTokens[1] : "",
+ outTokens.count>2 ? outTokens[2] : "", outTokens.count>3 ? outTokens[3] : "",
+ outTokens.count>4 ? outTokens[4] : "", outTokens.count>5 ? outTokens[5] : "",
+ outTokens.count>6 ? outTokens[6] : "", outTokens.count>7 ? outTokens[7] : "",
+ outTokens.count>8 ? outTokens[8] : "", outTokens.count>9 ? outTokens[9] : "");
+ else
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "notify-async-output: ", outTokens[0]);
+ }
outTokens.RemoveAll();
break;
case '*':
}
else if(!strcmp(outTokens[0], "*stopped"))
{
- ChangeState(stopped);
-
- if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
+ int tk;
+ _ChangeState(stopped);
+
+ for(tk = 1; tk < outTokens.count; tk++)
{
- if(!strcmp(item.name, "reason"))
+ if(TokenizeListItem(outTokens[tk], item))
{
- char * reason = item.value;
- StripQuotes(reason, reason);
- if(!strcmp(reason, "exited-normally") || !strcmp(reason, "exited") || !strcmp(reason, "exited-signalled"))
+ if(!strcmp(item.name, "reason"))
{
- char * exitCode;
- if(outTokens.count > 2 && TokenizeListItem(outTokens[2], item2))
+ char * reason = item.value;
+ StripQuotes(reason, reason);
+ if(!strcmp(reason, "exited-normally") || !strcmp(reason, "exited") || !strcmp(reason, "exited-signalled"))
{
- StripQuotes(item2.value, item2.value);
- if(!strcmp(item2.name, "exit-code"))
- exitCode = item2.value;
+ char * exitCode;
+ if(outTokens.count > tk+1 && TokenizeListItem(outTokens[tk+1], item2))
+ {
+ tk++;
+ StripQuotes(item2.value, item2.value);
+ if(!strcmp(item2.name, "exit-code"))
+ exitCode = item2.value;
+ else
+ exitCode = null;
+ }
else
exitCode = null;
+ HandleExit(reason, exitCode);
+ needReset = true;
}
- else
- exitCode = null;
- HandleExit(reason, exitCode);
- }
- else if(!strcmp(reason, "breakpoint-hit"))
- {
- #ifdef _DEBUG
- if(stopItem)
- printf("problem\n");
- #endif
- stopItem = GdbDataStop { };
-
- for(i = 2; i < outTokens.count; i++)
+ else if(!strcmp(reason, "breakpoint-hit") ||
+ !strcmp(reason, "function-finished") ||
+ !strcmp(reason, "end-stepping-range") ||
+ !strcmp(reason, "location-reached") ||
+ !strcmp(reason, "signal-received"))
{
- TokenizeListItem(outTokens[i], item);
- StripQuotes(item.value, item.value);
- if(!strcmp(item.name, "bkptno"))
- stopItem.bkptno = atoi(item.value);
- else if(!strcmp(item.name, "thread-id"))
- stopItem.threadid = atoi(item.value);
- else if(!strcmp(item.name, "frame"))
+ char r = reason[0];
+#ifdef _DEBUG
+ if(stopItem) _dpl(0, "problem");
+#endif
+ stopItem = GdbDataStop { };
+ stopItem.reason = r == 'b' ? breakpointHit : r == 'f' ? functionFinished : r == 'e' ? endSteppingRange : r == 'l' ? locationReached : signalReceived;
+
+ for(i = tk+1; i < outTokens.count; i++)
{
- item.value = StripCurlies(item.value);
- ParseFrame(stopItem.frame, item.value);
+ TokenizeListItem(outTokens[i], item);
+ StripQuotes(item.value, item.value);
+ if(!strcmp(item.name, "thread-id"))
+ stopItem.threadid = atoi(item.value);
+ else if(!strcmp(item.name, "frame"))
+ {
+ item.value = StripCurlies(item.value);
+ ParseFrame(stopItem.frame, item.value);
+ }
+ else if(stopItem.reason == breakpointHit && !strcmp(item.name, "bkptno"))
+ stopItem.bkptno = atoi(item.value);
+ else if(stopItem.reason == functionFinished && !strcmp(item.name, "gdb-result-var"))
+ stopItem.gdbResultVar = CopyString(item.value);
+ else if(stopItem.reason == functionFinished && !strcmp(item.name, "return-value"))
+ stopItem.returnValue = CopyString(item.value);
+ else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-name"))
+ stopItem.name = CopyString(item.value);
+ else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-meaning"))
+ stopItem.meaning = CopyString(item.value);
+ else if(!strcmp(item.name, "stopped-threads"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Advanced thread debugging not handled");
+ else if(!strcmp(item.name, "core"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Information (core) not used");
+ else if(!strcmp(item.name, "disp"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": (", item.name, "=", item.value, ")");
+ else
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown ", reason, " item name (", item.name, "=", item.value, ")");
}
- else
- DebuggerProtocolUnknown("Unknown breakpoint hit item name", item.name);
- }
-
- event = hit;
- }
- else if(!strcmp(reason, "end-stepping-range"))
- {
- #ifdef _DEBUG
- if(stopItem)
- printf("problem\n");
- #endif
- stopItem = GdbDataStop { };
- for(i = 2; i < outTokens.count; i++)
- {
- TokenizeListItem(outTokens[i], item);
- StripQuotes(item.value, item.value);
- if(!strcmp(item.name, "thread-id"))
- stopItem.threadid = atoi(item.value);
- else if(!strcmp(item.name, "frame"))
+ if(stopItem.reason == signalReceived && !strcmp(stopItem.name, "SIGTRAP"))
{
- item.value = StripCurlies(item.value);
- ParseFrame(stopItem.frame, item.value);
+ switch(breakType)
+ {
+ case internal:
+ breakType = none;
+ break;
+ case restart:
+ case stop:
+ break;
+ default:
+ event = breakEvent;
+ }
}
- else if(!strcmp(item.name, "reason"))
- ;
- else if(!strcmp(item.name, "bkptno"))
- ;
else
- DebuggerProtocolUnknown("Unknown end of stepping range item name", item.name);
- }
-
- event = stepEnd;
- ide.Update(null);
- }
- else if(!strcmp(reason, "function-finished"))
- {
- #ifdef _DEBUG
- if(stopItem)
- printf("problem\n");
- #endif
- stopItem = GdbDataStop { };
- stopItem.reason = CopyString(reason);
-
- for(i = 2; i < outTokens.count; i++)
- {
- TokenizeListItem(outTokens[i], item);
- StripQuotes(item.value, item.value);
- if(!strcmp(item.name, "thread-id"))
- stopItem.threadid = atoi(item.value);
- else if(!strcmp(item.name, "frame"))
{
- item.value = StripCurlies(item.value);
- ParseFrame(stopItem.frame, item.value);
+ event = r == 'b' ? hit : r == 'f' ? functionEnd : r == 'e' ? stepEnd : r == 'l' ? locationReached : signal;
+ ide.Update(null);
}
- else if(!strcmp(item.name, "gdb-result-var"))
- stopItem.gdbResultVar = CopyString(item.value);
- else if(!strcmp(item.name, "return-value"))
- stopItem.returnValue = CopyString(item.value);
- else
- DebuggerProtocolUnknown("Unknown function finished item name", item.name);
}
-
- event = functionEnd;
- ide.Update(null);
+ else if(!strcmp(reason, "watchpoint-trigger"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint trigger not handled");
+ else if(!strcmp(reason, "read-watchpoint-trigger"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason read watchpoint trigger not handled");
+ else if(!strcmp(reason, "access-watchpoint-trigger"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason access watchpoint trigger not handled");
+ else if(!strcmp(reason, "watchpoint-scope"))
+ _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint scope not handled");
+ else
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown reason: ", reason);
}
- else if(!strcmp(reason, "signal-received"))
+ else
{
- #ifdef _DEBUG
- if(stopItem)
- printf("problem\n");
- #endif
- stopItem = GdbDataStop { };
- stopItem.reason = CopyString(reason);
-
- for(i = 2; i < outTokens.count; i++)
- {
- TokenizeListItem(outTokens[i], item);
- StripQuotes(item.value, item.value);
- if(!strcmp(item.name, "signal-name"))
- stopItem.name = CopyString(item.value);
- else if(!strcmp(item.name, "signal-meaning"))
- stopItem.meaning = CopyString(item.value);
- else if(!strcmp(item.name, "thread-id"))
- stopItem.threadid = atoi(item.value);
- else if(!strcmp(item.name, "frame"))
- {
- item.value = StripCurlies(item.value);
- ParseFrame(stopItem.frame, item.value);
- }
- else
- DebuggerProtocolUnknown("Unknown signal reveived item name", item.name);
- }
- if(!strcmp(stopItem.name, "SIGTRAP"))
- {
- switch(breakType)
- {
- case internal:
- breakType = none;
- break;
- case restart:
- case stop:
- break;
- default:
- event = breakEvent;
- }
- }
- else
- {
- event = signal;
- }
+ PrintLn(output);
}
- else if(!strcmp(reason, "watchpoint-trigger"))
- DebuggerProtocolUnknown("Reason watchpoint trigger not handled", "");
- else if(!strcmp(reason, "read-watchpoint-trigger"))
- DebuggerProtocolUnknown("Reason read watchpoint trigger not handled", "");
- else if(!strcmp(reason, "access-watchpoint-trigger"))
- DebuggerProtocolUnknown("Reason access watchpoint trigger not handled", "");
- else if(!strcmp(reason, "watchpoint-scope"))
- DebuggerProtocolUnknown("Reason watchpoint scope not handled", "");
- else if(!strcmp(reason, "location-reached"))
- DebuggerProtocolUnknown("Reason location reached not handled", "");
- else
- DebuggerProtocolUnknown("Unknown reason", reason);
}
}
+ if(usingValgrind && event == none && !stopItem)
+ event = valgrindStartPause;
app.SignalEvent();
}
}
else
- DebuggerProtocolUnknown("Unknown exec-async-output", outTokens[0]);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown exec-async-output: ", outTokens[0]);
outTokens.RemoveAll();
break;
case '(':
int oldProcessID = targetProcessId;
GetLastDirectory(targetFile, exeFile);
- while(true)
+ while(!targetProcessId/*true*/)
{
targetProcessId = Process_GetChildExeProcessId(gdbProcessId, exeFile);
if(targetProcessId || gdbHandle.Peek()) break;
}
if(targetProcessId)
- ChangeState(running);
+ _ChangeState(running);
else if(!oldProcessID)
{
ide.outputView.debugBox.Logf($"Debugger Error: No target process ID\n");
// TO VERIFY: The rest of this block has not been thoroughly tested in this particular location
gdbHandle.Printf("-gdb-exit\n");
gdbTimer.Stop();
- ChangeState(terminated); //loaded;
+ _ChangeState(terminated); //loaded;
prjConfig = null;
if(ide.workspace)
bp.inserted = false;
if(bpRunToCursor)
bpRunToCursor.inserted = false;
-
+
ide.outputView.debugBox.Logf($"Debugging stopped\n");
ClearBreakDisplay();
#if defined(__unix__)
- if(FileExists(progFifoPath)) //fileCreated)
+ if(!usingValgrind && FileExists(progFifoPath)) //fileCreated)
{
progThread.terminate = true;
if(fifoFile)
serialSemaphore.Release();
}
else
- DebuggerProtocolUnknown($"Unknown prompt", output);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown prompt", output);
break;
case '&':
}
break;
default:
- DebuggerProtocolUnknown($"Unknown output", output);
+ _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown output: ", output);
}
if(!setWaitingForPID)
waitingForPID = false;
delete item2;
}
- void RunToCursorPrepare(char * absoluteFilePath, char * relativeFilePath, int lineNumber)
+ // From GDB Output functions
+ void FGODetectLoadedLibraryForAddedProjectIssues(Array<char *> outTokens)
{
- if(bpRunToCursor)
+ char path[MAX_LOCATION] = "";
+ char file[MAX_FILENAME] = "";
+ bool symbolsLoaded;
+ DebugListItem item { };
+ //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGODetectLoadedLibraryForAddedProjectIssues()");
+ for(token : outTokens)
{
- //bpRunToCursor.Free();
- bpRunToCursor = Breakpoint { };
+ if(TokenizeListItem(token, item))
+ {
+ if(!strcmp(item.name, "target-name"))
+ {
+ StripQuotes(item.value, path);
+ MakeSystemPath(path);
+ GetLastDirectory(path, file);
+ }
+ else if(!strcmp(item.name, "symbols-loaded"))
+ {
+ symbolsLoaded = (atoi(item.value) == 1);
+ }
+ }
}
- else
- bpRunToCursor = Breakpoint { };
+ delete item;
+ if(path[0] && file[0])
+ {
+ for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
+ {
+ bool match;
+ char * dot;
+ char prjTargetPath[MAX_LOCATION];
+ char prjTargetFile[MAX_FILENAME];
+ DirExpression targetDirExp = prj.GetTargetDir(currentCompiler, prj.config, bitDepth);
+ strcpy(prjTargetPath, prj.topNode.path);
+ PathCat(prjTargetPath, targetDirExp.dir);
+ delete targetDirExp;
+ prjTargetFile[0] = '\0';
+ prj.CatTargetFileName(prjTargetFile, currentCompiler, prj.config);
+ PathCat(prjTargetPath, prjTargetFile);
+ MakeSystemPath(prjTargetPath);
+
+ match = !fstrcmp(prjTargetFile, file);
+ if(!match && (dot = strstr(prjTargetFile, ".so.")))
+ {
+ char * dot3 = strstr(dot+4, ".");
+ if(dot3)
+ {
+ dot3[0] = '\0';
+ match = !fstrcmp(prjTargetFile, file);
+ }
+ if(!match)
+ {
+ dot[3] = '\0';
+ match = !fstrcmp(prjTargetFile, file);
+ }
+ }
+ if(match)
+ {
+ // TODO: nice visual feedback to better warn user. use some ide notification system or other means.
+ /* -- this is disabled because we can't trust gdb's symbols-loaded="0" field for =library-loaded (http://sourceware.org/bugzilla/show_bug.cgi?id=10693)
+ if(!symbolsLoaded)
+ ide.outputView.debugBox.Logf($"Attention! No symbols for loaded library %s matched to the %s added project.\n", path, prj.topNode.name);
+ */
+ match = !fstrcmp(prjTargetPath, path);
+ if(!match && (dot = strstr(prjTargetPath, ".so.")))
+ {
+ char * dot3 = strstr(dot+4, ".");
+ if(dot3)
+ {
+ dot3[0] = '\0';
+ match = !fstrcmp(prjTargetPath, path);
+ }
+ if(!match)
+ {
+ dot[3] = '\0';
+ match = !fstrcmp(prjTargetPath, path);
+ }
+ }
+ if(match)
+ projectsLibraryLoaded[prj.name] = true;
+ else
+ ide.outputView.debugBox.Logf($"Loaded library %s doesn't match the %s target of the %s added project.\n", path, prjTargetPath, prj.topNode.name);
+ break;
+ }
+ }
+ }
+ }
- if(absoluteFilePath)
- bpRunToCursor.absoluteFilePath = CopyString(absoluteFilePath);
- if(relativeFilePath)
- bpRunToCursor.relativeFilePath = CopyString(relativeFilePath);
- bpRunToCursor.line = lineNumber;
- bpRunToCursor.type = runToCursor;
- bpRunToCursor.enabled = true;
- bpRunToCursor.condition = null;
- bpRunToCursor.ignore = 0;
- bpRunToCursor.level = -1;
+ void FGOBreakpointModified(Array<char *> outTokens)
+ {
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGOBreakpointModified() -- TODO only if needed: support breakpoint modified");
+#if 0
+ DebugListItem item { };
+ if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
+ {
+ if(!strcmp(item.name, "bkpt"))
+ {
+ GdbDataBreakpoint modBp = ParseBreakpoint(item.value, outTokens);
+ delete modBp;
+ }
+ }
+#endif
}
+
ExpressionType ::DebugEvalExpTypeError(char * result)
{
+ _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::DebugEvalExpTypeError()");
if(result)
return dummyExp;
switch(eval.error)
char * ::EvaluateExpression(char * expression, ExpressionType * error)
{
char * result;
+ _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateExpression(", expression, ")");
if(ide.projectView && ide.debugger.state == stopped)
{
result = GdbEvaluateExpression(expression);
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);
+ _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ReadMemory(", address, ")");
if(!result || !strcmp(result, "N/A"))
*error = memoryErrorExp;
else
}
}
+class ValgrindLogThread : Thread
+{
+ Debugger debugger;
+
+ unsigned int Main()
+ {
+ static char output[4096];
+ Array<char> dynamicBuffer { minAllocSize = 4096 };
+ File oldValgrindHandle = vgLogFile;
+ incref oldValgrindHandle;
+
+ app.Lock();
+ while(debugger.state != terminated && vgLogFile)
+ {
+ int result;
+ app.Unlock();
+ result = vgLogFile.Read(output, 1, sizeof(output));
+ app.Lock();
+ if(debugger.state == terminated || !vgLogFile/* || vgLogFile.Eof()*/)
+ break;
+ if(result)
+ {
+ int c;
+ int start = 0;
+
+ for(c = 0; c<result; c++)
+ {
+ if(output[c] == '\n')
+ {
+ int pos = dynamicBuffer.size;
+ dynamicBuffer.size += c - start;
+ memcpy(&dynamicBuffer[pos], output + start, c - start);
+ if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
+ // COMMENTED OUT DUE TO ISSUE #135, FIXED
+ //if(dynamicBuffer.array[dynamicBuffer.count - 1] != '\r')
+ dynamicBuffer.size++;
+ dynamicBuffer[dynamicBuffer.count - 1] = '\0';
+#ifdef _DEBUG
+ // printf("%s\n", dynamicBuffer.array);
+#endif
+ if(strstr(&dynamicBuffer[0], "vgdb me"))
+ debugger.serialSemaphore.Release();
+ {
+ char * msg = strstr(&dynamicBuffer[0], "==");
+ if(msg)
+ msg = strstr(msg+2, "== ");
+ if(msg)
+ {
+ msg += 3;
+ switch(msg[0])
+ {
+ case '(':
+ msg = strstr(msg, "(action ");
+ if(msg)
+ {
+ msg += 8;
+ if(!strstr(msg, "at startup) vgdb me ...") || !strstr(msg, "on error) vgdb me ..."))
+ msg = null;
+ }
+ break;
+ case 'T':
+ if(!strstr(msg, "TO DEBUG THIS PROCESS USING GDB: start GDB like this"))
+ msg = null;
+ break;
+ case 'a':
+ if(!strstr(msg, "and then give GDB the following command"))
+ msg = null;
+ break;
+ case ' ':
+ if(!strstr(msg, "/path/to/gdb") && !strstr(msg, "target remote | /usr/lib/valgrind/../../bin/vgdb --pid="))
+ msg = null;
+ break;
+ case '-':
+ if(!strstr(msg, "--pid is optional if only one valgrind process is running"))
+ msg = null;
+ break;
+ default:
+ msg = null;
+ break;
+ }
+ }
+ if(!msg)
+ ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
+ }
+ dynamicBuffer.size = 0;
+ start = c + 1;
+ }
+ }
+ if(c == result)
+ {
+ int pos = dynamicBuffer.size;
+ dynamicBuffer.size += c - start;
+ memcpy(&dynamicBuffer[pos], output + start, c - start);
+ }
+ }
+ else if(debugger.state == stopped)
+ {
+/*#ifdef _DEBUG
+ printf("Got end of file from GDB!\n");
+#endif*/
+ app.Unlock();
+ Sleep(0.2);
+ app.Lock();
+ }
+ }
+ delete dynamicBuffer;
+ ide.outputView.debugBox.Logf($"ValgrindLogThreadExit\n");
+ //if(oldValgrindHandle == vgLogFile)
+ debugger.GdbThreadExit/*ValgrindLogThreadExit*/();
+ delete oldValgrindHandle;
+ app.Unlock();
+ return 0;
+ }
+}
+
+class ValgrindTargetThread : Thread
+{
+ Debugger debugger;
+
+ unsigned int Main()
+ {
+ static char output[4096];
+ Array<char> dynamicBuffer { minAllocSize = 4096 };
+ DualPipe oldValgrindHandle = vgTargetHandle;
+ incref oldValgrindHandle;
+
+ app.Lock();
+ while(debugger.state != terminated && vgTargetHandle && !vgTargetHandle.Eof())
+ {
+ int result;
+ app.Unlock();
+ result = vgTargetHandle.Read(output, 1, sizeof(output));
+ app.Lock();
+ if(debugger.state == terminated || !vgTargetHandle || vgTargetHandle.Eof())
+ break;
+ if(result)
+ {
+ int c;
+ int start = 0;
+
+ for(c = 0; c<result; c++)
+ {
+ if(output[c] == '\n')
+ {
+ int pos = dynamicBuffer.size;
+ dynamicBuffer.size += c - start;
+ memcpy(&dynamicBuffer[pos], output + start, c - start);
+ if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
+ // COMMENTED OUT DUE TO ISSUE #135, FIXED
+ //if(dynamicBuffer.array[dynamicBuffer.count - 1] != '\r')
+ dynamicBuffer.size++;
+ dynamicBuffer[dynamicBuffer.count - 1] = '\0';
+#ifdef _DEBUG
+ // printf("%s\n", dynamicBuffer.array);
+#endif
+ ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
+
+ dynamicBuffer.size = 0;
+ start = c + 1;
+ }
+ }
+ if(c == result)
+ {
+ int pos = dynamicBuffer.size;
+ dynamicBuffer.size += c - start;
+ memcpy(&dynamicBuffer[pos], output + start, c - start);
+ }
+ }
+ else
+ {
+#ifdef _DEBUG
+ printf("Got end of file from GDB!\n");
+#endif
+ }
+ }
+ delete dynamicBuffer;
+ //if(oldValgrindHandle == vgTargetHandle)
+ debugger.ValgrindTargetThreadExit();
+ delete oldValgrindHandle;
+ app.Unlock();
+ return 0;
+ }
+}
+
class GdbThread : Thread
{
Debugger debugger;
dynamicBuffer.size++;
dynamicBuffer[dynamicBuffer.count - 1] = '\0';
#ifdef _DEBUG
- // printf("%s\n", dynamicBuffer.array);
+ // _dpl(0, dynamicBuffer.array);
#endif
debugger.GdbThreadMain(&dynamicBuffer[0]);
dynamicBuffer.size = 0;
else
{
#ifdef _DEBUG
- printf("Got end of file from GDB!\n");
+ _dpl(0, "Got end of file from GDB!");
#endif
}
}
}
else
{
-#ifdef BSD
- // TODO: Fix on BSD
- fd = 0;
-#else
- fd = fileno(fifoFile.input);
-#endif
+ fd = fileno((FILE *)fifoFile.input);
//fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
}
}
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)
{
Argument prev, next;
char * name;
- char * value;
+ property char * name { set { delete name; if(value) name = CopyString(value); } }
+ char * val;
+ property char * val { set { delete val; if(value) val = CopyString(value); } }
void Free()
{
delete name;
- delete value;
+ delete val;
}
~Argument()
Frame prev, next;
int level;
char * addr;
+ property char * addr { set { delete addr; if(value) addr = CopyString(value); } }
char * func;
+ property char * func { set { delete func; if(value) func = CopyString(value); } }
int argsCount;
OldList args;
char * from;
char * file;
property char * file { set { delete file; if(value) file = CopyUnescapedUnixPath(value); } }
char * absoluteFile;
+ property char * absoluteFile { set { delete absoluteFile; if(value) absoluteFile = CopyUnescapedUnixPath(value); } }
int line;
void Free()
class GdbDataStop : struct
{
- char * reason;
+ DebuggerReason reason;
int threadid;
union
{
{
if(reason)
{
- if(!strcmp(reason, "signal-received"))
+ if(reason == signalReceived)
{
delete name;
delete meaning;
}
- else if(!strcmp(reason, "function-finished"))
+ else if(reason == functionFinished)
{
delete gdbResultVar;
delete returnValue;
}
- delete reason;
}
if(frame) frame.Free();
}
class GdbDataBreakpoint : struct
{
- int number;
+ int id;
+ char * number;
+ property char * number { set { delete number; if(value) number = CopyString(value); } }
char * type;
+ property char * type { set { delete type; if(value) type = CopyString(value); } }
char * disp;
+ property char * disp { set { delete disp; if(value) disp = CopyString(value); } }
bool enabled;
char * addr;
+ property char * addr { set { delete addr; if(value) addr = CopyString(value); } }
char * func;
+ property char * func { set { delete func; if(value) func = CopyString(value); } }
char * file;
property char * file { set { delete file; if(value) file = CopyUnescapedUnixPath(value); } }
+ char * fullname;
+ property char * fullname { set { delete fullname; if(value) fullname = CopyUnescapedUnixPath(value); } }
int line;
char * at;
+ property char * at { set { delete at; if(value) at = CopyString(value); } }
int times;
+ Array<GdbDataBreakpoint> multipleBPs;
+
+ void Print()
+ {
+ _dpl(0, "");
+ PrintLn("{", "#", number, " T", type, " D", disp, " E", enabled, " H", times, " (", func, ") (", file, ":", line, ") (", fullname, ") (", addr, ") (", at, ")", "}");
+ }
+
void Free()
{
delete type;
delete func;
delete file;
delete at;
+ if(multipleBPs) multipleBPs.Free();
+ delete multipleBPs;
+ delete number;
+ delete fullname;
}
~GdbDataBreakpoint()
{
class_no_expansion;
+ char * function;
+ property char * function { set { delete function; if(value) function = CopyString(value); } }
char * relativeFilePath;
+ property char * relativeFilePath { set { delete relativeFilePath; if(value) relativeFilePath = CopyString(value); } }
char * absoluteFilePath;
+ property char * absoluteFilePath { set { delete absoluteFilePath; if(value) absoluteFilePath = CopyString(value); } }
+ char * location;
+ property char * location { set { delete location; if(value) location = CopyString(value); } }
int line;
bool enabled;
int hits;
bool inserted;
BreakpointType type;
DataRow row;
-
GdbDataBreakpoint bp;
+ Project project;
+ char * address;
+ property char * address { set { delete address; if(value) address = CopyString(value); } }
- char * LocationToString()
+ void ParseLocation()
{
- char location[MAX_LOCATION+20];
- sprintf(location, "%s:%d", relativeFilePath, line);
-#if defined(__WIN32__)
- ChangeCh(location, '/', '\\');
-#endif
- return CopyString(location);
+ char * prjName = null;
+ char * filePath = null;
+ char * file;
+ char * line;
+ char fullPath[MAX_LOCATION];
+ if(location[0] == '(' && location[1] && (file = strchr(location+2, ')')) && file[1])
+ {
+ prjName = new char[file-location];
+ strncpy(prjName, location+1, file-location-1);
+ prjName[file-location-1] = '\0';
+ file++;
+ }
+ else
+ file = location;
+ if((line = strchr(file+1, ':')))
+ {
+ filePath = new char[strlen(file)+1];
+ strncpy(filePath, file, line-file);
+ filePath[line-file] = '\0';
+ line++;
+ }
+ else
+ filePath = CopyString(file);
+ property::relativeFilePath = filePath;
+ if(prjName)
+ {
+ for(prj : ide.workspace.projects)
+ {
+ if(!strcmp(prjName, prj.name))
+ {
+ if(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
+ {
+ property::absoluteFilePath = fullPath;
+ project = prj;
+ break;
+ }
+ }
+ }
+ if(line[0])
+ this.line = atoi(line);
+ }
+ else
+ {
+ Project prj = ide.project;
+ if(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
+ {
+ property::absoluteFilePath = fullPath;
+ project = prj;
+ }
+ }
+ if(!absoluteFilePath)
+ property::absoluteFilePath = "";
+ delete prjName;
+ delete filePath;
+ }
+
+ char * CopyLocationString(bool removePath)
+ {
+ char * location;
+ char * file = relativeFilePath ? relativeFilePath : absoluteFilePath;
+ bool removingPath = removePath && file;
+ if(removingPath)
+ {
+ char * fileName = new char[MAX_FILENAME];
+ GetLastDirectory(file, fileName);
+ file = fileName;
+ }
+ if(function)
+ {
+ if(file)
+ location = PrintString(file, ":", function);
+ else
+ location = CopyString(function);
+ }
+ else
+ location = PrintString(file, ":", line);
+ if(removingPath)
+ delete file;
+ return location;
+ }
+
+ char * CopyUserLocationString()
+ {
+ char * location;
+ char * loc = CopyLocationString(false);
+ Project prj = null;
+ if(absoluteFilePath)
+ {
+ for(p : ide.workspace.projects; p != ide.workspace.projects.firstIterator.data)
+ {
+ if(p.topNode.FindByFullPath(absoluteFilePath, false))
+ {
+ prj = p;
+ break;
+ }
+ }
+ }
+ if(prj)
+ {
+ location = PrintString("(", prj.name, ")", loc);
+ delete loc;
+ }
+ else
+ location = loc;
+ return location;
}
void Save(File f)
{
if(relativeFilePath && relativeFilePath[0])
{
- f.Printf(" * %d,%d,%d,%d,%s\n", enabled ? 1 : 0, ignore, level, line, relativeFilePath);
+ char * location = CopyUserLocationString();
+ f.Printf(" * %d,%d,%d,%d,%s\n", enabled ? 1 : 0, ignore, level, line, location);
+ delete location;
if(condition)
f.Printf(" ~ %s\n", condition.expression);
}
void Free()
{
+ Reset();
+ delete function;
+ delete relativeFilePath;
+ delete absoluteFilePath;
+ delete location;
+ }
+
+ void Reset()
+ {
+ inserted = false;
+ delete address;
if(bp)
bp.Free();
delete bp;
- delete relativeFilePath;
- delete absoluteFilePath;
}
~Breakpoint()
class Watch : struct
{
class_no_expansion;
-
+
Type type;
char * expression;
char * value;
bool active;
char * result;
int bytes;
- uint nextBlockAddress;
+ uint64 nextBlockAddress;
DebuggerEvaluationError error;
};
Free();
}
}
+
+void GDBFallBack(Expression exp, String expString)
+{
+ char * result;
+ ExpressionType evalError = dummyExp;
+ result = Debugger::EvaluateExpression(expString, &evalError);
+ if(result)
+ {
+ exp.constant = result;
+ exp.type = constantExp;
+ }
+}
+
+static Project WorkspaceGetFileOwner(char * absolutePath)
+{
+ Project owner = null;
+ for(prj : ide.workspace.projects)
+ {
+ if(prj.topNode.FindByFullPath(absolutePath, false))
+ {
+ owner = prj;
+ break;
+ }
+ }
+ if(!owner)
+ WorkspaceGetObjectFileNode(absolutePath, &owner);
+ return owner;
+}
+
+static ProjectNode WorkspaceGetObjectFileNode(char * filePath, Project * project)
+{
+ ProjectNode node = null;
+ char ext[MAX_EXTENSION];
+ GetExtension(filePath, ext);
+ if(ext[0])
+ {
+ IntermediateFileType type = IntermediateFileType::FromExtension(ext);
+ if(type)
+ {
+ char fileName[MAX_FILENAME];
+ GetLastDirectory(filePath, fileName);
+ if(fileName[0])
+ {
+ DotMain dotMain = DotMain::FromFileName(fileName);
+ for(prj : ide.workspace.projects)
+ {
+ if((node = prj.FindNodeByObjectFileName(fileName, type, dotMain, null)))
+ {
+ if(project)
+ *project = prj;
+ break;
+ }
+ }
+ }
+ }
+ }
+ return node;
+}
+
+static ProjectNode ProjectGetObjectFileNode(Project project, char * filePath)
+{
+ ProjectNode node = null;
+ char ext[MAX_EXTENSION];
+ GetExtension(filePath, ext);
+ if(ext[0])
+ {
+ IntermediateFileType type = IntermediateFileType::FromExtension(ext);
+ if(type)
+ {
+ char fileName[MAX_FILENAME];
+ GetLastDirectory(filePath, fileName);
+ if(fileName[0])
+ {
+ DotMain dotMain = DotMain::FromFileName(fileName);
+ node = project.FindNodeByObjectFileName(fileName, type, dotMain, null);
+ }
+ }
+ }
+ return node;
+}
+
+static void WorkspaceGetRelativePath(char * absolutePath, char * relativePath, Project * owner)
+{
+ Project prj = WorkspaceGetFileOwner(absolutePath);
+ if(owner)
+ *owner = prj;
+ if(!prj)
+ prj = ide.workspace.projects.firstIterator.data;
+ if(prj)
+ {
+ MakePathRelative(absolutePath, prj.topNode.path, relativePath);
+ MakeSlashPath(relativePath);
+ }
+ else
+ relativePath[0] = '\0';
+}
+
+static bool ProjectGetAbsoluteFromRelativePath(Project project, char * relativePath, char * absolutePath)
+{
+ ProjectNode node = project.topNode.FindWithPath(relativePath, false);
+ if(!node)
+ node = ProjectGetObjectFileNode(project, relativePath);
+ if(node)
+ {
+ strcpy(absolutePath, node.project.topNode.path);
+ PathCat(absolutePath, relativePath);
+ MakeSlashPath(absolutePath);
+ }
+ return node != null;
+}