2 public import static "ecere"
3 public import static "ec"
15 #define GDB_DEBUG_CONSOLE
19 extern char * strrchr(const char * s, int c);
22 #define strlen _strlen
33 #include <sys/time.h> // Required on Apple...
47 sprintf(s[0], "%04d", now.year);
48 sprintf(s[1], "%02d", now.month+1);
49 sprintf(s[2], "%02d", now.day);
50 sprintf(s[3], "%02d", now.hour);
51 sprintf(s[4], "%02d", now.minute);
52 sprintf(s[5], "%02d", now.second);
53 time = PrintString("*", s[0], s[1], s[2], "-", s[3], s[4], s[5], "*");
59 // use =0 to disable printing of specific channels
61 static enum dplchan { none, gdbProtoIgnored=0/*1*/, gdbProtoUnknown=2, gdbOutput=3/*3*/, gdbCommand=4/*4*/, debuggerCall=0/*5*/, debuggerProblem=6,
62 debuggerUserAction=7,debuggerState=8, debuggerBreakpoints=9, debuggerWatches=0/*10*/, debuggerTemp=0 };
64 static enum dplchan { none, gdbProtoIgnored=0, gdbProtoUnknown=0, gdbOutput=0, gdbCommand=0, debuggerCall=0, debuggerProblem=0,
65 debuggerUserAction=0,debuggerState=0, debuggerBreakpoints=0, debuggerWatches=0, debuggerTemp=0 };
67 static char * _dpct[] = {
69 "GDB Protocol Ignored",
70 "GDB Protocol ***Unknown***",
74 "Debugger ***Problem***",
75 "Debugger::ChangeUserAction",
76 "Debugger::ChangeState",
79 "-----> Temporary Message",
83 // TODO if(strlen(item.value) < MAX_F_STRING)
87 #define _dpl2(...) __dpl2(__FILE__, __LINE__, ##__VA_ARGS__)
91 static void __dpl2(char * file, int line, char ** channels, int channel, int indent, typed_object object, ...)
93 bool chan = channel && channels && channels[channel];
96 char string[MAX_F_STRING];
98 char * time = PrintNow();
100 //ide.outputView.debugBox.Logf();
101 Logf("%s %s:% 5d: %s%s", time, file, line, chan ? channels[channel] : "", chan && channels[channel][0] ? ": " : "");
102 va_start(args, object);
103 len = PrintStdArgsToBuffer(string, sizeof(string), object, args);
111 #define _dpl(...) __dpl(__FILE__, __LINE__, ##__VA_ARGS__)
112 static void __dpl(char * file, int line, int indent, char * format, ...)
115 char string[MAX_F_STRING];
117 char * time = PrintNow();
118 //static File f = null;
119 va_start(args, format);
120 vsnprintf(string, sizeof(string), format, args);
121 string[sizeof(string)-1] = 0;
124 char * time = PrintNow();
126 logName = PrintString(time, ".log");
128 f = FileOpen(logName, write);
131 /*f.Printf("%s %s:% 5d: ", time, file, line);
132 for(c = 0; c<indent; c++)
134 f.Printf("%s\n", string);*/
135 Logf("%s %s:% 5d: ", time, file, line);
136 for(c = 0; c<indent; c++)
138 Logf("%s\n", string);
143 public char * StripQuotes2(char * string, char * output)
147 bool quoted = false, escaped = false;
149 for(c = 0; ch = string[c]; c++)
153 if(escaped || ch != '\"')
156 escaped = !escaped && ch == '\\';
170 // String Escape Copy
171 static void strescpy(char * d, char * s)
179 case '\n': d[k] = '\\'; d[++k] = 'n'; break;
180 case '\t': d[k] = '\\'; d[++k] = 't'; break;
181 case '\a': d[k] = '\\'; d[++k] = 'a'; break;
182 case '\b': d[k] = '\\'; d[++k] = 'b'; break;
183 case '\f': d[k] = '\\'; d[++k] = 'f'; break;
184 case '\r': d[k] = '\\'; d[++k] = 'r'; break;
185 case '\v': d[k] = '\\'; d[++k] = 'v'; break;
186 case '\\': d[k] = '\\'; d[++k] = '\\'; break;
187 case '\"': d[k] = '\\'; d[++k] = '\"'; break;
188 default: d[k] = s[j];
195 static char * CopyUnescapedSystemPath(char * p)
197 char * d = new char[strlen(p) + 1];
199 #if defined(__WIN32__)
200 ChangeCh(d, '/', '\\');
205 static char * CopyUnescapedUnixPath(char * p)
207 char * d = new char[strlen(p) + 1];
209 #if defined(__WIN32__)
210 ChangeCh(d, '\\', '/');
215 static char * CopyUnescapedString(char * s)
217 char * d = new char[strlen(s) + 1];
222 // String Unescape Copy
224 // TOFIX: THIS DOESN'T HANDLE NUMERIC ESCAPE CODES (OCTAL/HEXADECIMAL...)?
225 // Seems very similar to ReadString in pass15.ec (which also misses numeric escape codes :) )
227 static void struscpy(char * d, char * s)
238 case 'n': d[k] = '\n'; break;
239 case 't': d[k] = '\t'; break;
240 case 'a': d[k] = '\a'; break;
241 case 'b': d[k] = '\b'; break;
242 case 'f': d[k] = '\f'; break;
243 case 'r': d[k] = '\r'; break;
244 case 'v': d[k] = '\v'; break;
245 case '\\': d[k] = '\\'; break;
246 case '\"': d[k] = '\"'; break;
247 default: d[k] = '\\'; d[++k] = s[j];
258 static char * StripBrackets(char * string)
260 int length = strlen(string);
261 if(length > 1 && *string == '[' && string[length - 1] == ']')
264 string[length - 1] = '\0';
271 static char * StripCurlies(char * string)
273 int length = strlen(string);
274 if(length > 1 && *string == '{' && string[length - 1] == '}')
277 string[length - 1] = '\0';
284 static int StringGetInt(char * string, int start)
287 int i, len = strlen(string);
289 for(i = start; i < len && i < start + 8; i++)
291 if(string[i] == '0' || string[i] == '1' || string[i] == '2' || string[i] == '3' || string[i] == '4' || string[i] == '5' || string[i] == '6' || string[i] == '7' || string[i] == '8' || string[i] == '9')
292 strncat(number, &string[i], 1);
299 static int TokenizeList(char * string, const char seperator, Array<char *> tokens)
303 bool quoted = false, escaped = false;
304 char * start = string, ch;
306 for(; (ch = *string); string++)
313 if(escaped || ch != '\"')
314 escaped = !escaped && ch == '\\';
320 else if(ch == '{' || ch == '[' || ch == '(' || ch == '<')
322 else if(ch == '}' || ch == ']' || ch == ')' || ch == '>')
324 else if(ch == seperator && !level)
333 //tokens[count] = start;
334 //tokens[count++] = start;
341 static bool TokenizeListItem(char * string, DebugListItem item)
343 char * equal = strstr(string, "=");
355 static bool CheckCommandAvailable(const char * command)
357 bool available = false;
359 char * name = new char[MAX_FILENAME];
360 char * pathVar = new char[maxPathLen];
362 GetEnvironment("PATH", pathVar, maxPathLen);
363 count = TokenizeWith(pathVar, sizeof(paths) / sizeof(char *), paths, pathListSep, false);
364 strcpy(name, command);
368 const char * extensions[] = { "exe", "com", "bat", null };
369 for(e=0; extensions[e]; e++)
371 ChangeExtension(name, extensions[e], name);
373 for(c=0; c<count; c++)
375 FileListing fl { paths[c] };
378 if(fl.stats.attribs.isFile && !fstrcmp(fl.name, name))
397 // define GdbGetLineSize = 1638400;
398 define GdbGetLineSize = 5638400;
399 #if defined(__unix__)
400 char progFifoPath[MAX_LOCATION];
401 char progFifoDir[MAX_LOCATION];
404 enum DebuggerState { none, prompt, loaded, running, stopped, terminated, error };
407 none, hit, breakEvent, signal, stepEnd, functionEnd, exit, valgrindStartPause, locationReached;
409 property bool canBeMonitored { get { return (this == hit || this == breakEvent || this == signal || this == stepEnd || this == functionEnd || this == locationReached); } };
411 enum DebuggerAction { none, internal, restart, stop, selectFrame, advance }; //, bpValidation
414 unknown, endSteppingRange, functionFinished, signalReceived, breakpointHit, locationReached
415 //watchpointTrigger, readWatchpointTrigger, accessWatchpointTrigger, watchpointScope,
416 //exited, exitedNormally, exitedSignalled;
420 none, internalMain, internalWinMain, internalModulesLoaded, user, runToCursor, internalModuleLoad, internalEntry;
422 property bool isInternal { get { return (this == internalMain || this == internalWinMain || this == internalModulesLoaded || this == internalModuleLoad || this == internalEntry); } };
423 property bool isUser { get { return (this == user || this == runToCursor); } };
425 enum DebuggerEvaluationError { none, symbolNotFound, memoryCantBeRead, unknown };
426 enum DebuggerUserAction
428 none, start, resume, _break, stop, restart, selectThread, selectFrame, stepInto, stepOver, stepUntil, stepOut, runToCursor;
429 property bool breaksOnInternalBreakpoint { get { return (this == stepInto || this == stepOver || this == stepUntil); } };
433 none, run, _continue, next, until, advance, step, finish;
434 property bool suspendInternalBreakpoints { get { return (this == until || this == advance || this == step || this == finish); } };
437 FileDialog debuggerFileDialog { type = selectDir };
439 static DualPipe vgTargetHandle;
440 static File vgLogFile;
441 static char vgLogPath[MAX_LOCATION];
442 static DualPipe gdbHandle;
443 static DebugEvaluationData eval { };
445 static int targetProcessId;
447 static bool gdbReady;
448 static bool breakpointError;
452 Semaphore serialSemaphore { };
458 bool sentBreakInsert;
459 bool ignoreBreakpoints;
467 int activeFrameLevel;
476 GdbExecution gdbExecution;
477 DebuggerUserAction userAction;
480 DebuggerAction breakType;
482 //DebuggerCommand lastCommand; // THE COMPILER COMPILES STUFF THAT DOES NOT EXIST???
484 GdbDataStop stopItem;
485 GdbDataBreakpoint bpItem;
488 List<Breakpoint> sysBPs { };
489 Breakpoint bpRunToCursor;
490 Breakpoint intBpEntry;
491 Breakpoint intBpMain;
492 Breakpoint intBpWinMain;
496 CompilerConfig currentCompiler;
497 ProjectConfig prjConfig;
500 CodeEditor codeEditor;
502 ValgrindLogThread vgLogThread { debugger = this };
503 ValgrindTargetThread vgTargetThread { debugger = this };
504 GdbThread gdbThread { debugger = this };
507 Map<String, bool> projectsLibraryLoaded { };
511 delay = 0.0, userData = this;
515 bool monitor = false;
516 DebuggerEvent curEvent = event;
517 GdbDataStop stopItem = this.stopItem;
518 Breakpoint bpUser = null;
519 Breakpoint bpInternal = null;
527 this.stopItem = null;
531 DynamicString bpReport { };
533 for(bp : sysBPs; bp.inserted)
535 bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
538 if(bpRunToCursor && bpRunToCursor.inserted)
540 Breakpoint bp = bpRunToCursor;
541 bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
544 for(bp : ide.workspace.breakpoints; bp.inserted)
546 bpReport.concatx(",", bp.type, "(", s=bp.CopyLocationString(false), ")");
550 _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "gdbTimer::DelayExpired: ", s+1);
555 Breakpoint bp = GetBreakpointById(stopItem.bkptno, &isInternal);
558 _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "gdb stopped by a breakpoint: ", bp.type, "(", s=bp.CopyLocationString(false), ")");
569 if(curEvent && curEvent != exit)
571 _dpl(0, "No stop item");
579 Restart(currentCompiler, prjConfig, bitDepth, usingValgrind);
588 GdbCommand(0, false, "-stack-select-frame %d", activeFrameLevel);
589 for(activeFrame = stackFrames.first; activeFrame; activeFrame = activeFrame.next)
590 if(activeFrame.level == activeFrameLevel)
596 // GdbCommand(0, false, "-break-info %s", bpItem.number);
608 Breakpoint bp = stopItem ? GetBreakpointById(stopItem.bkptno, &isInternal) : null;
609 if(bp && bp.inserted && bp.bp.addr)
611 if(bp.type.isInternal)
615 if(stopItem && stopItem.frame)
617 if(bpInternal && bpRunToCursor && bpRunToCursor.inserted && !strcmp(bpRunToCursor.bp.addr, bp.bp.addr))
618 bpUser = bpRunToCursor;
621 for(item : (bpInternal ? ide.workspace.breakpoints : sysBPs); item.inserted)
623 if(item.bp && item.bp.addr && !strcmp(item.bp.addr, bp.bp.addr))
635 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Invalid stopItem!");
636 if(bpUser && strcmp(stopItem.frame.addr, bpUser.bp.addr))
637 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Breakpoint bkptno(", stopItem.bkptno, ") address missmatch!");
640 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Breakpoint bkptno(", stopItem.bkptno, ") invalid or not found!");
641 if((bpUser && !ignoreBreakpoints) || (bpInternal && userAction.breaksOnInternalBreakpoint))
643 hitThread = stopItem.threadid;
647 signalThread = stopItem.threadid;
651 case locationReached:
653 ignoreBreakpoints = false;
655 case valgrindStartPause:
656 GdbExecContinue(true);
664 if(curEvent == signal)
668 ide.outputView.debugBox.Logf($"Signal received: %s - %s\n", stopItem.name, stopItem.meaning);
669 ide.outputView.debugBox.Logf(" %s:%d\n", (s = CopySystemPath(stopItem.frame.file)), stopItem.frame.line);
670 ide.outputView.Show();
671 ide.callStackView.Show();
674 else if(curEvent == breakEvent)
676 ide.threadsView.Show();
677 ide.callStackView.Show();
678 ide.callStackView.Activate();
680 else if(curEvent == hit)
682 if(BreakpointHit(stopItem, bpInternal, bpUser))
684 ide.AdjustDebugMenus();
685 if(bpUser && bpUser.type == runToCursor)
687 ignoreBreakpoints = false;
688 UnsetBreakpoint(bpUser);
689 delete bpRunToCursor;
694 if(breakType == advance && bpInternal && (bpInternal.type == internalMain || bpInternal.type == internalEntry))
697 GdbExecAdvance(breakString, 0);
702 GdbExecContinue(false);
708 if(monitor && curEvent.canBeMonitored)
711 activeThread = stopItem.threadid;
712 GdbCommand(0, false, "-thread-list-ids");
713 InternalSelectFrame(activeFrameLevel);
714 GoToStackFrameLine(activeFrameLevel, true, false);
716 ide.ShowCodeEditor();
717 ide.AdjustDebugMenus();
718 ideMainFrame.Activate(); // TOFIX: ide.Activate() is not reliable (app inactive)
731 #ifdef GDB_DEBUG_CONSOLE
732 char lastGdbOutput[GdbGetLineSize];
734 #if defined(__unix__)
735 ProgramThread progThread { };
739 #define _ChangeUserAction(value) ChangeUserAction(__FILE__, __LINE__, value)
740 void ChangeUserAction(char * file, int line, DebuggerUserAction value)
742 bool same = value == userAction;
743 __dpl2(file, line, _dpct, dplchan::debuggerUserAction, 0, userAction, /*same ? " *** == *** " : */" -> ", value);
747 #define _ChangeUserAction(value) userAction = value
751 #define _ChangeState(value) ChangeState(__FILE__, __LINE__, value)
752 void ChangeState(char * file, int line, DebuggerState value)
754 #define _ChangeState(value) ChangeState(value)
755 void ChangeState(DebuggerState value)
758 bool same = value == state;
760 __dpl2(file, line, _dpct, dplchan::debuggerState, 0, state, same ? " *** == *** " : " -> ", value);
763 if(!same) ide.AdjustDebugMenus();
768 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::CleanUp");
770 stackFrames.Free(Frame::Free);
780 waitingForPID = false;
785 sentBreakInsert = false;
786 ignoreBreakpoints = false;
789 activeFrameLevel = 0;
806 bpRunToCursor = null;
808 delete currentCompiler;
811 WatchesReleaseCodeEditor();
814 projectsLibraryLoaded.Free();
816 /*GdbThread gdbThread
822 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::constructor");
823 ideProcessId = Process_GetCurrentProcessId();
825 sysBPs.Add((intBpEntry = Breakpoint { type = internalEntry, enabled = false, level = -1 }));
826 sysBPs.Add((intBpMain = Breakpoint { type = internalMain, function = "main", enabled = true, level = -1 }));
827 #if defined(__WIN32__)
828 sysBPs.Add((intBpWinMain = Breakpoint { type = internalWinMain, function = "WinMain", enabled = true, level = -1 }));
830 sysBPs.Add(Breakpoint { type = internalModulesLoaded, enabled = true, level = -1 });
831 sysBPs.Add(Breakpoint { type = internalModuleLoad, function = "InternalModuleLoadBreakpoint", enabled = true, level = -1 });
836 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::destructor");
844 property bool isActive { get { return state == running || state == stopped; } }
845 property bool isPrepared { get { return state == loaded || state == running || state == stopped; } }
849 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Resume");
850 _ChangeUserAction(resume);
851 GdbExecContinue(true);
856 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Break");
857 _ChangeUserAction(_break);
861 GdbDebugBreak(false);
867 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Stop");
868 _ChangeUserAction(stop);
875 GdbDebugBreak(false);
889 void Restart(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
891 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Restart");
892 _ChangeUserAction(restart);
893 if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
897 bool GoToCodeLine(char * location)
900 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToCodeLine(", location, ")");
901 codloc = CodeLocation::ParseCodeLocation(location);
904 CodeEditor editor = (CodeEditor)ide.OpenFile(codloc.absoluteFile, normal, true, null, no, normal, false);
907 EditBox editBox = editor.editBox;
908 editBox.GoToLineNum(codloc.line - 1);
909 editBox.GoToPosition(editBox.line, codloc.line - 1, 0);
916 bool GoToStackFrameLine(int stackLevel, bool askForLocation, bool fromCallStack)
918 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GoToStackFrameLine(", stackLevel, ", ", askForLocation, ")");
921 char filePath[MAX_LOCATION];
922 char sourceDir[MAX_LOCATION];
924 CodeEditor editor = null;
925 if(stackLevel == -1) // this (the two lines) is part of that fix that I would not put in for some time
927 for(frame = stackFrames.first; frame; frame = frame.next)
928 if(frame.level == stackLevel)
933 ide.callStackView.Show();
935 if(frame.absoluteFile)
936 editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
937 if(!editor && frame.file)
938 frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
939 if(!frame.absoluteFile && askForLocation && frame.file)
942 char title[MAX_LOCATION];
943 snprintf(title, sizeof(title), $"Provide source file location for %s", (s = CopySystemPath(frame.file)));
944 title[sizeof(title)-1] = 0;
946 if(SourceDirDialog(title, ide.workspace.projectDir, frame.file, sourceDir))
948 AddSourceDir(sourceDir);
949 frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
952 if(!editor && frame.absoluteFile)
953 editor = (CodeEditor)ide.OpenFile(frame.absoluteFile, normal, true, null, no, normal, false);
955 ide.RepositionWindows(false);
957 if(editor && frame.line)
959 EditBox editBox = editor.editBox;
960 editBox.GoToLineNum(frame.line - 1);
961 editBox.GoToPosition(editBox.line, frame.line - 1, 0);
969 void SelectThread(int thread)
971 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectThread(", thread, ")");
972 _ChangeUserAction(selectThread);
975 if(thread != activeThread)
977 activeFrameLevel = -1;
978 ide.callStackView.Clear();
979 GdbCommand(0, false, "-thread-select %d", thread);
981 InternalSelectFrame(activeFrameLevel);
982 GoToStackFrameLine(activeFrameLevel, true, false);
986 ide.callStackView.Show();
990 void SelectFrame(int frame)
992 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SelectFrame(", frame, ")");
993 _ChangeUserAction(selectFrame);
996 if(frame != activeFrameLevel)
998 InternalSelectFrame(frame);
1005 void InternalSelectFrame(int frame)
1007 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::InternalSelectFrame(", frame, ")");
1008 activeFrameLevel = frame; // there is no active frame number in the gdb reply
1009 GdbCommand(0, false, "-stack-select-frame %d", activeFrameLevel);
1010 for(activeFrame = stackFrames.first; activeFrame; activeFrame = activeFrame.next)
1011 if(activeFrame.level == activeFrameLevel)
1015 void HandleExit(char * reason, char * code)
1017 bool returnedExitCode = false;
1018 char verboseExitCode[128];
1020 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::HandleExit(", reason, ", ", code, ")");
1021 _ChangeState(loaded); // this state change seems to be superfluous, might be in case of gdb crash
1022 targetProcessId = 0;
1026 snprintf(verboseExitCode, sizeof(verboseExitCode), $" with exit code %s", code);
1027 verboseExitCode[sizeof(verboseExitCode)-1] = 0;
1030 verboseExitCode[0] = '\0';
1034 // ClearBreakDisplay();
1038 for(wh : ide.workspace.watches)
1040 if(wh.type) FreeType(wh.type);
1043 ide.watchesView.UpdateWatch(wh);
1047 #if defined(__unix__)
1050 progThread.terminate = true;
1053 fifoFile.CloseInput();
1063 char program[MAX_LOCATION];
1064 GetSystemPathBuffer(program, targetFile);
1066 ide.outputView.debugBox.Logf($"The program %s has exited%s.\n", program, verboseExitCode);
1067 else if(!strcmp(reason, "exited-normally"))
1068 ide.outputView.debugBox.Logf($"The program %s has exited normally%s.\n", program, verboseExitCode);
1069 else if(!strcmp(reason, "exited"))
1070 ide.outputView.debugBox.Logf($"The program %s has exited%s.\n", program, verboseExitCode);
1071 else if(!strcmp(reason, "exited-signalled"))
1072 ide.outputView.debugBox.Logf($"The program %s has exited with a signal%s.\n", program, verboseExitCode);
1074 ide.outputView.debugBox.Logf($"The program %s has exited (gdb provided an unknown reason)%s.\n", program, verboseExitCode);
1079 DebuggerState StartSession(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool restart, bool ignoreBreakpoints)
1081 DebuggerState result = none;
1082 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StartSession(restart(", restart, "), ignoreBreakpoints(", ignoreBreakpoints, ")");
1083 if(restart && state == running && targetProcessId)
1085 breakType = DebuggerAction::restart;
1086 GdbDebugBreak(false);
1090 if(restart && state == stopped)
1092 if(needReset && state == loaded)
1093 GdbExit(); // this reset is to get a clean state with all the breakpoints until a better state can be maintained on program exit
1095 if(result == none || result == terminated)
1097 ide.outputView.ShowClearSelectTab(debug);
1098 ide.outputView.debugBox.Logf($"Starting debug mode\n");
1105 for(bp : ide.workspace.breakpoints)
1111 if(GdbInit(compiler, config, bitDepth, useValgrind))
1116 this.ignoreBreakpoints = ignoreBreakpoints;
1121 void Start(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
1123 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::Start()");
1124 _ChangeUserAction(start);
1125 if(StartSession(compiler, config, bitDepth, useValgrind, true, false) == loaded)
1129 void StepInto(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
1131 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepInto()");
1132 _ChangeUserAction(stepInto);
1133 switch(StartSession(compiler, config, bitDepth, useValgrind, false, false))
1135 case loaded: GdbExecRun(); break;
1136 case stopped: GdbExecStep(); break;
1140 void StepOver(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
1142 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOver()");
1143 _ChangeUserAction(stepOver);
1144 switch(StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints))
1146 case loaded: GdbExecRun(); break;
1147 case stopped: GdbExecNext(); break;
1151 void StepUntil(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, bool ignoreBreakpoints)
1153 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepUntil()");
1154 _ChangeUserAction(stepUntil);
1155 switch(StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints))
1157 case loaded: GdbExecRun(); break;
1158 case stopped: GdbExecUntil(null, 0); break;
1162 void StepOut(bool ignoreBreakpoints)
1164 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::StepOut()");
1165 _ChangeUserAction(stepOut);
1166 if(state == stopped)
1168 this.ignoreBreakpoints = ignoreBreakpoints;
1172 GdbExecContinue(true);
1176 void RunToCursor(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind, char * absoluteFilePath, int lineNumber, bool ignoreBreakpoints, bool atSameLevel, bool oldImplementation)
1178 char relativeFilePath[MAX_LOCATION];
1179 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::RunToCursor()");
1180 _ChangeUserAction(runToCursor);
1181 WorkspaceGetRelativePath(absoluteFilePath, relativeFilePath, null);
1183 if(bpRunToCursor && bpRunToCursor.inserted && symbols)
1185 UnsetBreakpoint(bpRunToCursor);
1186 delete bpRunToCursor;
1189 StartSession(compiler, config, bitDepth, useValgrind, false, ignoreBreakpoints);
1192 if(oldImplementation)
1194 bpRunToCursor = Breakpoint { };
1195 bpRunToCursor.absoluteFilePath = absoluteFilePath;
1196 bpRunToCursor.relativeFilePath = relativeFilePath;
1197 bpRunToCursor.line = lineNumber;
1198 bpRunToCursor.type = runToCursor;
1199 bpRunToCursor.enabled = true;
1200 bpRunToCursor.level = atSameLevel ? frameCount - activeFrameLevel -1 : -1;
1205 breakType = advance;
1206 breakString = PrintString(relativeFilePath, ":", lineNumber);
1209 else if(state == stopped)
1211 if(oldImplementation)
1212 GdbExecContinue(true);
1216 GdbExecUntil(absoluteFilePath, lineNumber);
1218 GdbExecAdvance(absoluteFilePath, lineNumber);
1223 void GetCallStackCursorLine(bool * error, int * lineCursor, int * lineTopFrame)
1225 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetCallStackCursorLine()");
1226 if(activeFrameLevel == -1)
1234 *error = signalOn && activeThread == signalThread;
1235 *lineCursor = activeFrameLevel - ((frameCount > 192 && activeFrameLevel > 191) ? frameCount - 192 - 1 : 0) + 1;
1236 *lineTopFrame = activeFrameLevel ? 1 : 0;
1240 int GetMarginIconsLineNumbers(char * fileName, int lines[], bool enabled[], int max, bool * error, int * lineCursor, int * lineTopFrame)
1242 char winFilePath[MAX_LOCATION];
1243 char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
1245 Iterator<Breakpoint> it { ide.workspace.breakpoints };
1246 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GetMarginIconsLineNumbers()");
1247 while(it.Next() && count < max)
1249 Breakpoint bp = it.data;
1252 if(bp.absoluteFilePath && bp.absoluteFilePath[0] && !fstrcmp(bp.absoluteFilePath, absoluteFilePath))
1254 lines[count] = bp.line;
1255 enabled[count] = bp.enabled;
1260 if(activeFrameLevel == -1)
1268 *error = signalOn && activeThread == signalThread;
1269 if(activeFrame && activeFrame.absoluteFile && !fstrcmp(absoluteFilePath, activeFrame.absoluteFile))
1270 *lineCursor = activeFrame.line;
1273 if(activeFrame && stopItem && stopItem.frame && activeFrame.level == stopItem.frame.level)
1275 else if(stopItem && stopItem.frame && stopItem.frame.absoluteFile && !fstrcmp(absoluteFilePath, stopItem.frame.absoluteFile))
1276 *lineTopFrame = stopItem.frame.line;
1280 if(*lineTopFrame == *lineCursor && *lineTopFrame)
1286 void ChangeWatch(DataRow row, char * expression)
1288 Watch wh = (Watch)row.tag;
1289 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ChangeWatch(", expression, ")");
1292 delete wh.expression;
1294 wh.expression = CopyString(expression);
1297 Iterator<Watch> it { ide.workspace.watches };
1299 ide.workspace.watches.Delete(it.pointer);
1305 row.tag = (int64)wh;
1306 ide.workspace.watches.Add(wh);
1308 wh.expression = CopyString(expression);
1310 ide.workspace.Save();
1311 //if(expression && state == stopped)
1316 void MoveIcons(char * fileName, int lineNumber, int move, bool start)
1318 char winFilePath[MAX_LOCATION];
1319 char * absoluteFilePath = GetSlashPathBuffer(winFilePath, fileName);
1322 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::MoveIcons()");
1323 for(bpLink = ide.workspace.breakpoints.first; bpLink; bpLink = next)
1325 Breakpoint bp = (Breakpoint)bpLink.data;
1328 if(bp.type == user && bp.absoluteFilePath && !fstrcmp(bp.absoluteFilePath, absoluteFilePath))
1330 if(bp.line > lineNumber || (bp.line == lineNumber && start))
1332 if(move < 0 && (bp.line < lineNumber - move))
1333 ide.workspace.RemoveBreakpoint(bp);
1337 ide.breakpointsView.UpdateBreakpoint(bp.row);
1338 ide.workspace.Save();
1344 // moving code cursors is futile, on next step, stop, hit, cursors will be offset anyways
1347 bool SourceDirDialog(char * title, char * startDir, char * test, char * sourceDir)
1351 String srcDir = null;
1353 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SourceDirDialog()");
1354 debuggerFileDialog.text = title;
1355 debuggerFileDialog.currentDirectory = startDir;
1356 debuggerFileDialog.master = ide;
1358 while(debuggerFileDialog.Modal())
1360 strcpy(sourceDir, debuggerFileDialog.filePath);
1361 if(!fstrcmp(ide.workspace.projectDir, sourceDir) &&
1362 MessageBox { type = yesNo, master = ide,
1363 contents = $"This is the project directory.\nWould you like to try again?",
1364 text = $"Invalid Source Directory" }.Modal() == no)
1368 for(dir : ide.workspace.sourceDirs)
1370 if(!fstrcmp(dir, sourceDir))
1378 MessageBox { type = yesNo, master = ide,
1379 contents = $"This source directory is already specified.\nWould you like to try again?",
1380 text = $"Invalid Source Directory" }.Modal() == no)
1386 char file[MAX_LOCATION];
1387 strcpy(file, sourceDir);
1388 PathCat(file, test);
1389 result = FileExists(file);
1391 MessageBox { type = yesNo, master = ide,
1392 contents = $"Unable to locate source file.\nWould you like to try again?",
1393 text = $"Invalid Source Directory" }.Modal() == no)
1407 void AddSourceDir(char * sourceDir)
1409 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::AddSourceDir(", sourceDir, ")");
1410 ide.workspace.sourceDirs.Add(CopyString(sourceDir));
1411 ide.workspace.Save();
1415 DebuggerState oldState = state;
1420 GdbDebugBreak(true);
1423 GdbCommand(0, false, "-environment-directory \"%s\"", sourceDir);
1426 if(oldState == running)
1427 GdbExecContinue(false);
1431 void ToggleBreakpoint(char * fileName, int lineNumber)
1433 char absolutePath[MAX_LOCATION];
1434 Breakpoint bp = null;
1436 _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::ToggleBreakpoint(", fileName, ":", lineNumber, ")");
1438 GetSlashPathBuffer(absolutePath, fileName);
1439 for(i : ide.workspace.breakpoints; i.type == user && i.absoluteFilePath && !fstrcmp(i.absoluteFilePath, absolutePath) && i.line == lineNumber)
1448 ide.workspace.RemoveBreakpoint(bp);
1457 char relativePath[MAX_LOCATION];
1459 WorkspaceGetRelativePath(absolutePath, relativePath, &owner);
1461 if(!owner && !FileExists(absolutePath))
1463 char title[MAX_LOCATION];
1464 char directory[MAX_LOCATION];
1465 char sourceDir[MAX_LOCATION];
1466 StripLastDirectory(absolutePath, directory);
1467 snprintf(title, sizeof(title), $"Provide source files location directory for %s", relativePath);
1468 title[sizeof(title)-1] = 0;
1471 String srcDir = null;
1472 for(dir : ide.workspace.sourceDirs)
1474 if(IsPathInsideOf(absolutePath, dir))
1476 MakePathRelative(absolutePath, dir, relativePath);
1484 if(SourceDirDialog(title, directory, null, sourceDir))
1486 if(IsPathInsideOf(absolutePath, sourceDir))
1488 AddSourceDir(sourceDir);
1489 MakePathRelative(absolutePath, sourceDir, relativePath);
1492 else if(MessageBox { type = yesNo, master = ide,
1493 contents = $"You must provide a valid source directory in order to place a breakpoint in this file.\nWould you like to try again?",
1494 text = $"Invalid Source Directory" }.Modal() == no)
1501 ide.workspace.bpCount++;
1502 bp = { line = lineNumber, type = user, enabled = true, level = -1, project = owner };
1503 ide.workspace.breakpoints.Add(bp);
1504 bp.absoluteFilePath = absolutePath;
1505 bp.relativeFilePath = relativePath;
1506 ide.breakpointsView.AddBreakpoint(bp);
1511 DebuggerState oldState = state;
1516 GdbDebugBreak(true);
1519 SetBreakpoint(bp, false);
1522 if(oldState == running)
1523 GdbExecContinue(false);
1526 ide.workspace.Save();
1529 void UpdateRemovedBreakpoint(Breakpoint bp)
1531 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::UpdateRemovedBreakpoint()");
1532 if(targeted && bp.inserted)
1534 DebuggerState oldState = state;
1539 GdbDebugBreak(true);
1542 UnsetBreakpoint(bp);
1545 if(oldState == running)
1546 GdbExecContinue(false);
1552 void ParseFrame(Frame frame, char * string)
1555 Array<char *> frameTokens { minAllocSize = 50 };
1556 Array<char *> argsTokens { minAllocSize = 50 };
1557 Array<char *> argumentTokens { minAllocSize = 50 };
1558 DebugListItem item { };
1561 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
1562 TokenizeList(string, ',', frameTokens);
1563 for(i = 0; i < frameTokens.count; i++)
1565 if(TokenizeListItem(frameTokens[i], item))
1567 StripQuotes(item.value, item.value);
1568 if(!strcmp(item.name, "level"))
1569 frame.level = atoi(item.value);
1570 else if(!strcmp(item.name, "addr"))
1571 frame.addr = item.value;
1572 else if(!strcmp(item.name, "func"))
1573 frame.func = item.value;
1574 else if(!strcmp(item.name, "args"))
1576 if(!strcmp(item.value, "[]"))
1577 frame.argsCount = 0;
1580 item.value = StripBrackets(item.value);
1581 TokenizeList(item.value, ',', argsTokens);
1582 for(j = 0; j < argsTokens.count; j++)
1584 argsTokens[j] = StripCurlies(argsTokens[j]);
1585 TokenizeList(argsTokens[j], ',', argumentTokens);
1586 for(k = 0; k < argumentTokens.count; k++)
1589 frame.args.Add(arg);
1590 if(TokenizeListItem(argumentTokens[k], item))
1592 if(!strcmp(item.name, "name"))
1594 StripQuotes(item.value, item.value);
1595 arg.name = item.value;
1597 else if(!strcmp(item.name, "value"))
1599 StripQuotes(item.value, item.value);
1600 arg.val = item.value;
1603 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame args item (", item.name, "=", item.value, ") is unheard of");
1606 _dpl(0, "Bad frame args item");
1608 argumentTokens.RemoveAll();
1610 frame.argsCount = argsTokens.count;
1611 argsTokens.RemoveAll();
1614 else if(!strcmp(item.name, "from"))
1615 frame.from = item.value;
1616 else if(!strcmp(item.name, "file"))
1617 frame.file = item.value;
1618 else if(!strcmp(item.name, "line"))
1619 frame.line = atoi(item.value);
1620 else if(!strcmp(item.name, "fullname"))
1621 frame.absoluteFile = item.value;
1623 // GDB 6.3 on OS X is giving "fullname" and "dir", all in absolute, but file name only in 'file'
1624 String path = ide.workspace.GetPathWorkspaceRelativeOrAbsolute(item.value);
1625 if(strcmp(frame.file, path))
1628 frame.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(frame.file);
1633 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame member (", item.name, "=", item.value, ") is unheard of");
1636 _dpl(0, "Bad frame");
1641 delete argumentTokens;
1645 Breakpoint GetBreakpointById(int id, bool * isInternal)
1647 Breakpoint bp = null;
1648 //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::GetBreakpointById(", id, ")");
1650 *isInternal = false;
1653 for(i : sysBPs; i.bp && i.bp.id == id)
1660 if(!bp && bpRunToCursor && bpRunToCursor.bp && bpRunToCursor.bp.id == id)
1664 for(i : ide.workspace.breakpoints; i.bp && i.bp.id == id)
1674 GdbDataBreakpoint ParseBreakpoint(char * string, Array<char *> outTokens)
1677 GdbDataBreakpoint bp { };
1678 DebugListItem item { };
1679 Array<char *> bpTokens { minAllocSize = 16 };
1680 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseBreakpoint()");
1681 string = StripCurlies(string);
1682 TokenizeList(string, ',', bpTokens);
1683 for(i = 0; i < bpTokens.count; i++)
1685 if(TokenizeListItem(bpTokens[i], item))
1687 StripQuotes(item.value, item.value);
1688 if(!strcmp(item.name, "number"))
1690 if(!strchr(item.value, '.'))
1691 bp.id = atoi(item.value);
1692 bp.number = item.value;
1694 else if(!strcmp(item.name, "type"))
1695 bp.type = item.value;
1696 else if(!strcmp(item.name, "disp"))
1697 bp.disp = item.value;
1698 else if(!strcmp(item.name, "enabled"))
1699 bp.enabled = (!strcmpi(item.value, "y"));
1700 else if(!strcmp(item.name, "addr"))
1702 if(outTokens && !strcmp(item.value, "<MULTIPLE>"))
1705 Array<GdbDataBreakpoint> bpArray = bp.multipleBPs = { };
1706 while(outTokens.count > ++c)
1708 GdbDataBreakpoint multBp = ParseBreakpoint(outTokens[c], null);
1709 bpArray.Add(multBp);
1713 bp.addr = item.value;
1715 else if(!strcmp(item.name, "func"))
1716 bp.func = item.value;
1717 else if(!strcmp(item.name, "file"))
1718 bp.file = item.value;
1719 else if(!strcmp(item.name, "fullname"))
1720 bp.fullname = item.value;
1721 else if(!strcmp(item.name, "line"))
1722 bp.line = atoi(item.value);
1723 else if(!strcmp(item.name, "at"))
1725 else if(!strcmp(item.name, "times"))
1726 bp.times = atoi(item.value);
1727 else if(!strcmp(item.name, "original-location") || !strcmp(item.name, "thread-groups"))
1728 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "breakpoint member (", item.name, "=", item.value, ") is ignored");
1730 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "breakpoint member (", item.name, "=", item.value, ") is unheard of");
1738 void ShowDebuggerViews()
1740 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ShowDebuggerViews()");
1741 ide.outputView.Show();
1742 ide.outputView.SelectTab(debug);
1743 ide.threadsView.Show();
1744 ide.callStackView.Show();
1745 ide.watchesView.Show();
1749 void HideDebuggerViews()
1751 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::HideDebuggerViews()");
1752 ide.RepositionWindows(true);
1755 bool ::GdbCommand(Time timeOut, bool focus, char * format, ...)
1757 bool result = false;
1761 // TODO: Improve this limit
1762 static char string[MAX_F_STRING*4];
1764 va_start(args, format);
1765 vsnprintf(string, sizeof(string), format, args);
1766 string[sizeof(string)-1] = 0;
1770 ide.debugger.serialSemaphore.TryWait();
1772 #ifdef GDB_DEBUG_CONSOLE
1773 _dpl2(_dpct, dplchan::gdbCommand, 0, string);
1775 #ifdef GDB_DEBUG_OUTPUT
1776 ide.outputView.gdbBox.Logf("cmd: %s\n", string);
1778 #ifdef GDB_DEBUG_GUI
1780 ide.gdbDialog.AddCommand(string);
1783 strcat(string,"\n");
1784 gdbHandle.Puts(string);
1787 Process_ShowWindows(targetProcessId);
1793 startTime = GetTime();
1796 if(ide.debugger.serialSemaphore.TryWait())
1803 if(GetTime() - startTime > timeOut)
1811 ide.debugger.serialSemaphore.Wait();
1820 bool ValidateBreakpoint(Breakpoint bp)
1822 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ValidateBreakpoint()");
1823 if(modules && bp.line && bp.bp)
1825 if(bp.bp.line != bp.line)
1831 ide.outputView.debugBox.Logf("WOULD HAVE -- Invalid breakpoint disabled: %s:%d\n", bp.relativeFilePath, bp.line);
1833 //UnsetBreakpoint(bp);
1834 //bp.enabled = false;
1840 ide.outputView.debugBox.Logf("Debugger Error: ValidateBreakpoint error\n");
1841 bp.line = bp.bp.line;
1848 void BreakpointsMaintenance()
1850 //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::BreakpointsMaintenance()");
1853 if(gdbExecution.suspendInternalBreakpoints)
1855 for(bp : sysBPs; bp.inserted)
1856 UnsetBreakpoint(bp);
1860 DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig, bitDepth);
1861 for(bp : sysBPs; !bp.inserted)
1863 bool insert = false;
1864 if(bp.type == internalModulesLoaded)
1866 char path[MAX_LOCATION];
1867 char name[MAX_LOCATION];
1868 char fixedModuleName[MAX_FILENAME];
1871 bool moduleLoadBlock = false;
1873 ReplaceSpaces(fixedModuleName, ide.project.moduleName);
1874 snprintf(name, sizeof(name),"%s.main.ec", fixedModuleName);
1875 name[sizeof(name)-1] = 0;
1876 strcpy(path, ide.workspace.projectDir);
1877 PathCatSlash(path, objDir.dir);
1878 PathCatSlash(path, name);
1879 f = FileOpen(path, read);
1882 for(lineNumber = 1; !f.Eof(); lineNumber++)
1884 if(f.GetLine(line, sizeof(line) - 1))
1886 bool moduleLoadLine;
1887 TrimLSpaces(line, line);
1888 moduleLoadLine = !strncmp(line, "eModule_Load", strlen("eModule_Load"));
1889 if(!moduleLoadBlock && moduleLoadLine)
1890 moduleLoadBlock = true;
1891 else if(moduleLoadBlock && !moduleLoadLine && strlen(line) > 0)
1897 char relative[MAX_LOCATION];
1898 bp.absoluteFilePath = path;
1899 MakePathRelative(path, ide.workspace.projectDir, relative);
1900 bp.relativeFilePath = relative;
1901 bp.line = lineNumber;
1907 else if(bp.type == internalModuleLoad)
1911 for(prj : ide.workspace.projects)
1913 if(!strcmp(prj.moduleName, "ecere"))
1915 ProjectNode node = prj.topNode.Find("instance.c", false);
1918 char path[MAX_LOCATION];
1919 char relative[MAX_LOCATION];
1920 node.GetFullFilePath(path);
1921 bp.absoluteFilePath = path;
1922 MakePathRelative(path, prj.topNode.path, relative);
1923 bp.relativeFilePath = relative;
1934 SetBreakpoint(bp, false);
1939 if(userAction != runToCursor && bpRunToCursor && bpRunToCursor.inserted)
1940 UnsetBreakpoint(bpRunToCursor);
1941 if(bpRunToCursor && !bpRunToCursor.inserted)
1942 SetBreakpoint(bpRunToCursor, false);
1944 if(ignoreBreakpoints)
1946 for(bp : ide.workspace.breakpoints; bp.inserted)
1947 UnsetBreakpoint(bp);
1951 for(bp : ide.workspace.breakpoints; !bp.inserted && bp.type == user)
1955 if(!SetBreakpoint(bp, false))
1956 SetBreakpoint(bp, true);
1965 bp.bp = GdbDataBreakpoint { };
1972 void UnsetBreakpoint(Breakpoint bp)
1974 char * s = null; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::UnsetBreakpoint(", s=bp.CopyLocationString(false), ") -- ", bp.type); delete s;
1975 if(symbols && bp.inserted)
1977 GdbCommand(0, false, "-break-delete %s", bp.bp.number);
1978 bp.inserted = false;
1984 bool SetBreakpoint(Breakpoint bp, bool removePath)
1986 char * s = null; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::SetBreakpoint(", s=bp.CopyLocationString(false), ", ", removePath ? "**** removePath(true) ****" : "", ") -- ", bp.type); delete s;
1987 breakpointError = false;
1988 if(symbols && bp.enabled && (!bp.project || bp.project.GetTargetType(bp.project.config) == staticLibrary || bp.project == ide.project || projectsLibraryLoaded[bp.project.name]))
1990 sentBreakInsert = true;
1992 GdbCommand(0, false, "-break-insert *%s", bp.address);
1995 char * location = bp.CopyLocationString(removePath);
1996 GdbCommand(0, false, "-break-insert %s", location);
1999 if(!breakpointError)
2001 char * address = null;
2002 if(bpItem && bpItem.multipleBPs && bpItem.multipleBPs.count)
2005 GdbDataBreakpoint first = null;
2006 for(n : bpItem.multipleBPs)
2008 if(!fstrcmp(n.fullname, bp.absoluteFilePath) && !first)
2018 GdbCommand(0, false, "-break-disable %s", n.number);
2022 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error breakpoint already disabled.");
2027 address = CopyString(first.addr);
2028 bpItem.addr = first.addr;
2029 bpItem.func = first.func;
2030 bpItem.file = first.file;
2031 bpItem.fullname = first.fullname;
2032 bpItem.line = first.line;
2033 //bpItem.thread-groups = first.thread-groups;*/
2036 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints all disabled.");
2038 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints in exact same file not supported.");
2039 bpItem.multipleBPs.Free();
2040 delete bpItem.multipleBPs;
2045 bp.inserted = (bp.bp && bp.bp.number && strcmp(bp.bp.number, "0"));
2047 ValidateBreakpoint(bp);
2051 UnsetBreakpoint(bp);
2052 bp.address = address;
2054 SetBreakpoint(bp, removePath);
2058 return !breakpointError;
2063 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbGetStack()");
2065 stackFrames.Free(Frame::Free);
2066 GdbCommand(0, false, "-stack-info-depth");
2068 GdbCommand(0, false, "-stack-info-depth 192");
2069 if(frameCount && frameCount <= 192)
2070 GdbCommand(0, false, "-stack-list-frames 0 %d", Min(frameCount-1, 191));
2073 GdbCommand(0, false, "-stack-list-frames 0 %d", Min(frameCount-1, 95));
2074 GdbCommand(0, false, "-stack-list-frames %d %d", Max(frameCount - 96, 96), frameCount - 1);
2076 GdbCommand(0, false, "");
2081 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbTargetSet()");
2084 char escaped[MAX_LOCATION];
2085 strescpy(escaped, targetFile);
2086 GdbCommand(0, 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
2093 const char *vgdbCommand = "/usr/bin/vgdb"; // TODO: vgdb command config option
2094 //GdbCommand(0, false, "-target-select remote | %s --pid=%d", "vgdb", targetProcessId);
2095 printf("target remote | %s --pid=%d\n", vgdbCommand, targetProcessId);
2096 GdbCommand(0, false, "target remote | %s --pid=%d", vgdbCommand, targetProcessId); // TODO: vgdb command config option
2099 GdbCommand(0, false, "info target"); //GDB/MI Missing Implementation -file-list-symbol-files and -file-list-exec-sections
2101 /*for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
2102 GdbCommand(0, false, "-environment-directory \"%s\"", prj.topNode.path);*/
2104 for(dir : ide.workspace.sourceDirs; dir && dir[0])
2106 bool interference = false;
2107 for(prj : ide.workspace.projects)
2109 if(!fstrcmp(prj.topNode.path, dir))
2111 interference = true;
2115 if(!interference && dir[0])
2116 GdbCommand(0, false, "-environment-directory \"%s\"", dir);
2124 /*void GdbTargetRelease()
2128 BreakpointsDeleteAll();
2129 GdbCommand(0, false, "file"); //GDB/MI Missing Implementation -target-detach
2135 void GdbDebugBreak(bool internal)
2137 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbDebugBreak()");
2141 breakType = DebuggerAction::internal;
2143 if(ide) ide.Update(null);
2145 if(Process_Break(targetProcessId)) //GdbCommand(0, false, "-exec-interrupt");
2146 serialSemaphore.Wait();
2149 _ChangeState(loaded);
2150 targetProcessId = 0;
2155 ide.outputView.debugBox.Logf("Debugger Error: GdbDebugBreak with not target id should never happen\n");
2160 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecRun()");
2165 ShowDebuggerViews();
2167 GdbExecContinue(true);
2168 else if(!GdbCommand(3, true, "-exec-run"))
2169 gdbExecution = none;
2172 void GdbExecContinue(bool focus)
2174 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecContinue()");
2177 GdbCommand(0, focus, "-exec-continue");
2182 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecNext()");
2183 gdbExecution = next;
2185 GdbCommand(0, true, "-exec-next");
2188 void GdbExecUntil(char * absoluteFilePath, int lineNumber)
2190 char relativeFilePath[MAX_LOCATION];
2191 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecUntil()");
2192 gdbExecution = until;
2194 if(absoluteFilePath)
2196 WorkspaceGetRelativePath(absoluteFilePath, relativeFilePath, null);
2197 GdbCommand(0, true, "-exec-until %s:%d", relativeFilePath, lineNumber);
2200 GdbCommand(0, true, "-exec-until");
2203 void GdbExecAdvance(char * absoluteFilePathOrLocation, int lineNumber)
2205 char relativeFilePath[MAX_LOCATION];
2206 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecAdvance()");
2207 gdbExecution = advance;
2211 WorkspaceGetRelativePath(absoluteFilePathOrLocation, relativeFilePath, null);
2212 GdbCommand(0, true, "advance %s:%d", relativeFilePath, lineNumber); // should use -exec-advance -- GDB/MI implementation missing
2215 GdbCommand(0, true, "advance %s", absoluteFilePathOrLocation); // should use -exec-advance -- GDB/MI implementation missing
2220 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecStep()");
2221 gdbExecution = step;
2223 GdbCommand(0, true, "-exec-step");
2226 void GdbExecFinish()
2228 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecFinish()");
2229 gdbExecution = finish;
2231 GdbCommand(0, true, "-exec-finish");
2234 void GdbExecCommon()
2236 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecCommon()");
2237 BreakpointsMaintenance();
2240 #ifdef GDB_DEBUG_GUI
2241 void SendGDBCommand(char * command)
2243 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SendGDBCommand()");
2244 DebuggerState oldState = state;
2249 GdbDebugBreak(true);
2252 GdbCommand(0, false, command);
2255 if(oldState == running)
2256 GdbExecContinue(false);
2260 void ClearBreakDisplay()
2262 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ClearBreakDisplay()");
2264 activeFrameLevel = -1;
2274 stackFrames.Free(Frame::Free);
2275 ide.callStackView.Clear();
2276 ide.threadsView.Clear();
2282 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbAbortExec()");
2284 GdbCommand(0, false, "-interpreter-exec console \"kill\""); // should use -exec-abort -- GDB/MI implementation incomplete
2288 bool GdbInit(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
2291 char oldDirectory[MAX_LOCATION];
2292 char tempPath[MAX_LOCATION];
2293 char command[MAX_F_STRING*4];
2294 Project project = ide.project;
2295 DirExpression targetDirExp = project.GetTargetDir(compiler, config, bitDepth);
2296 PathBackup pathBackup { };
2298 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbInit()");
2299 if(currentCompiler != compiler)
2301 delete currentCompiler;
2302 currentCompiler = compiler;
2303 incref currentCompiler;
2306 this.bitDepth = bitDepth;
2307 usingValgrind = useValgrind;
2309 _ChangeState(loaded);
2311 sentBreakInsert = false;
2312 breakpointError = false;
2313 ignoreBreakpoints = false;
2318 projectsLibraryLoaded.Free();
2320 ide.outputView.ShowClearSelectTab(debug);
2321 ide.outputView.debugBox.Logf($"Starting debug mode\n");
2323 #ifdef GDB_DEBUG_OUTPUT
2324 ide.outputView.gdbBox.Logf("run: Starting GDB\n");
2327 strcpy(tempPath, ide.workspace.projectDir);
2328 PathCatSlash(tempPath, targetDirExp.dir);
2330 targetDir = CopyString(tempPath);
2331 project.CatTargetFileName(tempPath, compiler, config);
2333 targetFile = CopyString(tempPath);
2335 GetWorkingDir(oldDirectory, MAX_LOCATION);
2336 if(ide.workspace.debugDir && ide.workspace.debugDir[0])
2338 char temp[MAX_LOCATION];
2339 strcpy(temp, ide.workspace.projectDir);
2340 PathCatSlash(temp, ide.workspace.debugDir);
2341 ChangeWorkingDir(temp);
2344 ChangeWorkingDir(ide.workspace.projectDir);
2346 ide.SetPath(true, compiler, config, bitDepth);
2348 // TODO: This pollutes the environment, but at least it works
2349 // It shouldn't really affect the IDE as the PATH gets restored and other variables set for testing will unlikely cause problems
2350 // What is the proper solution for this? DualPipeOpenEnv?
2351 // gdb set environment commands don't seem to take effect
2352 for(e : ide.workspace.environmentVars)
2354 SetEnvironment(e.name, e.string);
2359 char * clArgs = ide.workspace.commandLineArgs;
2360 const char *valgrindCommand = "valgrind"; // TODO: valgrind command config option //TODO: valgrind options
2361 ValgrindLeakCheck vgLeakCheck = ide.workspace.vgLeakCheck;
2362 int vgRedzoneSize = ide.workspace.vgRedzoneSize;
2363 bool vgTrackOrigins = ide.workspace.vgTrackOrigins;
2364 vgLogFile = CreateTemporaryFile(vgLogPath, "ecereidevglog");
2368 vgLogThread.Create();
2372 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't open temporary log file for Valgrind output\n");
2375 if(result && !CheckCommandAvailable(valgrindCommand))
2377 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Command %s for Valgrind is not available.\n", valgrindCommand);
2382 char * vgRedzoneSizeFlag = vgRedzoneSize == -1 ? "" : PrintString(" --redzone-size=", vgRedzoneSize);
2383 sprintf(command, "%s --vgdb=yes --vgdb-error=0 --log-file=%s --leak-check=%s%s --track-origins=%s %s%s%s",
2384 valgrindCommand, vgLogPath, (char*)vgLeakCheck, vgRedzoneSizeFlag, vgTrackOrigins ? "yes" : "no", targetFile, clArgs ? " " : "", clArgs ? clArgs : "");
2385 if(vgRedzoneSize != -1)
2386 delete vgRedzoneSizeFlag;
2387 vgTargetHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
2390 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start Valgrind\n");
2396 incref vgTargetHandle;
2397 vgTargetThread.Create();
2399 targetProcessId = vgTargetHandle.GetProcessID();
2400 waitingForPID = false;
2401 if(!targetProcessId)
2403 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't get Valgrind process ID\n");
2410 serialSemaphore.Wait();
2418 (compiler.targetPlatform == win32 && bitDepth == 64) ? "x86_64-w64-mingw32-gdb" :
2419 (compiler.targetPlatform == win32 && bitDepth == 32) ? "i686-w64-mingw32-gdb" :
2421 if(!CheckCommandAvailable(command))
2423 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Command %s for GDB is not available.\n", command);
2428 strcat(command, " -n -silent --interpreter=mi2"); //-async //\"%s\"
2430 gdbHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
2433 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start GDB\n");
2443 gdbProcessId = gdbHandle.GetProcessID();
2446 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't get GDB process ID\n");
2453 serialSemaphore.Wait();
2456 GdbCommand(0, false, "-gdb-set verbose off");
2457 //GdbCommand(0, false, "-gdb-set exec-done-display on");
2458 GdbCommand(0, false, "-gdb-set step-mode off");
2459 GdbCommand(0, false, "-gdb-set unwindonsignal on");
2460 //GdbCommand(0, false, "-gdb-set shell on");
2461 GdbCommand(0, false, "set print elements 992");
2462 GdbCommand(0, false, "-gdb-set backtrace limit 100000");
2466 //_ChangeState(terminated);
2472 #if defined(__unix__)
2474 CreateTemporaryDir(progFifoDir, "ecereide");
2475 strcpy(progFifoPath, progFifoDir);
2476 PathCat(progFifoPath, "ideprogfifo");
2477 if(!mkfifo(progFifoPath, 0600))
2479 //fileCreated = true;
2484 ide.outputView.debugBox.Logf(createFIFOMsg, progFifoPath);
2491 progThread.terminate = false;
2492 progThread.Create();
2496 #if defined(__WIN32__)
2497 GdbCommand(0, false, "-gdb-set new-console on");
2500 #if defined(__unix__)
2502 GdbCommand(0, false, "-inferior-tty-set %s", progFifoPath);
2506 GdbCommand(0, false, "-gdb-set args %s", ide.workspace.commandLineArgs ? ide.workspace.commandLineArgs : "");
2508 for(e : ide.workspace.environmentVars)
2510 GdbCommand(0, false, "set environment %s=%s", e.name, e.string);
2515 ChangeWorkingDir(oldDirectory);
2521 delete targetDirExp;
2527 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExit()");
2528 if(gdbHandle && gdbProcessId)
2531 GdbCommand(0, false, "-gdb-exit");
2541 vgLogFile.CloseInput();
2550 vgTargetThread.Wait();
2560 _ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
2566 for(bp : ide.workspace.breakpoints)
2572 bpRunToCursor.Reset();
2574 ide.outputView.debugBox.Logf($"Debugging stopped\n");
2575 ClearBreakDisplay();
2578 #if defined(__unix__)
2579 if(!usingValgrind && FileExists(progFifoPath)) //fileCreated)
2581 progThread.terminate = true;
2584 fifoFile.CloseInput();
2590 DeleteFile(progFifoPath);
2591 progFifoPath[0] = '\0';
2597 bool WatchesLinkCodeEditor()
2599 bool goodFrame = activeFrame && activeFrame.absoluteFile;
2600 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesLinkCodeEditor()");
2601 if(codeEditor && (!goodFrame || fstrcmp(codeEditor.fileName, activeFrame.absoluteFile)))
2602 WatchesReleaseCodeEditor();
2604 if(!codeEditor && goodFrame)
2606 codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, normal, false, null, no, normal, false);
2609 codeEditor.inUseDebug = true;
2613 return codeEditor != null;
2616 void WatchesReleaseCodeEditor()
2618 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesReleaseCodeEditor()");
2621 codeEditor.inUseDebug = false;
2622 if(!codeEditor.visible)
2623 codeEditor.Destroy(0);
2628 bool ResolveWatch(Watch wh)
2630 bool result = false;
2632 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::ResolveWatch()");
2644 char watchmsg[MAX_F_STRING];
2645 if(state == stopped && !codeEditor)
2646 wh.value = CopyString($"No source file found for selected frame");
2647 //if(codeEditor && state == stopped || state != stopped)
2650 Module backupPrivateModule;
2651 Context backupContext;
2652 Class backupThisClass;
2656 backupPrivateModule = GetPrivateModule();
2657 backupContext = GetCurrentContext();
2658 backupThisClass = GetThisClass();
2661 SetPrivateModule(codeEditor.privateModule);
2662 SetCurrentContext(codeEditor.globalContext);
2663 SetTopContext(codeEditor.globalContext);
2664 SetGlobalContext(codeEditor.globalContext);
2665 SetGlobalData(&codeEditor.globalData);
2668 exp = ParseExpressionString(wh.expression);
2670 if(exp && !parseError)
2672 char expString[4096];
2674 PrintExpression(exp, expString);
2676 if(GetPrivateModule())
2679 DebugFindCtxTree(codeEditor.ast, activeFrame.line, 0);
2680 ProcessExpressionType(exp);
2682 wh.type = exp.expType;
2685 DebugComputeExpression(exp);
2686 if(ExpressionIsError(exp))
2688 GDBFallBack(exp, expString);
2691 /*if(exp.hasAddress)
2693 char temp[MAX_F_STRING];
2694 sprintf(temp, "0x%x", exp.address);
2695 wh.address = CopyString(temp);
2696 // wh.address = CopyStringf("0x%x", exp.address);
2701 Type dataType = exp.expType;
2704 char temp[MAX_F_STRING];
2705 switch(dataType.kind)
2708 sprintf(temp, "%i", exp.val.c);
2711 sprintf(temp, "%i", exp.val.s);
2716 sprintf(temp, "%i", exp.val.i);
2719 sprintf(temp, "%i", exp.val.i64);
2722 sprintf(temp, "%i", exp.val.p);
2727 long v = (long)exp.val.f;
2728 sprintf(temp, "%i", v);
2733 long v = (long)exp.val.d;
2734 sprintf(temp, "%i", v);
2739 wh.intVal = CopyString(temp);
2740 switch(dataType.kind)
2743 sprintf(temp, "0x%x", exp.val.c);
2746 sprintf(temp, "0x%x", exp.val.s);
2750 sprintf(temp, "0x%x", exp.val.i);
2753 sprintf(temp, "0x%x", exp.val.i64);
2756 sprintf(temp, "0x%x", exp.val.i64);
2759 sprintf(temp, "0x%x", exp.val.p);
2764 long v = (long)exp.val.f;
2765 sprintf(temp, "0x%x", v);
2770 long v = (long)exp.val.d;
2771 sprintf(temp, "0x%x", v);
2776 wh.hexVal = CopyString(temp);
2777 switch(dataType.kind)
2780 sprintf(temp, "0o%o", exp.val.c);
2783 sprintf(temp, "0o%o", exp.val.s);
2787 sprintf(temp, "0o%o", exp.val.i);
2790 sprintf(temp, "0o%o", exp.val.i64);
2793 sprintf(temp, "0o%o", exp.val.i64);
2796 sprintf(temp, "0o%o", exp.val.p);
2801 long v = (long)exp.val.f;
2802 sprintf(temp, "0o%o", v);
2807 long v = (long)exp.val.d;
2808 sprintf(temp, "0o%o", v);
2813 wh.octVal = CopyString(temp);
2816 // WHATS THIS HERE ?
2817 if(exp.type == constantExp && exp.constant)
2818 wh.constant = CopyString(exp.constant);
2824 case symbolErrorExp:
2825 snprintf(watchmsg, sizeof(watchmsg), $"Symbol \"%s\" not found", exp.identifier.string);
2827 case structMemberSymbolErrorExp:
2828 // todo get info as in next case (ExpClassMemberSymbolError)
2829 snprintf(watchmsg, sizeof(watchmsg), $"Error: Struct member not found for \"%s\"", wh.expression);
2831 case classMemberSymbolErrorExp:
2834 Expression memberExp = exp.member.exp;
2835 Identifier memberID = exp.member.member;
2836 Type type = memberExp.expType;
2839 _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
2842 char string[256] = "";
2844 PrintTypeNoConst(type, string, false, true);
2845 classSym = FindClass(string);
2846 _class = classSym ? classSym.registered : null;
2849 snprintf(watchmsg, sizeof(watchmsg), $"Member \"%s\" not found in class \"%s\"", memberID ? memberID.string : "", _class.name);
2851 snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in unregistered class? (Should never get this message)", memberID ? memberID.string : "");
2854 snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in no type? (Should never get this message)", memberID ? memberID.string : "");
2857 case memoryErrorExp:
2858 // Need to ensure when set to memoryErrorExp, constant is set
2859 snprintf(watchmsg, sizeof(watchmsg), $"Memory can't be read at %s", /*(exp.type == constantExp) ? */exp.constant /*: null*/);
2861 case dereferenceErrorExp:
2862 snprintf(watchmsg, sizeof(watchmsg), $"Dereference failure for \"%s\"", wh.expression);
2864 case unknownErrorExp:
2865 snprintf(watchmsg, sizeof(watchmsg), $"Unknown error for \"%s\"", wh.expression);
2867 case noDebuggerErrorExp:
2868 snprintf(watchmsg, sizeof(watchmsg), $"Debugger required for symbol evaluation in \"%s\"", wh.expression);
2870 case debugStateErrorExp:
2871 snprintf(watchmsg, sizeof(watchmsg), $"Incorrect debugger state for symbol evaluation in \"%s\"", wh.expression);
2874 snprintf(watchmsg, sizeof(watchmsg), $"Null type for \"%s\"", wh.expression);
2878 // Temporary Code for displaying Strings
2879 if((exp.expType && ((exp.expType.kind == pointerType ||
2880 exp.expType.kind == arrayType) && exp.expType.type.kind == charType)) ||
2881 (wh.type && wh.type.kind == classType && wh.type._class &&
2882 wh.type._class.registered && wh.type._class.registered.type == normalClass &&
2883 !strcmp(wh.type._class.registered.name, "String")))
2886 if(exp.expType.kind != arrayType || exp.hasAddress)
2892 //char temp[MAX_F_STRING * 32];
2894 ExpressionType evalError = dummyExp;
2895 /*if(exp.expType.kind == arrayType)
2896 sprintf(temp, "(char*)0x%x", exp.address);
2898 sprintf(temp, "(char*)%s", exp.constant);*/
2900 //evaluation = Debugger::EvaluateExpression(temp, &evalError);
2901 // address = strtoul(exp.constant, null, 0);
2902 address = _strtoui64(exp.constant, null, 0);
2903 //_dpl(0, "0x", address);
2904 // snprintf(value, sizeof(value), "0x%08x ", address);
2906 if(address > 0xFFFFFFFFLL)
2907 snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%016I64x " : "0x%016llx ", address);
2909 snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%08I64x " : "0x%08llx ", address);
2910 value[sizeof(value)-1] = 0;
2913 strcat(value, $"Null string");
2917 len = strlen(value);
2919 while(!string && size > 2)
2921 string = GdbReadMemory(address, size);
2924 if(string && string[0])
2927 if(UTF8Validate(string))
2932 for(c = 0; (ch = string[c]) && c<4096; c++)
2935 value[len++] = '\0';
2940 ISO8859_1toUTF8(string, value + len, 4096 - len - 30);
2941 strcat(value, ") (ISO8859-1)");
2948 strcat(value, $"Empty string");
2952 strcat(value, $"Couldn't read memory");
2954 wh.value = CopyString(value);
2957 else if(wh.type && wh.type.kind == classType && wh.type._class &&
2958 wh.type._class.registered && wh.type._class.registered.type == enumClass)
2960 uint64 value = strtoul(exp.constant, null, 0);
2961 Class enumClass = eSystem_FindClass(GetPrivateModule(), wh.type._class.registered.name);
2962 EnumClassData enumeration = (EnumClassData)enumClass.data;
2964 for(item = enumeration.values.first; item; item = item.next)
2965 if((int)item.data == value)
2968 wh.value = CopyString(item.name);
2970 wh.value = CopyString($"Invalid Enum Value");
2973 else if(wh.type && (wh.type.kind == charType || (wh.type.kind == classType && wh.type._class &&
2974 wh.type._class.registered && !strcmp(wh.type._class.registered.fullName, "ecere::com::unichar"))) )
2981 if(exp.constant[0] == '\'')
2983 if((int)((byte *)exp.constant)[1] > 127)
2986 value = UTF8GetChar(exp.constant + 1, &nb);
2987 if(nb < 2) value = exp.constant[1];
2988 signedValue = value;
2992 signedValue = exp.constant[1];
2994 // Precomp Syntax error with boot strap here:
2995 byte b = (byte)(char)signedValue;
2996 value = (unichar) b;
3002 if(wh.type.kind == charType && wh.type.isSigned)
3004 signedValue = (int)(char)strtol(exp.constant, null, 0);
3006 // Precomp Syntax error with boot strap here:
3007 byte b = (byte)(char)signedValue;
3008 value = (unichar) b;
3013 value = (uint)strtoul(exp.constant, null, 0);
3014 signedValue = (int)value;
3018 UTF32toUTF8Len(&value, 1, charString, 5);
3020 snprintf(string, sizeof(string), "\'\\0' (0)");
3021 else if(value == '\t')
3022 snprintf(string, sizeof(string), "\'\\t' (%d)", value);
3023 else if(value == '\n')
3024 snprintf(string, sizeof(string), "\'\\n' (%d)", value);
3025 else if(value == '\r')
3026 snprintf(string, sizeof(string), "\'\\r' (%d)", value);
3027 else if(wh.type.kind == charType && wh.type.isSigned)
3028 snprintf(string, sizeof(string), "\'%s\' (%d)", charString, signedValue);
3029 else if(value > 256 || wh.type.kind != charType)
3031 if(value > 0x10FFFF || !GetCharCategory(value))
3032 snprintf(string, sizeof(string), $"Invalid Unicode Keypoint (0x%08X)", value);
3034 snprintf(string, sizeof(string), "\'%s\' (U+%04X)", charString, value);
3037 snprintf(string, sizeof(string), "\'%s\' (%d)", charString, value);
3038 string[sizeof(string)-1] = 0;
3040 wh.value = CopyString(string);
3045 wh.value = CopyString(exp.constant);
3052 wh.value = PrintHexUInt64(exp.address);
3057 char tempString[256];
3058 if(exp.member.memberType == propertyMember)
3059 snprintf(watchmsg, sizeof(watchmsg), $"Missing property evaluation support for \"%s\"", wh.expression);
3061 snprintf(watchmsg, sizeof(watchmsg), $"Evaluation failed for \"%s\" of type \"%s\"", wh.expression,
3062 exp.type.OnGetString(tempString, null, null));
3068 snprintf(watchmsg, sizeof(watchmsg), $"Invalid expression: \"%s\"", wh.expression);
3069 if(exp) FreeExpression(exp);
3072 SetPrivateModule(backupPrivateModule);
3073 SetCurrentContext(backupContext);
3074 SetTopContext(backupContext);
3075 SetGlobalContext(backupContext);
3076 SetThisClass(backupThisClass);
3079 // wh.value = CopyString("No source file found for selected frame");
3081 watchmsg[sizeof(watchmsg)-1] = 0;
3083 wh.value = CopyString(watchmsg);
3085 ide.watchesView.UpdateWatch(wh);
3089 void EvaluateWatches()
3091 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateWatches()");
3092 WatchesLinkCodeEditor();
3093 if(state == stopped)
3095 for(wh : ide.workspace.watches)
3100 char * ::GdbEvaluateExpression(char * expression)
3102 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::GdbEvaluateExpression(", expression, ")");
3105 GdbCommand(0, false, "-data-evaluate-expression \"%s\"", expression);
3107 ide.outputView.debugBox.Logf("Debugger Error: GdbEvaluateExpression\n");
3111 // to be removed... use GdbReadMemory that returns a byte array instead
3112 char * ::GdbReadMemoryString(uint64 address, int size, char format, int rows, int cols)
3114 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemoryString(", address, ")");
3119 _dpl(0, "GdbReadMemoryString called with size = 0!");
3121 // GdbCommand(0, false, "-data-read-memory 0x%08x %c, %d, %d, %d", address, format, size, rows, cols);
3122 if(GetRuntimePlatform() == win32)
3123 GdbCommand(0, false, "-data-read-memory 0x%016I64x %c, %d, %d, %d", address, format, size, rows, cols);
3125 GdbCommand(0, false, "-data-read-memory 0x%016llx %c, %d, %d, %d", address, format, size, rows, cols);
3127 ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemoryString\n");
3131 byte * ::GdbReadMemory(uint64 address, int bytes)
3133 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemory(", address, ")");
3136 //GdbCommand(0, false, "-data-read-memory 0x%08x %c, 1, 1, %d", address, 'u', bytes);
3137 if(GetRuntimePlatform() == win32)
3138 GdbCommand(0, false, "-data-read-memory 0x%016I64x %c, 1, 1, %d", address, 'u', bytes);
3140 GdbCommand(0, false, "-data-read-memory 0x%016llx %c, 1, 1, %d", address, 'u', bytes);
3143 _dpl(0, "GdbReadMemory called with bytes = 0!");
3146 ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemory\n");
3147 else if(eval.result && strcmp(eval.result, "N/A"))
3149 byte * result = new byte[bytes];
3150 byte * string = eval.result;
3154 result[c++] = (byte)strtol(string, &string, 10);
3170 bool BreakpointHit(GdbDataStop stopItem, Breakpoint bpInternal, Breakpoint bpUser)
3173 char * s1 = null; char * s2 = null;
3174 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::BreakpointHit(",
3175 "bpInternal(", bpInternal ? s1=bpInternal.CopyLocationString(false) : null, "), ",
3176 "bpUser(", bpUser ? s2=bpUser.CopyLocationString(false) : null, ")) -- ",
3177 "ignoreBreakpoints(", ignoreBreakpoints, "), ",
3178 "hitCursorBreakpoint(", bpUser && bpUser.type == runToCursor, ")");
3179 delete s1; delete s2;
3183 bool conditionMet = true;
3184 if(bpUser.condition)
3186 if(WatchesLinkCodeEditor())
3187 conditionMet = ResolveWatch(bpUser.condition);
3189 conditionMet = false;
3204 if(stopItem.frame.line && bpUser.line != stopItem.frame.line)
3206 // updating user breakpoint on hit location difference
3207 // todo, print something?
3208 bpUser.line = stopItem.frame.line;
3209 ide.breakpointsView.UpdateBreakpoint(bpUser.row);
3210 ide.workspace.Save();
3213 ide.breakpointsView.UpdateBreakpoint(bpUser.row);
3218 if(bpInternal.type == internalModulesLoaded)
3220 if(userAction == stepOver)
3222 if((bpInternal.type == internalEntry && ((intBpMain && intBpMain.inserted) || (intBpWinMain && intBpWinMain.inserted))) ||
3223 (bpInternal.type == internalMain && intBpWinMain && intBpWinMain.inserted))
3226 if(!bpUser && !userAction.breaksOnInternalBreakpoint)
3228 if(userAction == stepOut)
3229 StepOut(ignoreBreakpoints);
3235 if(!bpUser && !bpInternal)
3241 void ValgrindTargetThreadExit()
3243 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ValgrindTargetThreadExit()");
3246 vgTargetHandle.Wait();
3247 delete vgTargetHandle;
3249 HandleExit(null, null);
3252 void GdbThreadExit()
3254 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbThreadExit()");
3255 if(state != terminated)
3257 _ChangeState(terminated);
3258 targetProcessId = 0;
3259 ClearBreakDisplay();
3264 serialSemaphore.Release();
3269 ide.outputView.debugBox.Logf($"Debugger Fatal Error: GDB lost\n");
3270 ide.outputView.debugBox.Logf($"Debugging stopped\n");
3272 HideDebuggerViews();
3274 //_ChangeState(terminated);
3278 void GdbThreadMain(char * output)
3282 Array<char *> outTokens { minAllocSize = 50 };
3283 Array<char *> subTokens { minAllocSize = 50 };
3284 DebugListItem item { };
3285 DebugListItem item2 { };
3286 bool setWaitingForPID = false;
3288 #if defined(GDB_DEBUG_CONSOLE) || defined(GDB_DEBUG_GUI)
3289 #ifdef GDB_DEBUG_CONSOLE
3290 // _dpl2(_dpct, dplchan::gdbOutput, 0, output);
3293 #ifdef GDB_DEBUG_OUTPUT
3295 int len = strlen(output);
3303 for(c = 0; c < len / 1024; c++)
3305 strncpy(tmp, start, 1024);
3306 ide.outputView.gdbBox.Logf("out: %s\n", tmp);
3309 ide.outputView.gdbBox.Logf("out: %s\n", start);
3313 ide.outputView.gdbBox.Logf("out: %s\n", output);
3317 #ifdef GDB_DEBUG_CONSOLE
3318 strcpy(lastGdbOutput, output);
3320 #ifdef GDB_DEBUG_GUI
3321 if(ide.gdbDialog) ide.gdbDialog.AddOutput(output);
3328 if(strstr(output, "No debugging symbols found") || strstr(output, "(no debugging symbols found)"))
3331 ide.outputView.debugBox.Logf($"Target doesn't contain debug information!\n");
3334 if(!entryPoint && (t = strstr(output, "Entry point:")))
3336 char * addr = t + strlen("Entry point:");
3338 if(*t++ == ' ' && *t++ == '0' && *t == 'x')
3341 while(isxdigit(*++t));
3343 for(bp : sysBPs; bp.type == internalEntry)
3346 bp.enabled = entryPoint = true;
3354 if(TokenizeList(output, ',', outTokens) && !strcmp(outTokens[0], "^done"))
3356 //if(outTokens.count == 1)
3361 _ChangeState(loaded);
3362 targetProcessId = 0;
3363 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
3365 if(!strcmp(item.name, "reason"))
3367 char * reason = item.value;
3368 StripQuotes(reason, reason);
3369 if(!strcmp(reason, "exited-normally") || !strcmp(reason, "exited") || !strcmp(reason, "exited-signalled"))
3372 if(outTokens.count > 2 && TokenizeListItem(outTokens[2], item2))
3374 StripQuotes(item2.value, item2.value);
3375 if(!strcmp(item2.name, "exit-code"))
3376 exitCode = item2.value;
3382 HandleExit(reason, exitCode);
3386 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "kill reply (", item.name, "=", item.value, ") is unheard of");
3389 HandleExit(null, null);
3392 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
3394 if(!strcmp(item.name, "bkpt"))
3396 sentBreakInsert = false;
3402 bpItem = ParseBreakpoint(item.value, outTokens);
3403 //breakType = bpValidation;
3405 else if(!strcmp(item.name, "depth"))
3407 StripQuotes(item.value, item.value);
3408 frameCount = atoi(item.value);
3410 stackFrames.Free(Frame::Free);
3412 else if(!strcmp(item.name, "stack"))
3415 if(stackFrames.count)
3416 ide.callStackView.Logf("...\n");
3419 item.value = StripBrackets(item.value);
3420 TokenizeList(item.value, ',', subTokens);
3421 for(i = 0; i < subTokens.count; i++)
3423 if(TokenizeListItem(subTokens[i], item))
3425 if(!strcmp(item.name, "frame"))
3428 stackFrames.Add(frame);
3429 item.value = StripCurlies(item.value);
3430 ParseFrame(frame, item.value);
3431 if(frame.file && frame.from)
3432 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "unexpected frame file and from members present");
3436 if(activeFrameLevel == -1)
3438 if(ide.projectView.IsModuleInProject(frame.file));
3440 if(frame.level != 0)
3442 //stopItem.frame = frame;
3443 breakType = selectFrame;
3446 activeFrame = frame;
3447 activeFrameLevel = frame.level;
3450 ide.callStackView.Logf("%3d ", frame.level);
3451 if(!strncmp(frame.func, "__ecereMethod_", strlen("__ecereMethod_")))
3452 ide.callStackView.Logf($"%s Method, %s:%d\n", &frame.func[strlen("__ecereMethod_")], (s = CopySystemPath(frame.file)), frame.line);
3453 else if(!strncmp(frame.func, "__ecereProp_", strlen("__ecereProp_")))
3454 ide.callStackView.Logf($"%s Property, %s:%d\n", &frame.func[strlen("__ecereProp_")], (s = CopySystemPath(frame.file)), frame.line);
3455 else if(!strncmp(frame.func, "__ecereConstructor_", strlen("__ecereConstructor_")))
3456 ide.callStackView.Logf($"%s Constructor, %s:%d\n", &frame.func[strlen("__ecereConstructor_")], (s = CopySystemPath(frame.file)), frame.line);
3457 else if(!strncmp(frame.func, "__ecereDestructor_", strlen("__ecereDestructor_")))
3458 ide.callStackView.Logf($"%s Destructor, %s:%d\n", &frame.func[strlen("__ecereDestructor_")], (s = CopySystemPath(frame.file)), frame.line);
3460 ide.callStackView.Logf($"%s Function, %s:%d\n", frame.func, (s = CopySystemPath(frame.file)), frame.line);
3465 ide.callStackView.Logf("%3d ", frame.level);
3470 ide.callStackView.Logf($"inside %s, %s\n", frame.func, (s = CopySystemPath(frame.from)));
3474 ide.callStackView.Logf("%s\n", frame.func);
3476 ide.callStackView.Logf($"unknown source\n");
3480 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "stack content (", item.name, "=", item.value, ") is unheard of");
3483 if(activeFrameLevel == -1)
3485 activeFrameLevel = 0;
3486 activeFrame = stackFrames.first;
3488 ide.callStackView.Home();
3490 subTokens.RemoveAll();
3492 /*else if(!strcmp(item.name, "frame"))
3495 item.value = StripCurlies(item.value);
3496 ParseFrame(&frame, item.value);
3498 else if(!strcmp(item.name, "thread-ids"))
3500 ide.threadsView.Clear();
3501 item.value = StripCurlies(item.value);
3502 TokenizeList(item.value, ',', subTokens);
3503 for(i = subTokens.count - 1; ; i--)
3505 if(TokenizeListItem(subTokens[i], item))
3507 if(!strcmp(item.name, "thread-id"))
3510 StripQuotes(item.value, item.value);
3511 value = atoi(item.value);
3512 ide.threadsView.Logf("%3d \n", value);
3515 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "threads content (", item.name, "=", item.value, ") is unheard of");
3520 ide.threadsView.Home();
3522 subTokens.RemoveAll();
3523 //if(!strcmp(outTokens[2], "number-of-threads"))
3525 else if(!strcmp(item.name, "new-thread-id"))
3527 StripQuotes(item.value, item.value);
3528 activeThread = atoi(item.value);
3530 else if(!strcmp(item.name, "value"))
3532 StripQuotes(item.value, item.value);
3533 eval.result = CopyString(item.value);
3534 eval.active = false;
3536 else if(!strcmp(item.name, "addr"))
3538 for(i = 2; i < outTokens.count; i++)
3540 if(TokenizeListItem(outTokens[i], item))
3542 if(!strcmp(item.name, "total-bytes"))
3544 StripQuotes(item.value, item.value);
3545 eval.bytes = atoi(item.value);
3547 else if(!strcmp(item.name, "next-row"))
3549 StripQuotes(item.value, item.value);
3550 eval.nextBlockAddress = _strtoui64(item.value, null, 0);
3552 else if(!strcmp(item.name, "memory"))
3556 //StripQuotes(item.value, item.value);
3557 item.value = StripBrackets(item.value);
3558 // this should be treated as a list...
3559 item.value = StripCurlies(item.value);
3560 TokenizeList(item.value, ',', subTokens);
3561 for(j = 0; j < subTokens.count; j++)
3563 if(TokenizeListItem(subTokens[j], item))
3565 if(!strcmp(item.name, "data"))
3567 item.value = StripBrackets(item.value);
3568 StripQuotes2(item.value, item.value);
3569 eval.result = CopyString(item.value);
3570 eval.active = false;
3574 subTokens.RemoveAll();
3579 else if(!strcmp(item.name, "source-path") || !strcmp(item.name, "BreakpointTable"))
3580 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "command reply (", item.name, "=", item.value, ") is ignored");
3582 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "command reply (", item.name, "=", item.value, ") is unheard of");
3585 else if(!strcmp(outTokens[0], "^running"))
3587 waitingForPID = true;
3588 setWaitingForPID = true;
3589 ClearBreakDisplay();
3591 else if(!strcmp(outTokens[0], "^exit"))
3593 _ChangeState(terminated);
3594 // ide.outputView.debugBox.Logf("Exit\n");
3595 // ide.Update(null);
3597 serialSemaphore.Release();
3599 else if(!strcmp(outTokens[0], "^error"))
3603 sentBreakInsert = false;
3604 breakpointError = true;
3607 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
3609 if(!strcmp(item.name, "msg"))
3611 StripQuotes(item.value, item.value);
3614 eval.active = false;
3616 if(strstr(item.value, "No symbol") && strstr(item.value, "in current context"))
3617 eval.error = symbolNotFound;
3618 else if(strstr(item.value, "Cannot access memory at address"))
3619 eval.error = memoryCantBeRead;
3621 eval.error = unknown;
3623 else if(!strcmp(item.value, "Previous frame inner to this frame (corrupt stack?)"))
3626 else if(!strncmp(item.value, "Cannot access memory at address", 31))
3629 else if(!strcmp(item.value, "Cannot find bounds of current function"))
3631 _ChangeState(stopped);
3632 gdbHandle.Printf("-exec-continue\n");
3634 else if(!strcmp(item.value, "ptrace: No such process."))
3636 _ChangeState(loaded);
3637 targetProcessId = 0;
3639 else if(!strcmp(item.value, "Function \\\"WinMain\\\" not defined."))
3642 else if(!strcmp(item.value, "You can't do that without a process to debug."))
3644 _ChangeState(loaded);
3645 targetProcessId = 0;
3647 else if(strstr(item.value, "No such file or directory."))
3649 _ChangeState(loaded);
3650 targetProcessId = 0;
3652 else if(strstr(item.value, "During startup program exited with code "))
3654 _ChangeState(loaded);
3655 targetProcessId = 0;
3660 if(strlen(item.value) < MAX_F_STRING)
3663 ide.outputView.debugBox.Logf("GDB: %s\n", (s = CopyUnescapedString(item.value)));
3667 ide.outputView.debugBox.Logf("GDB: %s\n", item.value);
3673 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "error content (", item.name, "=", item.value, ") is unheard of");
3676 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "result-record: ", outTokens[0]);
3677 outTokens.RemoveAll();
3680 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "status-async-output: ", outTokens[0]);
3683 if(TokenizeList(output, ',', outTokens))
3685 if(!strcmp(outTokens[0], "=library-loaded"))
3686 FGODetectLoadedLibraryForAddedProjectIssues(outTokens);
3687 else if(!strcmp(outTokens[0], "=thread-group-created") || !strcmp(outTokens[0], "=thread-group-added") ||
3688 !strcmp(outTokens[0], "=thread-group-started") || !strcmp(outTokens[0], "=thread-group-exited") ||
3689 !strcmp(outTokens[0], "=thread-created") || !strcmp(outTokens[0], "=thread-exited") ||
3690 !strcmp(outTokens[0], "=cmd-param-changed") || !strcmp(outTokens[0], "=library-unloaded") ||
3691 !strcmp(outTokens[0], "=breakpoint-modified"))
3692 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, outTokens[0], outTokens.count>1 ? outTokens[1] : "",
3693 outTokens.count>2 ? outTokens[2] : "", outTokens.count>3 ? outTokens[3] : "",
3694 outTokens.count>4 ? outTokens[4] : "", outTokens.count>5 ? outTokens[5] : "",
3695 outTokens.count>6 ? outTokens[6] : "", outTokens.count>7 ? outTokens[7] : "",
3696 outTokens.count>8 ? outTokens[8] : "", outTokens.count>9 ? outTokens[9] : "");
3698 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "notify-async-output: ", outTokens[0]);
3700 outTokens.RemoveAll();
3704 if(TokenizeList(output, ',', outTokens))
3706 if(!strcmp(outTokens[0],"*running"))
3708 waitingForPID = true;
3709 setWaitingForPID = true;
3711 else if(!strcmp(outTokens[0], "*stopped"))
3714 _ChangeState(stopped);
3716 for(tk = 1; tk < outTokens.count; tk++)
3718 if(TokenizeListItem(outTokens[tk], item))
3720 if(!strcmp(item.name, "reason"))
3722 char * reason = item.value;
3723 StripQuotes(reason, reason);
3724 if(!strcmp(reason, "exited-normally") || !strcmp(reason, "exited") || !strcmp(reason, "exited-signalled"))
3727 if(outTokens.count > tk+1 && TokenizeListItem(outTokens[tk+1], item2))
3730 StripQuotes(item2.value, item2.value);
3731 if(!strcmp(item2.name, "exit-code"))
3732 exitCode = item2.value;
3738 HandleExit(reason, exitCode);
3741 else if(!strcmp(reason, "breakpoint-hit") ||
3742 !strcmp(reason, "function-finished") ||
3743 !strcmp(reason, "end-stepping-range") ||
3744 !strcmp(reason, "location-reached") ||
3745 !strcmp(reason, "signal-received"))
3749 if(stopItem) _dpl(0, "problem");
3751 stopItem = GdbDataStop { };
3752 stopItem.reason = r == 'b' ? breakpointHit : r == 'f' ? functionFinished : r == 'e' ? endSteppingRange : r == 'l' ? locationReached : signalReceived;
3754 for(i = tk+1; i < outTokens.count; i++)
3756 TokenizeListItem(outTokens[i], item);
3757 StripQuotes(item.value, item.value);
3758 if(!strcmp(item.name, "thread-id"))
3759 stopItem.threadid = atoi(item.value);
3760 else if(!strcmp(item.name, "frame"))
3762 item.value = StripCurlies(item.value);
3763 ParseFrame(stopItem.frame, item.value);
3765 else if(stopItem.reason == breakpointHit && !strcmp(item.name, "bkptno"))
3766 stopItem.bkptno = atoi(item.value);
3767 else if(stopItem.reason == functionFinished && !strcmp(item.name, "gdb-result-var"))
3768 stopItem.gdbResultVar = CopyString(item.value);
3769 else if(stopItem.reason == functionFinished && !strcmp(item.name, "return-value"))
3770 stopItem.returnValue = CopyString(item.value);
3771 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-name"))
3772 stopItem.name = CopyString(item.value);
3773 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-meaning"))
3774 stopItem.meaning = CopyString(item.value);
3775 else if(!strcmp(item.name, "stopped-threads"))
3776 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Advanced thread debugging not handled");
3777 else if(!strcmp(item.name, "core"))
3778 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Information (core) not used");
3779 else if(!strcmp(item.name, "disp"))
3780 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": (", item.name, "=", item.value, ")");
3782 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown ", reason, " item name (", item.name, "=", item.value, ")");
3785 if(stopItem.reason == signalReceived && !strcmp(stopItem.name, "SIGTRAP"))
3801 event = r == 'b' ? hit : r == 'f' ? functionEnd : r == 'e' ? stepEnd : r == 'l' ? locationReached : signal;
3805 else if(!strcmp(reason, "watchpoint-trigger"))
3806 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint trigger not handled");
3807 else if(!strcmp(reason, "read-watchpoint-trigger"))
3808 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason read watchpoint trigger not handled");
3809 else if(!strcmp(reason, "access-watchpoint-trigger"))
3810 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason access watchpoint trigger not handled");
3811 else if(!strcmp(reason, "watchpoint-scope"))
3812 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint scope not handled");
3814 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown reason: ", reason);
3822 if(usingValgrind && event == none && !stopItem)
3823 event = valgrindStartPause;
3828 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown exec-async-output: ", outTokens[0]);
3829 outTokens.RemoveAll();
3832 if(!strcmpi(output, "(gdb) "))
3836 Time startTime = GetTime();
3837 char exeFile[MAX_LOCATION];
3838 int oldProcessID = targetProcessId;
3839 GetLastDirectory(targetFile, exeFile);
3841 while(!targetProcessId/*true*/)
3843 targetProcessId = Process_GetChildExeProcessId(gdbProcessId, exeFile);
3844 if(targetProcessId) break;
3845 // Can't break on Peek(), GDB is giving us =library and other info before the process is listed in /proc
3846 // if(gdbHandle.Peek()) break;
3848 if(gdbHandle.Peek() && GetTime() - startTime > 2.5) // Give the process 2.5 seconds to show up in /proc
3853 _ChangeState(running);
3854 else if(!oldProcessID)
3856 ide.outputView.debugBox.Logf($"Debugger Error: No target process ID\n");
3857 // TO VERIFY: The rest of this block has not been thoroughly tested in this particular location
3858 gdbHandle.Printf("-gdb-exit\n");
3860 _ChangeState(terminated); //loaded;
3865 for(bp : ide.workspace.breakpoints)
3866 bp.inserted = false;
3869 bp.inserted = false;
3871 bpRunToCursor.inserted = false;
3873 ide.outputView.debugBox.Logf($"Debugging stopped\n");
3874 ClearBreakDisplay();
3876 #if defined(__unix__)
3877 if(!usingValgrind && FileExists(progFifoPath)) //fileCreated)
3879 progThread.terminate = true;
3882 fifoFile.CloseInput();
3889 DeleteFile(progFifoPath);
3890 progFifoPath[0] = '\0';
3897 serialSemaphore.Release();
3900 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown prompt", output);
3904 if(!strncmp(output, "&\"warning:", 10))
3907 content = strstr(output, "\"");
3908 StripQuotes(content, content);
3909 content = strstr(content, ":");
3915 ide.outputView.debugBox.LogRaw((s = CopyUnescapedString(content)));
3922 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown output: ", output);
3924 if(!setWaitingForPID)
3925 waitingForPID = false;
3926 setWaitingForPID = false;
3934 // From GDB Output functions
3935 void FGODetectLoadedLibraryForAddedProjectIssues(Array<char *> outTokens)
3937 char path[MAX_LOCATION] = "";
3938 char file[MAX_FILENAME] = "";
3940 DebugListItem item { };
3941 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGODetectLoadedLibraryForAddedProjectIssues()");
3942 for(token : outTokens)
3944 if(TokenizeListItem(token, item))
3946 if(!strcmp(item.name, "target-name"))
3948 StripQuotes(item.value, path);
3949 MakeSystemPath(path);
3950 GetLastDirectory(path, file);
3952 else if(!strcmp(item.name, "symbols-loaded"))
3954 symbolsLoaded = (atoi(item.value) == 1);
3959 if(path[0] && file[0])
3961 for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
3965 char prjTargetPath[MAX_LOCATION];
3966 char prjTargetFile[MAX_FILENAME];
3967 DirExpression targetDirExp = prj.GetTargetDir(currentCompiler, prj.config, bitDepth);
3968 strcpy(prjTargetPath, prj.topNode.path);
3969 PathCat(prjTargetPath, targetDirExp.dir);
3970 delete targetDirExp;
3971 prjTargetFile[0] = '\0';
3972 prj.CatTargetFileName(prjTargetFile, currentCompiler, prj.config);
3973 PathCat(prjTargetPath, prjTargetFile);
3974 MakeSystemPath(prjTargetPath);
3976 match = !fstrcmp(prjTargetFile, file);
3977 if(!match && (dot = strstr(prjTargetFile, ".so.")))
3979 char * dot3 = strstr(dot+4, ".");
3983 match = !fstrcmp(prjTargetFile, file);
3988 match = !fstrcmp(prjTargetFile, file);
3993 // TODO: nice visual feedback to better warn user. use some ide notification system or other means.
3994 /* -- 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)
3996 ide.outputView.debugBox.Logf($"Attention! No symbols for loaded library %s matched to the %s added project.\n", path, prj.topNode.name);
3998 match = !fstrcmp(prjTargetPath, path);
3999 if(!match && (dot = strstr(prjTargetPath, ".so.")))
4001 char * dot3 = strstr(dot+4, ".");
4005 match = !fstrcmp(prjTargetPath, path);
4010 match = !fstrcmp(prjTargetPath, path);
4014 projectsLibraryLoaded[prj.name] = true;
4016 ide.outputView.debugBox.Logf($"Loaded library %s doesn't match the %s target of the %s added project.\n", path, prjTargetPath, prj.topNode.name);
4023 void FGOBreakpointModified(Array<char *> outTokens)
4025 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGOBreakpointModified() -- TODO only if needed: support breakpoint modified");
4027 DebugListItem item { };
4028 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
4030 if(!strcmp(item.name, "bkpt"))
4032 GdbDataBreakpoint modBp = ParseBreakpoint(item.value, outTokens);
4040 ExpressionType ::DebugEvalExpTypeError(char * result)
4042 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::DebugEvalExpTypeError()");
4047 case symbolNotFound:
4048 return symbolErrorExp;
4049 case memoryCantBeRead:
4050 return memoryErrorExp;
4052 return unknownErrorExp;
4055 char * ::EvaluateExpression(char * expression, ExpressionType * error)
4058 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateExpression(", expression, ")");
4059 if(ide.projectView && ide.debugger.state == stopped)
4061 result = GdbEvaluateExpression(expression);
4062 *error = DebugEvalExpTypeError(result);
4067 *error = noDebuggerErrorExp;
4072 char * ::ReadMemory(uint64 address, int size, char format, ExpressionType * error)
4075 char * result = GdbReadMemoryString(address, size, format, 1, 1);
4076 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ReadMemory(", address, ")");
4077 if(!result || !strcmp(result, "N/A"))
4078 *error = memoryErrorExp;
4080 *error = DebugEvalExpTypeError(result);
4085 class ValgrindLogThread : Thread
4091 static char output[4096];
4092 Array<char> dynamicBuffer { minAllocSize = 4096 };
4093 File oldValgrindHandle = vgLogFile;
4094 incref oldValgrindHandle;
4097 while(debugger.state != terminated && vgLogFile)
4102 result = vgLogFile.Read(output, 1, sizeof(output));
4104 if(debugger.state == terminated || !vgLogFile) // || vgLogFile.Eof()
4111 for(c = 0; c<result; c++)
4113 if(output[c] == '\n')
4115 int pos = dynamicBuffer.size;
4116 dynamicBuffer.size += c - start;
4117 memcpy(&dynamicBuffer[pos], output + start, c - start);
4118 if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
4119 dynamicBuffer.size++;
4120 dynamicBuffer[dynamicBuffer.count - 1] = '\0';
4122 // printf("%s\n", dynamicBuffer.array);
4124 if(strstr(&dynamicBuffer[0], "vgdb me"))
4125 debugger.serialSemaphore.Release();
4127 char * s = strstr(&dynamicBuffer[0], "==");
4129 s = strstr(s+2, "== ");
4136 if(!strstr(s, "vgdb me ...")) //==21690== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
4140 if(!strstr(s, "TO DEBUG THIS PROCESS USING GDB: start GDB like this"))
4144 if(!strstr(s, "and then give GDB the following command"))
4148 if(!strstr(s, "/path/to/gdb") && !strstr(s, "target remote | /usr/lib/valgrind/../../bin/vgdb --pid="))
4152 if(!strstr(s, "--pid is optional if only one valgrind process is running"))
4161 ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
4163 dynamicBuffer.size = 0;
4169 int pos = dynamicBuffer.size;
4170 dynamicBuffer.size += c - start;
4171 memcpy(&dynamicBuffer[pos], output + start, c - start);
4174 else if(debugger.state == stopped)
4177 printf("Got end of file from GDB!\n");
4184 delete dynamicBuffer;
4185 _dpl2(_dpct, dplchan::debuggerCall, 0, "ValgrindLogThreadExit");
4186 //if(oldValgrindHandle == vgLogFile)
4187 debugger.GdbThreadExit/*ValgrindLogThreadExit*/();
4188 delete oldValgrindHandle;
4194 class ValgrindTargetThread : Thread
4200 static char output[4096];
4201 Array<char> dynamicBuffer { minAllocSize = 4096 };
4202 DualPipe oldValgrindHandle = vgTargetHandle;
4203 incref oldValgrindHandle;
4206 while(debugger.state != terminated && vgTargetHandle && !vgTargetHandle.Eof())
4210 result = vgTargetHandle.Read(output, 1, sizeof(output));
4212 if(debugger.state == terminated || !vgTargetHandle || vgTargetHandle.Eof())
4219 for(c = 0; c<result; c++)
4221 if(output[c] == '\n')
4223 int pos = dynamicBuffer.size;
4224 dynamicBuffer.size += c - start;
4225 memcpy(&dynamicBuffer[pos], output + start, c - start);
4226 if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
4227 // COMMENTED OUT DUE TO ISSUE #135, FIXED
4228 //if(dynamicBuffer.array[dynamicBuffer.count - 1] != '\r')
4229 dynamicBuffer.size++;
4230 dynamicBuffer[dynamicBuffer.count - 1] = '\0';
4232 // printf("%s\n", dynamicBuffer.array);
4234 ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
4236 dynamicBuffer.size = 0;
4242 int pos = dynamicBuffer.size;
4243 dynamicBuffer.size += c - start;
4244 memcpy(&dynamicBuffer[pos], output + start, c - start);
4250 printf("Got end of file from GDB!\n");
4254 delete dynamicBuffer;
4255 //if(oldValgrindHandle == vgTargetHandle)
4256 debugger.ValgrindTargetThreadExit();
4257 delete oldValgrindHandle;
4263 class GdbThread : Thread
4269 static char output[4096];
4270 Array<char> dynamicBuffer { minAllocSize = 4096 };
4271 DualPipe oldGdbHandle = gdbHandle;
4272 incref oldGdbHandle;
4275 while(debugger.state != terminated && gdbHandle && !gdbHandle.Eof())
4279 result = gdbHandle.Read(output, 1, sizeof(output));
4281 if(debugger.state == terminated || !gdbHandle || gdbHandle.Eof())
4288 for(c = 0; c<result; c++)
4290 if(output[c] == '\n')
4292 int pos = dynamicBuffer.size;
4293 dynamicBuffer.size += c - start;
4294 memcpy(&dynamicBuffer[pos], output + start, c - start);
4295 if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
4296 // COMMENTED OUT DUE TO ISSUE #135, FIXED
4297 //if(dynamicBuffer.array[dynamicBuffer.count - 1] != '\r')
4298 dynamicBuffer.size++;
4299 dynamicBuffer[dynamicBuffer.count - 1] = '\0';
4301 // _dpl(0, dynamicBuffer.array);
4303 debugger.GdbThreadMain(&dynamicBuffer[0]);
4304 dynamicBuffer.size = 0;
4310 int pos = dynamicBuffer.size;
4311 dynamicBuffer.size += c - start;
4312 memcpy(&dynamicBuffer[pos], output + start, c - start);
4318 _dpl(0, "Got end of file from GDB!");
4322 delete dynamicBuffer;
4323 //if(oldGdbHandle == gdbHandle)
4324 debugger.GdbThreadExit();
4325 delete oldGdbHandle;
4331 static define createFIFOMsg = $"err: Unable to create FIFO %s\n";
4332 static define openFIFOMsg = $"err: Unable to open FIFO %s for read\n";
4334 #if defined(__unix__)
4339 #include <sys/types.h>
4344 class ProgramThread : Thread
4350 bool fileCreated = false;
4352 static char output[1000];
4355 /*if(!mkfifo(progFifoPath, mask))
4362 ide.outputView.debugBox.Logf($"err: Unable to create FIFO %s\n", progFifoPath);
4366 if(FileExists(progFifoPath)) //fileCreated)
4368 fifoFile = FileOpen(progFifoPath, read);
4372 ide.outputView.debugBox.Logf(openFIFOMsg, progFifoPath);
4377 fd = fileno((FILE *)fifoFile.input);
4378 //fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
4382 while(!terminate && fifoFile && !fifoFile.Eof())
4385 struct timeval time;
4393 selectResult = select(fd + 1, &rs, null, null, &time);
4394 if(FD_ISSET(fd, &rs))
4396 int result = (int)read(fd, output, sizeof(output)-1);
4397 if(!result || (result < 0 && errno != EAGAIN))
4401 output[result] = '\0';
4402 if(strcmp(output,"&\"warning: GDB: Failed to set controlling terminal: Invalid argument\\n\"\n"))
4405 ide.outputView.debugBox.Log(output);
4414 //fifoFile.CloseInput();
4417 ide.outputView.debugBox.Log("\n");
4421 if(FileExists(progFifoPath)) //fileCreated)
4423 DeleteFile(progFifoPath);
4424 progFifoPath[0] = '\0';
4432 class Argument : struct
4434 Argument prev, next;
4436 property char * name { set { delete name; if(value) name = CopyString(value); } }
4438 property char * val { set { delete val; if(value) val = CopyString(value); } }
4452 class Frame : struct
4457 property char * addr { set { delete addr; if(value) addr = CopyString(value); } }
4459 property char * func { set { delete func; if(value) func = CopyString(value); } }
4463 property char * from { set { delete from; if(value) from = CopyUnescapedUnixPath(value); } }
4465 property char * file { set { delete file; if(value) file = CopyUnescapedUnixPath(value); } }
4466 char * absoluteFile;
4467 property char * absoluteFile { set { delete absoluteFile; if(value) absoluteFile = CopyUnescapedUnixPath(value); } }
4476 delete absoluteFile;
4477 args.Free(Argument::Free);
4486 class GdbDataStop : struct
4488 DebuggerReason reason;
4503 char * gdbResultVar;
4513 if(reason == signalReceived)
4518 else if(reason == functionFinished)
4520 delete gdbResultVar;
4524 if(frame) frame.Free();
4533 class GdbDataBreakpoint : struct
4537 property char * number { set { delete number; if(value) number = CopyString(value); } }
4539 property char * type { set { delete type; if(value) type = CopyString(value); } }
4541 property char * disp { set { delete disp; if(value) disp = CopyString(value); } }
4544 property char * addr { set { delete addr; if(value) addr = CopyString(value); } }
4546 property char * func { set { delete func; if(value) func = CopyString(value); } }
4548 property char * file { set { delete file; if(value) file = CopyUnescapedUnixPath(value); } }
4550 property char * fullname { set { delete fullname; if(value) fullname = CopyUnescapedUnixPath(value); } }
4553 property char * at { set { delete at; if(value) at = CopyString(value); } }
4556 Array<GdbDataBreakpoint> multipleBPs;
4561 PrintLn("{", "#", number, " T", type, " D", disp, " E", enabled, " H", times, " (", func, ") (", file, ":", line, ") (", fullname, ") (", addr, ") (", at, ")", "}");
4572 if(multipleBPs) multipleBPs.Free();
4578 ~GdbDataBreakpoint()
4584 class Breakpoint : struct
4589 property char * function { set { delete function; if(value) function = CopyString(value); } }
4590 char * relativeFilePath;
4591 property char * relativeFilePath { set { delete relativeFilePath; if(value) relativeFilePath = CopyString(value); } }
4592 char * absoluteFilePath;
4593 property char * absoluteFilePath { set { delete absoluteFilePath; if(value) absoluteFilePath = CopyString(value); } }
4595 property char * location { set { delete location; if(value) location = CopyString(value); } }
4604 BreakpointType type;
4606 GdbDataBreakpoint bp;
4609 property char * address { set { delete address; if(value) address = CopyString(value); } }
4611 void ParseLocation()
4613 char * prjName = null;
4614 char * filePath = null;
4617 char fullPath[MAX_LOCATION];
4618 if(location[0] == '(' && location[1] && (file = strchr(location+2, ')')) && file[1])
4620 prjName = new char[file-location];
4621 strncpy(prjName, location+1, file-location-1);
4622 prjName[file-location-1] = '\0';
4627 if((line = strchr(file+1, ':')))
4629 filePath = new char[strlen(file)+1];
4630 strncpy(filePath, file, line-file);
4631 filePath[line-file] = '\0';
4635 filePath = CopyString(file);
4636 property::relativeFilePath = filePath;
4639 for(prj : ide.workspace.projects)
4641 if(!strcmp(prjName, prj.name))
4643 if(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
4645 property::absoluteFilePath = fullPath;
4652 this.line = atoi(line);
4656 Project prj = ide.project;
4657 if(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
4659 property::absoluteFilePath = fullPath;
4663 if(!absoluteFilePath)
4664 property::absoluteFilePath = "";
4669 char * CopyLocationString(bool removePath)
4672 char * file = relativeFilePath ? relativeFilePath : absoluteFilePath;
4673 bool removingPath = removePath && file;
4676 char * fileName = new char[MAX_FILENAME];
4677 GetLastDirectory(file, fileName);
4683 location = PrintString(file, ":", function);
4685 location = CopyString(function);
4688 location = PrintString(file, ":", line);
4694 char * CopyUserLocationString()
4697 char * loc = CopyLocationString(false);
4699 if(absoluteFilePath)
4701 for(p : ide.workspace.projects; p != ide.workspace.projects.firstIterator.data)
4703 if(p.topNode.FindByFullPath(absoluteFilePath, false))
4712 location = PrintString("(", prj.name, ")", loc);
4722 if(relativeFilePath && relativeFilePath[0])
4724 char * location = CopyUserLocationString();
4725 f.Printf(" * %d,%d,%d,%d,%s\n", enabled ? 1 : 0, ignore, level, line, location);
4728 f.Printf(" ~ %s\n", condition.expression);
4736 delete relativeFilePath;
4737 delete absoluteFilePath;
4757 class Watch : struct
4768 f.Printf(" ~ %s\n", expression);
4792 class DebugListItem : struct
4798 struct DebugEvaluationData
4803 uint64 nextBlockAddress;
4805 DebuggerEvaluationError error;
4808 class CodeLocation : struct
4811 char * absoluteFile;
4814 CodeLocation ::ParseCodeLocation(char * location)
4818 char * colon = null;
4820 char loc[MAX_LOCATION];
4821 strcpy(loc, location);
4822 for(temp = loc; temp = strstr(temp, ":"); temp++)
4830 int line = atoi(colon);
4833 CodeLocation codloc { line = line };
4834 codloc.file = CopyString(loc);
4835 codloc.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(loc);
4847 delete absoluteFile;
4856 void GDBFallBack(Expression exp, String expString)
4859 ExpressionType evalError = dummyExp;
4860 result = Debugger::EvaluateExpression(expString, &evalError);
4863 exp.constant = result;
4864 exp.type = constantExp;
4868 static Project WorkspaceGetFileOwner(char * absolutePath)
4870 Project owner = null;
4871 for(prj : ide.workspace.projects)
4873 if(prj.topNode.FindByFullPath(absolutePath, false))
4880 WorkspaceGetObjectFileNode(absolutePath, &owner);
4884 static ProjectNode WorkspaceGetObjectFileNode(char * filePath, Project * project)
4886 ProjectNode node = null;
4887 char ext[MAX_EXTENSION];
4888 GetExtension(filePath, ext);
4891 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
4894 char fileName[MAX_FILENAME];
4895 GetLastDirectory(filePath, fileName);
4898 DotMain dotMain = DotMain::FromFileName(fileName);
4899 for(prj : ide.workspace.projects)
4901 if((node = prj.FindNodeByObjectFileName(fileName, type, dotMain, null)))
4914 static ProjectNode ProjectGetObjectFileNode(Project project, char * filePath)
4916 ProjectNode node = null;
4917 char ext[MAX_EXTENSION];
4918 GetExtension(filePath, ext);
4921 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
4924 char fileName[MAX_FILENAME];
4925 GetLastDirectory(filePath, fileName);
4928 DotMain dotMain = DotMain::FromFileName(fileName);
4929 node = project.FindNodeByObjectFileName(fileName, type, dotMain, null);
4936 static void WorkspaceGetRelativePath(char * absolutePath, char * relativePath, Project * owner)
4938 Project prj = WorkspaceGetFileOwner(absolutePath);
4942 prj = ide.workspace.projects.firstIterator.data;
4945 MakePathRelative(absolutePath, prj.topNode.path, relativePath);
4946 MakeSlashPath(relativePath);
4949 relativePath[0] = '\0';
4952 static bool ProjectGetAbsoluteFromRelativePath(Project project, char * relativePath, char * absolutePath)
4954 ProjectNode node = project.topNode.FindWithPath(relativePath, false);
4956 node = ProjectGetObjectFileNode(project, relativePath);
4959 strcpy(absolutePath, node.project.topNode.path);
4960 PathCat(absolutePath, relativePath);
4961 MakeSlashPath(absolutePath);
4963 return node != null;