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 && stopItem.frame.addr && 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, false, true, null, no, normal, false);
907 EditBox editBox = editor.editBox;
908 if(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, false, 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, false, 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 if(!SetBreakpoint(bp, false))
1520 SetBreakpoint(bp, true);
1523 if(oldState == running)
1524 GdbExecContinue(false);
1527 ide.workspace.Save();
1530 void UpdateRemovedBreakpoint(Breakpoint bp)
1532 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::UpdateRemovedBreakpoint()");
1533 if(targeted && bp.inserted)
1535 DebuggerState oldState = state;
1540 GdbDebugBreak(true);
1543 UnsetBreakpoint(bp);
1546 if(oldState == running)
1547 GdbExecContinue(false);
1553 void ParseFrame(Frame frame, char * string)
1556 Array<char *> frameTokens { minAllocSize = 50 };
1557 Array<char *> argsTokens { minAllocSize = 50 };
1558 Array<char *> argumentTokens { minAllocSize = 50 };
1559 DebugListItem item { };
1562 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseFrame()");
1563 TokenizeList(string, ',', frameTokens);
1564 for(i = 0; i < frameTokens.count; i++)
1566 if(TokenizeListItem(frameTokens[i], item))
1568 StripQuotes(item.value, item.value);
1569 if(!strcmp(item.name, "level"))
1570 frame.level = atoi(item.value);
1571 else if(!strcmp(item.name, "addr"))
1572 frame.addr = item.value;
1573 else if(!strcmp(item.name, "func"))
1574 frame.func = item.value;
1575 else if(!strcmp(item.name, "args"))
1577 if(!strcmp(item.value, "[]"))
1578 frame.argsCount = 0;
1581 item.value = StripBrackets(item.value);
1582 TokenizeList(item.value, ',', argsTokens);
1583 for(j = 0; j < argsTokens.count; j++)
1585 argsTokens[j] = StripCurlies(argsTokens[j]);
1586 TokenizeList(argsTokens[j], ',', argumentTokens);
1587 for(k = 0; k < argumentTokens.count; k++)
1590 frame.args.Add(arg);
1591 if(TokenizeListItem(argumentTokens[k], item))
1593 if(!strcmp(item.name, "name"))
1595 StripQuotes(item.value, item.value);
1596 arg.name = item.value;
1598 else if(!strcmp(item.name, "value"))
1600 StripQuotes(item.value, item.value);
1601 arg.val = item.value;
1604 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame args item (", item.name, "=", item.value, ") is unheard of");
1607 _dpl(0, "Bad frame args item");
1609 argumentTokens.RemoveAll();
1611 frame.argsCount = argsTokens.count;
1612 argsTokens.RemoveAll();
1615 else if(!strcmp(item.name, "from"))
1616 frame.from = item.value;
1617 else if(!strcmp(item.name, "file"))
1618 frame.file = item.value;
1619 else if(!strcmp(item.name, "line"))
1620 frame.line = atoi(item.value);
1621 else if(!strcmp(item.name, "fullname"))
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))
1629 frame.absoluteFile = item.value; // ide.workspace.GetAbsolutePathFromRelative(frame.file);
1632 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "frame member (", item.name, "=", item.value, ") is unheard of");
1635 _dpl(0, "Bad frame");
1640 delete argumentTokens;
1644 Breakpoint GetBreakpointById(int id, bool * isInternal)
1646 Breakpoint bp = null;
1647 //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::GetBreakpointById(", id, ")");
1649 *isInternal = false;
1652 for(i : sysBPs; i.bp && i.bp.id == id)
1659 if(!bp && bpRunToCursor && bpRunToCursor.bp && bpRunToCursor.bp.id == id)
1663 for(i : ide.workspace.breakpoints; i.bp && i.bp.id == id)
1673 GdbDataBreakpoint ParseBreakpoint(char * string, Array<char *> outTokens)
1676 GdbDataBreakpoint bp { };
1677 DebugListItem item { };
1678 Array<char *> bpTokens { minAllocSize = 16 };
1679 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ParseBreakpoint()");
1680 string = StripCurlies(string);
1681 TokenizeList(string, ',', bpTokens);
1682 for(i = 0; i < bpTokens.count; i++)
1684 if(TokenizeListItem(bpTokens[i], item))
1686 StripQuotes(item.value, item.value);
1687 if(!strcmp(item.name, "number"))
1689 if(!strchr(item.value, '.'))
1690 bp.id = atoi(item.value);
1691 bp.number = item.value;
1693 else if(!strcmp(item.name, "type"))
1694 bp.type = item.value;
1695 else if(!strcmp(item.name, "disp"))
1696 bp.disp = item.value;
1697 else if(!strcmp(item.name, "enabled"))
1698 bp.enabled = (!strcmpi(item.value, "y"));
1699 else if(!strcmp(item.name, "addr"))
1701 if(outTokens && !strcmp(item.value, "<MULTIPLE>"))
1704 Array<GdbDataBreakpoint> bpArray = bp.multipleBPs = { };
1705 while(outTokens.count > ++c)
1707 GdbDataBreakpoint multBp = ParseBreakpoint(outTokens[c], null);
1708 bpArray.Add(multBp);
1712 bp.addr = item.value;
1714 else if(!strcmp(item.name, "func"))
1715 bp.func = item.value;
1716 else if(!strcmp(item.name, "file"))
1717 bp.file = item.value;
1718 else if(!strcmp(item.name, "fullname"))
1719 bp.fullname = item.value;
1720 else if(!strcmp(item.name, "line"))
1721 bp.line = atoi(item.value);
1722 else if(!strcmp(item.name, "at"))
1724 else if(!strcmp(item.name, "times"))
1725 bp.times = atoi(item.value);
1726 else if(!strcmp(item.name, "original-location") || !strcmp(item.name, "thread-groups"))
1727 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "breakpoint member (", item.name, "=", item.value, ") is ignored");
1729 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "breakpoint member (", item.name, "=", item.value, ") is unheard of");
1737 void ShowDebuggerViews()
1739 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ShowDebuggerViews()");
1740 ide.outputView.Show();
1741 ide.outputView.SelectTab(debug);
1742 ide.threadsView.Show();
1743 ide.callStackView.Show();
1744 ide.watchesView.Show();
1748 void HideDebuggerViews()
1750 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::HideDebuggerViews()");
1751 ide.RepositionWindows(true);
1754 bool ::GdbCommand(Time timeOut, bool focus, char * format, ...)
1756 bool result = false;
1760 // TODO: Improve this limit
1761 static char string[MAX_F_STRING*4];
1763 va_start(args, format);
1764 vsnprintf(string, sizeof(string), format, args);
1765 string[sizeof(string)-1] = 0;
1769 ide.debugger.serialSemaphore.TryWait();
1771 #ifdef GDB_DEBUG_CONSOLE
1772 _dpl2(_dpct, dplchan::gdbCommand, 0, string);
1774 #ifdef GDB_DEBUG_OUTPUT
1775 ide.outputView.gdbBox.Logf("cmd: %s\n", string);
1777 #ifdef GDB_DEBUG_GUI
1779 ide.gdbDialog.AddCommand(string);
1782 strcat(string,"\n");
1783 gdbHandle.Puts(string);
1786 Process_ShowWindows(targetProcessId);
1792 startTime = GetTime();
1795 if(ide.debugger.serialSemaphore.TryWait())
1802 if(GetTime() - startTime > timeOut)
1810 ide.debugger.serialSemaphore.Wait();
1819 bool ValidateBreakpoint(Breakpoint bp)
1821 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ValidateBreakpoint()");
1822 if(modules && bp.line && bp.bp)
1824 if(bp.bp.line != bp.line)
1830 ide.outputView.debugBox.Logf("WOULD HAVE -- Invalid breakpoint disabled: %s:%d\n", bp.relativeFilePath, bp.line);
1832 //UnsetBreakpoint(bp);
1833 //bp.enabled = false;
1839 ide.outputView.debugBox.Logf("Debugger Error: ValidateBreakpoint error\n");
1840 bp.line = bp.bp.line;
1847 void BreakpointsMaintenance()
1849 //_dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::BreakpointsMaintenance()");
1852 if(gdbExecution.suspendInternalBreakpoints)
1854 for(bp : sysBPs; bp.inserted)
1855 UnsetBreakpoint(bp);
1859 DirExpression objDir = ide.project.GetObjDir(currentCompiler, prjConfig, bitDepth);
1860 for(bp : sysBPs; !bp.inserted)
1862 bool insert = false;
1863 if(bp.type == internalModulesLoaded)
1865 char path[MAX_LOCATION];
1866 char name[MAX_LOCATION];
1867 char fixedModuleName[MAX_FILENAME];
1870 bool moduleLoadBlock = false;
1872 ReplaceSpaces(fixedModuleName, ide.project.moduleName);
1873 snprintf(name, sizeof(name),"%s.main.ec", fixedModuleName);
1874 name[sizeof(name)-1] = 0;
1875 strcpy(path, ide.workspace.projectDir);
1876 PathCatSlash(path, objDir.dir);
1877 PathCatSlash(path, name);
1878 f = FileOpen(path, read);
1881 for(lineNumber = 1; !f.Eof(); lineNumber++)
1883 if(f.GetLine(line, sizeof(line) - 1))
1885 bool moduleLoadLine;
1886 TrimLSpaces(line, line);
1887 moduleLoadLine = !strncmp(line, "eModule_Load", strlen("eModule_Load"));
1888 if(!moduleLoadBlock && moduleLoadLine)
1889 moduleLoadBlock = true;
1890 else if(moduleLoadBlock && !moduleLoadLine && strlen(line) > 0)
1896 char relative[MAX_LOCATION];
1897 bp.absoluteFilePath = path;
1898 MakePathRelative(path, ide.workspace.projectDir, relative);
1899 bp.relativeFilePath = relative;
1900 bp.line = lineNumber;
1906 else if(bp.type == internalModuleLoad)
1910 for(prj : ide.workspace.projects)
1912 if(!strcmp(prj.moduleName, "ecere"))
1914 ProjectNode node = prj.topNode.Find("instance.c", false);
1917 char path[MAX_LOCATION];
1918 char relative[MAX_LOCATION];
1919 node.GetFullFilePath(path);
1920 bp.absoluteFilePath = path;
1921 MakePathRelative(path, prj.topNode.path, relative);
1922 bp.relativeFilePath = relative;
1934 if(!SetBreakpoint(bp, false))
1935 SetBreakpoint(bp, true);
1941 if(userAction != runToCursor && bpRunToCursor && bpRunToCursor.inserted)
1942 UnsetBreakpoint(bpRunToCursor);
1943 if(bpRunToCursor && !bpRunToCursor.inserted)
1945 if(!SetBreakpoint(bpRunToCursor, false))
1946 SetBreakpoint(bpRunToCursor, true);
1949 if(ignoreBreakpoints)
1951 for(bp : ide.workspace.breakpoints; bp.inserted)
1952 UnsetBreakpoint(bp);
1956 for(bp : ide.workspace.breakpoints; !bp.inserted && bp.type == user)
1960 if(!SetBreakpoint(bp, false))
1961 SetBreakpoint(bp, true);
1970 bp.bp = GdbDataBreakpoint { };
1977 void UnsetBreakpoint(Breakpoint bp)
1979 char * s = null; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::UnsetBreakpoint(", s=bp.CopyLocationString(false), ") -- ", bp.type); delete s;
1980 if(symbols && bp.inserted)
1982 GdbCommand(0, false, "-break-delete %s", bp.bp.number);
1983 bp.inserted = false;
1989 bool SetBreakpoint(Breakpoint bp, bool removePath)
1991 char * s = null; _dpl2(_dpct, dplchan::debuggerBreakpoints, 0, "Debugger::SetBreakpoint(", s=bp.CopyLocationString(false), ", ", removePath ? "**** removePath(true) ****" : "", ") -- ", bp.type); delete s;
1992 breakpointError = false;
1993 if(symbols && bp.enabled && (!bp.project || bp.project.GetTargetType(bp.project.config) == staticLibrary || bp.project == ide.project || projectsLibraryLoaded[bp.project.name]))
1995 sentBreakInsert = true;
1997 GdbCommand(0, false, "-break-insert *%s", bp.address);
2000 char * location = bp.CopyLocationString(removePath);
2001 GdbCommand(0, false, "-break-insert %s", location);
2004 if(!breakpointError)
2006 char * address = null;
2007 if(bpItem && bpItem.multipleBPs && bpItem.multipleBPs.count)
2010 GdbDataBreakpoint first = null;
2011 for(n : bpItem.multipleBPs)
2013 if(!fstrcmp(n.fullname, bp.absoluteFilePath) && !first)
2023 GdbCommand(0, false, "-break-disable %s", n.number);
2027 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error breakpoint already disabled.");
2032 address = CopyString(first.addr);
2033 bpItem.addr = first.addr;
2034 bpItem.func = first.func;
2035 bpItem.file = first.file;
2036 bpItem.fullname = first.fullname;
2037 bpItem.line = first.line;
2038 //bpItem.thread-groups = first.thread-groups;*/
2041 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints all disabled.");
2043 _dpl2(_dpct, dplchan::debuggerProblem, 0, "Debugger::SetBreakpoint -- error multiple breakpoints in exact same file not supported.");
2044 bpItem.multipleBPs.Free();
2045 delete bpItem.multipleBPs;
2050 bp.inserted = (bp.bp && bp.bp.number && strcmp(bp.bp.number, "0"));
2052 ValidateBreakpoint(bp);
2056 UnsetBreakpoint(bp);
2057 bp.address = address;
2059 SetBreakpoint(bp, removePath);
2062 return !breakpointError;
2069 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbGetStack()");
2071 stackFrames.Free(Frame::Free);
2072 GdbCommand(0, false, "-stack-info-depth");
2074 GdbCommand(0, false, "-stack-info-depth 192");
2075 if(frameCount && frameCount <= 192)
2076 GdbCommand(0, false, "-stack-list-frames 0 %d", Min(frameCount-1, 191));
2079 GdbCommand(0, false, "-stack-list-frames 0 %d", Min(frameCount-1, 95));
2080 GdbCommand(0, false, "-stack-list-frames %d %d", Max(frameCount - 96, 96), frameCount - 1);
2082 GdbCommand(0, false, "");
2087 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbTargetSet()");
2090 char escaped[MAX_LOCATION];
2091 strescpy(escaped, targetFile);
2092 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
2099 const char *vgdbCommand = "/usr/bin/vgdb"; // TODO: vgdb command config option
2100 //GdbCommand(0, false, "-target-select remote | %s --pid=%d", "vgdb", targetProcessId);
2101 printf("target remote | %s --pid=%d\n", vgdbCommand, targetProcessId);
2102 GdbCommand(0, false, "target remote | %s --pid=%d", vgdbCommand, targetProcessId); // TODO: vgdb command config option
2105 GdbCommand(0, false, "info target"); //GDB/MI Missing Implementation -file-list-symbol-files and -file-list-exec-sections
2107 /*for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
2108 GdbCommand(0, false, "-environment-directory \"%s\"", prj.topNode.path);*/
2110 for(dir : ide.workspace.sourceDirs; dir && dir[0])
2112 bool interference = false;
2113 for(prj : ide.workspace.projects)
2115 if(!fstrcmp(prj.topNode.path, dir))
2117 interference = true;
2121 if(!interference && dir[0])
2122 GdbCommand(0, false, "-environment-directory \"%s\"", dir);
2130 /*void GdbTargetRelease()
2134 BreakpointsDeleteAll();
2135 GdbCommand(0, false, "file"); //GDB/MI Missing Implementation -target-detach
2141 void GdbDebugBreak(bool internal)
2143 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbDebugBreak()");
2147 breakType = DebuggerAction::internal;
2149 if(ide) ide.Update(null);
2151 if(Process_Break(targetProcessId)) //GdbCommand(0, false, "-exec-interrupt");
2152 serialSemaphore.Wait();
2155 _ChangeState(loaded);
2156 targetProcessId = 0;
2161 ide.outputView.debugBox.Logf("Debugger Error: GdbDebugBreak with not target id should never happen\n");
2166 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecRun()");
2171 ShowDebuggerViews();
2173 GdbExecContinue(true);
2174 else if(!GdbCommand(3, true, "-exec-run"))
2175 gdbExecution = none;
2178 void GdbExecContinue(bool focus)
2180 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecContinue()");
2183 GdbCommand(0, focus, "-exec-continue");
2188 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecNext()");
2189 gdbExecution = next;
2191 GdbCommand(0, true, "-exec-next");
2194 void GdbExecUntil(char * absoluteFilePath, int lineNumber)
2196 char relativeFilePath[MAX_LOCATION];
2197 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecUntil()");
2198 gdbExecution = until;
2200 if(absoluteFilePath)
2202 WorkspaceGetRelativePath(absoluteFilePath, relativeFilePath, null);
2203 GdbCommand(0, true, "-exec-until %s:%d", relativeFilePath, lineNumber);
2206 GdbCommand(0, true, "-exec-until");
2209 void GdbExecAdvance(char * absoluteFilePathOrLocation, int lineNumber)
2211 char relativeFilePath[MAX_LOCATION];
2212 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecAdvance()");
2213 gdbExecution = advance;
2217 WorkspaceGetRelativePath(absoluteFilePathOrLocation, relativeFilePath, null);
2218 GdbCommand(0, true, "advance %s:%d", relativeFilePath, lineNumber); // should use -exec-advance -- GDB/MI implementation missing
2221 GdbCommand(0, true, "advance %s", absoluteFilePathOrLocation); // should use -exec-advance -- GDB/MI implementation missing
2226 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecStep()");
2227 gdbExecution = step;
2229 GdbCommand(0, true, "-exec-step");
2232 void GdbExecFinish()
2234 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecFinish()");
2235 gdbExecution = finish;
2237 GdbCommand(0, true, "-exec-finish");
2240 void GdbExecCommon()
2242 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExecCommon()");
2243 BreakpointsMaintenance();
2246 #ifdef GDB_DEBUG_GUI
2247 void SendGDBCommand(char * command)
2249 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::SendGDBCommand()");
2250 DebuggerState oldState = state;
2255 GdbDebugBreak(true);
2258 GdbCommand(0, false, command);
2261 if(oldState == running)
2262 GdbExecContinue(false);
2266 void ClearBreakDisplay()
2268 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ClearBreakDisplay()");
2270 activeFrameLevel = -1;
2280 stackFrames.Free(Frame::Free);
2281 ide.callStackView.Clear();
2282 ide.threadsView.Clear();
2288 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbAbortExec()");
2290 GdbCommand(0, false, "-interpreter-exec console \"kill\""); // should use -exec-abort -- GDB/MI implementation incomplete
2294 bool GdbInit(CompilerConfig compiler, ProjectConfig config, int bitDepth, bool useValgrind)
2297 char oldDirectory[MAX_LOCATION];
2298 char tempPath[MAX_LOCATION];
2299 char command[MAX_F_STRING*4];
2300 Project project = ide.project;
2301 DirExpression targetDirExp = project.GetTargetDir(compiler, config, bitDepth);
2302 PathBackup pathBackup { };
2303 Map<String, String> envBackup { };
2305 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbInit()");
2306 if(currentCompiler != compiler)
2308 delete currentCompiler;
2309 currentCompiler = compiler;
2310 incref currentCompiler;
2313 this.bitDepth = bitDepth;
2314 usingValgrind = useValgrind;
2316 _ChangeState(loaded);
2318 sentBreakInsert = false;
2319 breakpointError = false;
2320 ignoreBreakpoints = false;
2325 projectsLibraryLoaded.Free();
2327 ide.outputView.ShowClearSelectTab(debug);
2328 ide.outputView.debugBox.Logf($"Starting debug mode\n");
2330 #ifdef GDB_DEBUG_OUTPUT
2331 ide.outputView.gdbBox.Logf("run: Starting GDB\n");
2334 strcpy(tempPath, ide.workspace.projectDir);
2335 PathCatSlash(tempPath, targetDirExp.dir);
2337 targetDir = CopyString(tempPath);
2338 project.CatTargetFileName(tempPath, compiler, config);
2340 targetFile = CopyString(tempPath);
2342 GetWorkingDir(oldDirectory, MAX_LOCATION);
2343 if(ide.workspace.debugDir && ide.workspace.debugDir[0])
2345 char temp[MAX_LOCATION];
2346 strcpy(temp, ide.workspace.projectDir);
2347 PathCatSlash(temp, ide.workspace.debugDir);
2348 ChangeWorkingDir(temp);
2351 ChangeWorkingDir(ide.workspace.projectDir);
2353 ide.SetPath(true, compiler, config, bitDepth);
2355 // TODO: This pollutes the environment, but at least it works
2356 // It shouldn't really affect the IDE as the PATH gets restored and other variables set for testing will unlikely cause problems
2357 // What is the proper solution for this? DualPipeOpenEnv?
2358 // gdb set environment commands don't seem to take effect
2359 for(e : ide.workspace.environmentVars)
2361 // Backing up the environment variables until we use DualPipeOpenEnv()
2362 envBackup[e.name] = CopyString(getenv(e.name));
2363 SetEnvironment(e.name, e.string);
2368 char * clArgs = ide.workspace.commandLineArgs;
2369 const char *valgrindCommand = "valgrind"; // TODO: valgrind command config option //TODO: valgrind options
2370 ValgrindLeakCheck vgLeakCheck = ide.workspace.vgLeakCheck;
2371 int vgRedzoneSize = ide.workspace.vgRedzoneSize;
2372 bool vgTrackOrigins = ide.workspace.vgTrackOrigins;
2373 vgLogFile = CreateTemporaryFile(vgLogPath, "ecereidevglog");
2377 vgLogThread.Create();
2381 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't open temporary log file for Valgrind output\n");
2384 if(result && !CheckCommandAvailable(valgrindCommand))
2386 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Command %s for Valgrind is not available.\n", valgrindCommand);
2391 char * vgRedzoneSizeFlag = vgRedzoneSize == -1 ? "" : PrintString(" --redzone-size=", vgRedzoneSize);
2392 sprintf(command, "%s --vgdb=yes --vgdb-error=0 --log-file=%s --leak-check=%s%s --track-origins=%s %s%s%s",
2393 valgrindCommand, vgLogPath, (char*)vgLeakCheck, vgRedzoneSizeFlag, vgTrackOrigins ? "yes" : "no", targetFile, clArgs ? " " : "", clArgs ? clArgs : "");
2394 if(vgRedzoneSize != -1)
2395 delete vgRedzoneSizeFlag;
2396 vgTargetHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
2399 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start Valgrind\n");
2405 incref vgTargetHandle;
2406 vgTargetThread.Create();
2408 targetProcessId = vgTargetHandle.GetProcessID();
2409 waitingForPID = false;
2410 if(!targetProcessId)
2412 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't get Valgrind process ID\n");
2419 serialSemaphore.Wait();
2426 if(compiler.targetPlatform == win32)
2429 #if !((defined(__WORDSIZE) && __WORDSIZE == 8) || defined(__x86_64__))
2432 bitDepth == 32 ? "i686-w64-mingw32-gdb" : "gdb"); // x86_64-w64-mingw32-gdb
2435 // We really should have a box to select GDB in the compiler/toolchain options
2436 strcpy(command, "gdb");
2437 if(!CheckCommandAvailable(command))
2439 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Command %s for GDB is not available.\n", command);
2444 strcat(command, " -n -silent --interpreter=mi2"); //-async //\"%s\"
2446 gdbHandle = DualPipeOpen(PipeOpenMode { output = true, /*error = true, */input = true }, command);
2449 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't start GDB\n");
2459 gdbProcessId = gdbHandle.GetProcessID();
2462 ide.outputView.debugBox.Logf($"Debugger Fatal Error: Couldn't get GDB process ID\n");
2469 serialSemaphore.Wait();
2472 GdbCommand(0, false, "-gdb-set verbose off");
2473 //GdbCommand(0, false, "-gdb-set exec-done-display on");
2474 GdbCommand(0, false, "-gdb-set step-mode off");
2475 GdbCommand(0, false, "-gdb-set unwindonsignal on");
2476 //GdbCommand(0, false, "-gdb-set shell on");
2477 GdbCommand(0, false, "set print elements 992");
2478 GdbCommand(0, false, "-gdb-set backtrace limit 100000");
2482 //_ChangeState(terminated);
2488 #if defined(__unix__)
2490 CreateTemporaryDir(progFifoDir, "ecereide");
2491 strcpy(progFifoPath, progFifoDir);
2492 PathCat(progFifoPath, "ideprogfifo");
2493 if(!mkfifo(progFifoPath, 0600))
2495 //fileCreated = true;
2500 ide.outputView.debugBox.Logf(createFIFOMsg, progFifoPath);
2507 progThread.terminate = false;
2508 progThread.Create();
2512 #if defined(__WIN32__)
2513 GdbCommand(0, false, "-gdb-set new-console on");
2516 #if defined(__unix__)
2518 GdbCommand(0, false, "-inferior-tty-set %s", progFifoPath);
2522 GdbCommand(0, false, "-gdb-set args %s", ide.workspace.commandLineArgs ? ide.workspace.commandLineArgs : "");
2524 for(e : ide.workspace.environmentVars)
2526 GdbCommand(0, false, "set environment %s=%s", e.name, e.string);
2531 ChangeWorkingDir(oldDirectory);
2535 SetEnvironment(&e, e);
2544 delete targetDirExp;
2550 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbExit()");
2551 if(gdbHandle && gdbProcessId)
2554 GdbCommand(0, false, "-gdb-exit");
2563 vgLogFile.CloseInput();
2564 if(vgLogThread.created)
2574 vgTargetThread.Wait();
2584 _ChangeState(terminated); // this state change seems to be superfluous, is it safety for something?
2590 for(bp : ide.workspace.breakpoints)
2596 bpRunToCursor.Reset();
2598 ide.outputView.debugBox.Logf($"Debugging stopped\n");
2599 ClearBreakDisplay();
2602 #if defined(__unix__)
2603 if(!usingValgrind && FileExists(progFifoPath)) //fileCreated)
2605 progThread.terminate = true;
2608 fifoFile.CloseInput();
2614 DeleteFile(progFifoPath);
2615 progFifoPath[0] = '\0';
2621 bool WatchesLinkCodeEditor()
2623 bool goodFrame = activeFrame && activeFrame.absoluteFile;
2624 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesLinkCodeEditor()");
2625 if(codeEditor && (!goodFrame || fstrcmp(codeEditor.fileName, activeFrame.absoluteFile)))
2626 WatchesReleaseCodeEditor();
2628 if(!codeEditor && goodFrame)
2630 codeEditor = (CodeEditor)ide.OpenFile(activeFrame.absoluteFile, false, false, null, no, normal, false);
2633 codeEditor.inUseDebug = true;
2637 return codeEditor != null;
2640 void WatchesReleaseCodeEditor()
2642 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::WatchesReleaseCodeEditor()");
2645 codeEditor.inUseDebug = false;
2646 if(!codeEditor.visible)
2647 codeEditor.Destroy(0);
2652 bool ResolveWatch(Watch wh)
2654 bool result = false;
2656 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::ResolveWatch()");
2668 char watchmsg[MAX_F_STRING];
2669 if(state == stopped && !codeEditor)
2670 wh.value = CopyString($"No source file found for selected frame");
2671 //if(codeEditor && state == stopped || state != stopped)
2674 Module backupPrivateModule;
2675 Context backupContext;
2676 Class backupThisClass;
2680 backupPrivateModule = GetPrivateModule();
2681 backupContext = GetCurrentContext();
2682 backupThisClass = GetThisClass();
2685 SetPrivateModule(codeEditor.privateModule);
2686 SetCurrentContext(codeEditor.globalContext);
2687 SetTopContext(codeEditor.globalContext);
2688 SetGlobalContext(codeEditor.globalContext);
2689 SetGlobalData(&codeEditor.globalData);
2692 exp = ParseExpressionString(wh.expression);
2694 if(exp && !parseError)
2696 char expString[4096];
2698 PrintExpression(exp, expString);
2700 if(GetPrivateModule())
2703 DebugFindCtxTree(codeEditor.ast, activeFrame.line, 0);
2704 ProcessExpressionType(exp);
2706 wh.type = exp.expType;
2709 DebugComputeExpression(exp);
2710 if(ExpressionIsError(exp))
2712 GDBFallBack(exp, expString);
2715 /*if(exp.hasAddress)
2717 char temp[MAX_F_STRING];
2718 sprintf(temp, "0x%x", exp.address);
2719 wh.address = CopyString(temp);
2720 // wh.address = CopyStringf("0x%x", exp.address);
2725 Type dataType = exp.expType;
2728 char temp[MAX_F_STRING];
2729 switch(dataType.kind)
2732 sprintf(temp, "%i", exp.val.c);
2735 sprintf(temp, "%i", exp.val.s);
2740 sprintf(temp, "%i", exp.val.i);
2743 sprintf(temp, "%i", exp.val.i64);
2746 sprintf(temp, "%i", exp.val.p);
2751 long v = (long)exp.val.f;
2752 sprintf(temp, "%i", v);
2757 long v = (long)exp.val.d;
2758 sprintf(temp, "%i", v);
2763 wh.intVal = CopyString(temp);
2764 switch(dataType.kind)
2767 sprintf(temp, "0x%x", exp.val.c);
2770 sprintf(temp, "0x%x", exp.val.s);
2774 sprintf(temp, "0x%x", exp.val.i);
2777 sprintf(temp, "0x%x", exp.val.i64);
2780 sprintf(temp, "0x%x", exp.val.i64);
2783 sprintf(temp, "0x%x", exp.val.p);
2788 long v = (long)exp.val.f;
2789 sprintf(temp, "0x%x", v);
2794 long v = (long)exp.val.d;
2795 sprintf(temp, "0x%x", v);
2800 wh.hexVal = CopyString(temp);
2801 switch(dataType.kind)
2804 sprintf(temp, "0o%o", exp.val.c);
2807 sprintf(temp, "0o%o", exp.val.s);
2811 sprintf(temp, "0o%o", exp.val.i);
2814 sprintf(temp, "0o%o", exp.val.i64);
2817 sprintf(temp, "0o%o", exp.val.i64);
2820 sprintf(temp, "0o%o", exp.val.p);
2825 long v = (long)exp.val.f;
2826 sprintf(temp, "0o%o", v);
2831 long v = (long)exp.val.d;
2832 sprintf(temp, "0o%o", v);
2837 wh.octVal = CopyString(temp);
2840 // WHATS THIS HERE ?
2841 if(exp.type == constantExp && exp.constant)
2842 wh.constant = CopyString(exp.constant);
2848 case symbolErrorExp:
2849 snprintf(watchmsg, sizeof(watchmsg), $"Symbol \"%s\" not found", exp.identifier.string);
2851 case structMemberSymbolErrorExp:
2852 // todo get info as in next case (ExpClassMemberSymbolError)
2853 snprintf(watchmsg, sizeof(watchmsg), $"Error: Struct member not found for \"%s\"", wh.expression);
2855 case classMemberSymbolErrorExp:
2858 Expression memberExp = exp.member.exp;
2859 Identifier memberID = exp.member.member;
2860 Type type = memberExp.expType;
2863 _class = (memberID && memberID.classSym) ? memberID.classSym.registered : ((type.kind == classType && type._class) ? type._class.registered : null);
2866 char string[256] = "";
2868 PrintTypeNoConst(type, string, false, true);
2869 classSym = FindClass(string);
2870 _class = classSym ? classSym.registered : null;
2873 snprintf(watchmsg, sizeof(watchmsg), $"Member \"%s\" not found in class \"%s\"", memberID ? memberID.string : "", _class.name);
2875 snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in unregistered class? (Should never get this message)", memberID ? memberID.string : "");
2878 snprintf(watchmsg, sizeof(watchmsg), "Member \"%s\" not found in no type? (Should never get this message)", memberID ? memberID.string : "");
2881 case memoryErrorExp:
2882 // Need to ensure when set to memoryErrorExp, constant is set
2883 snprintf(watchmsg, sizeof(watchmsg), $"Memory can't be read at %s", /*(exp.type == constantExp) ? */exp.constant /*: null*/);
2885 case dereferenceErrorExp:
2886 snprintf(watchmsg, sizeof(watchmsg), $"Dereference failure for \"%s\"", wh.expression);
2888 case unknownErrorExp:
2889 snprintf(watchmsg, sizeof(watchmsg), $"Unknown error for \"%s\"", wh.expression);
2891 case noDebuggerErrorExp:
2892 snprintf(watchmsg, sizeof(watchmsg), $"Debugger required for symbol evaluation in \"%s\"", wh.expression);
2894 case debugStateErrorExp:
2895 snprintf(watchmsg, sizeof(watchmsg), $"Incorrect debugger state for symbol evaluation in \"%s\"", wh.expression);
2898 snprintf(watchmsg, sizeof(watchmsg), $"Null type for \"%s\"", wh.expression);
2902 // Temporary Code for displaying Strings
2903 if((exp.expType && ((exp.expType.kind == pointerType ||
2904 exp.expType.kind == arrayType) && exp.expType.type.kind == charType)) ||
2905 (wh.type && wh.type.kind == classType && wh.type._class &&
2906 wh.type._class.registered && wh.type._class.registered.type == normalClass &&
2907 !strcmp(wh.type._class.registered.name, "String")))
2910 if(exp.expType.kind != arrayType || exp.hasAddress)
2916 //char temp[MAX_F_STRING * 32];
2918 ExpressionType evalError = dummyExp;
2919 /*if(exp.expType.kind == arrayType)
2920 sprintf(temp, "(char*)0x%x", exp.address);
2922 sprintf(temp, "(char*)%s", exp.constant);*/
2924 //evaluation = Debugger::EvaluateExpression(temp, &evalError);
2925 // address = strtoul(exp.constant, null, 0);
2926 address = _strtoui64(exp.constant, null, 0);
2927 //_dpl(0, "0x", address);
2928 // snprintf(value, sizeof(value), "0x%08x ", address);
2930 if(address > 0xFFFFFFFFLL)
2931 snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%016I64x " : "0x%016llx ", address);
2933 snprintf(value, sizeof(value), (GetRuntimePlatform() == win32) ? "0x%08I64x " : "0x%08llx ", address);
2934 value[sizeof(value)-1] = 0;
2937 strcat(value, $"Null string");
2941 len = strlen(value);
2943 while(!string && size > 2)
2945 string = GdbReadMemory(address, size);
2948 if(string && string[0])
2951 if(UTF8Validate(string))
2956 for(c = 0; (ch = string[c]) && c<4096; c++)
2959 value[len++] = '\0';
2964 ISO8859_1toUTF8(string, value + len, 4096 - len - 30);
2965 strcat(value, ") (ISO8859-1)");
2972 strcat(value, $"Empty string");
2976 strcat(value, $"Couldn't read memory");
2978 wh.value = CopyString(value);
2981 else if(wh.type && wh.type.kind == classType && wh.type._class &&
2982 wh.type._class.registered && wh.type._class.registered.type == enumClass)
2984 uint64 value = strtoul(exp.constant, null, 0);
2985 Class enumClass = eSystem_FindClass(GetPrivateModule(), wh.type._class.registered.name);
2986 EnumClassData enumeration = (EnumClassData)enumClass.data;
2988 for(item = enumeration.values.first; item; item = item.next)
2989 if((int)item.data == value)
2992 wh.value = CopyString(item.name);
2994 wh.value = CopyString($"Invalid Enum Value");
2997 else if(wh.type && (wh.type.kind == charType || (wh.type.kind == classType && wh.type._class &&
2998 wh.type._class.registered && !strcmp(wh.type._class.registered.fullName, "ecere::com::unichar"))) )
3005 if(exp.constant[0] == '\'')
3007 if((int)((byte *)exp.constant)[1] > 127)
3010 value = UTF8GetChar(exp.constant + 1, &nb);
3011 if(nb < 2) value = exp.constant[1];
3012 signedValue = value;
3016 signedValue = exp.constant[1];
3018 // Precomp Syntax error with boot strap here:
3019 byte b = (byte)(char)signedValue;
3020 value = (unichar) b;
3026 if(wh.type.kind == charType && wh.type.isSigned)
3028 signedValue = (int)(char)strtol(exp.constant, null, 0);
3030 // Precomp Syntax error with boot strap here:
3031 byte b = (byte)(char)signedValue;
3032 value = (unichar) b;
3037 value = (uint)strtoul(exp.constant, null, 0);
3038 signedValue = (int)value;
3042 UTF32toUTF8Len(&value, 1, charString, 5);
3044 snprintf(string, sizeof(string), "\'\\0' (0)");
3045 else if(value == '\t')
3046 snprintf(string, sizeof(string), "\'\\t' (%d)", value);
3047 else if(value == '\n')
3048 snprintf(string, sizeof(string), "\'\\n' (%d)", value);
3049 else if(value == '\r')
3050 snprintf(string, sizeof(string), "\'\\r' (%d)", value);
3051 else if(wh.type.kind == charType && wh.type.isSigned)
3052 snprintf(string, sizeof(string), "\'%s\' (%d)", charString, signedValue);
3053 else if(value > 256 || wh.type.kind != charType)
3055 if(value > 0x10FFFF || !GetCharCategory(value))
3056 snprintf(string, sizeof(string), $"Invalid Unicode Keypoint (0x%08X)", value);
3058 snprintf(string, sizeof(string), "\'%s\' (U+%04X)", charString, value);
3061 snprintf(string, sizeof(string), "\'%s\' (%d)", charString, value);
3062 string[sizeof(string)-1] = 0;
3064 wh.value = CopyString(string);
3069 wh.value = CopyString(exp.constant);
3076 wh.value = PrintHexUInt64(exp.address);
3081 char tempString[256];
3082 if(exp.member.memberType == propertyMember)
3083 snprintf(watchmsg, sizeof(watchmsg), $"Missing property evaluation support for \"%s\"", wh.expression);
3085 snprintf(watchmsg, sizeof(watchmsg), $"Evaluation failed for \"%s\" of type \"%s\"", wh.expression,
3086 exp.type.OnGetString(tempString, null, null));
3092 snprintf(watchmsg, sizeof(watchmsg), $"Invalid expression: \"%s\"", wh.expression);
3093 if(exp) FreeExpression(exp);
3096 SetPrivateModule(backupPrivateModule);
3097 SetCurrentContext(backupContext);
3098 SetTopContext(backupContext);
3099 SetGlobalContext(backupContext);
3100 SetThisClass(backupThisClass);
3103 // wh.value = CopyString("No source file found for selected frame");
3105 watchmsg[sizeof(watchmsg)-1] = 0;
3107 wh.value = CopyString(watchmsg);
3109 ide.watchesView.UpdateWatch(wh);
3113 void EvaluateWatches()
3115 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateWatches()");
3116 WatchesLinkCodeEditor();
3117 if(state == stopped)
3119 for(wh : ide.workspace.watches)
3124 char * ::GdbEvaluateExpression(char * expression)
3126 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::GdbEvaluateExpression(", expression, ")");
3129 GdbCommand(0, false, "-data-evaluate-expression \"%s\"", expression);
3131 ide.outputView.debugBox.Logf("Debugger Error: GdbEvaluateExpression\n");
3135 // to be removed... use GdbReadMemory that returns a byte array instead
3136 char * ::GdbReadMemoryString(uint64 address, int size, char format, int rows, int cols)
3138 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemoryString(", address, ")");
3143 _dpl(0, "GdbReadMemoryString called with size = 0!");
3145 // GdbCommand(0, false, "-data-read-memory 0x%08x %c, %d, %d, %d", address, format, size, rows, cols);
3146 if(GetRuntimePlatform() == win32)
3147 GdbCommand(0, false, "-data-read-memory 0x%016I64x %c, %d, %d, %d", address, format, size, rows, cols);
3149 GdbCommand(0, false, "-data-read-memory 0x%016llx %c, %d, %d, %d", address, format, size, rows, cols);
3151 ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemoryString\n");
3155 byte * ::GdbReadMemory(uint64 address, int bytes)
3157 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbReadMemory(", address, ")");
3160 //GdbCommand(0, false, "-data-read-memory 0x%08x %c, 1, 1, %d", address, 'u', bytes);
3161 if(GetRuntimePlatform() == win32)
3162 GdbCommand(0, false, "-data-read-memory 0x%016I64x %c, 1, 1, %d", address, 'u', bytes);
3164 GdbCommand(0, false, "-data-read-memory 0x%016llx %c, 1, 1, %d", address, 'u', bytes);
3167 _dpl(0, "GdbReadMemory called with bytes = 0!");
3170 ide.outputView.debugBox.Logf("Debugger Error: GdbReadMemory\n");
3171 else if(eval.result && strcmp(eval.result, "N/A"))
3173 byte * result = new byte[bytes];
3174 byte * string = eval.result;
3178 result[c++] = (byte)strtol(string, &string, 10);
3194 bool BreakpointHit(GdbDataStop stopItem, Breakpoint bpInternal, Breakpoint bpUser)
3197 char * s1 = null; char * s2 = null;
3198 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::BreakpointHit(",
3199 "bpInternal(", bpInternal ? s1=bpInternal.CopyLocationString(false) : null, "), ",
3200 "bpUser(", bpUser ? s2=bpUser.CopyLocationString(false) : null, ")) -- ",
3201 "ignoreBreakpoints(", ignoreBreakpoints, "), ",
3202 "hitCursorBreakpoint(", bpUser && bpUser.type == runToCursor, ")");
3203 delete s1; delete s2;
3207 bool conditionMet = true;
3208 if(bpUser.condition)
3210 if(WatchesLinkCodeEditor())
3211 conditionMet = ResolveWatch(bpUser.condition);
3213 conditionMet = false;
3228 if(stopItem.frame.line && bpUser.line != stopItem.frame.line)
3230 // updating user breakpoint on hit location difference
3231 // todo, print something?
3232 bpUser.line = stopItem.frame.line;
3233 ide.breakpointsView.UpdateBreakpoint(bpUser.row);
3234 ide.workspace.Save();
3237 ide.breakpointsView.UpdateBreakpoint(bpUser.row);
3242 if(bpInternal.type == internalModulesLoaded)
3244 if(userAction == stepOver)
3246 if((bpInternal.type == internalEntry && ((intBpMain && intBpMain.inserted) || (intBpWinMain && intBpWinMain.inserted))) ||
3247 (bpInternal.type == internalMain && intBpWinMain && intBpWinMain.inserted))
3250 if(!bpUser && !userAction.breaksOnInternalBreakpoint)
3252 if(userAction == stepOut)
3253 StepOut(ignoreBreakpoints);
3259 if(!bpUser && !bpInternal)
3265 void ValgrindTargetThreadExit()
3267 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ValgrindTargetThreadExit()");
3270 vgTargetHandle.Wait();
3271 delete vgTargetHandle;
3273 HandleExit(null, null);
3276 void GdbThreadExit()
3278 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::GdbThreadExit()");
3279 if(state != terminated)
3281 _ChangeState(terminated);
3282 targetProcessId = 0;
3283 ClearBreakDisplay();
3288 serialSemaphore.Release();
3293 ide.outputView.debugBox.Logf($"Debugger Fatal Error: GDB lost\n");
3294 ide.outputView.debugBox.Logf($"Debugging stopped\n");
3296 HideDebuggerViews();
3298 //_ChangeState(terminated);
3302 void GdbThreadMain(char * output)
3306 Array<char *> outTokens { minAllocSize = 50 };
3307 Array<char *> subTokens { minAllocSize = 50 };
3308 DebugListItem item { };
3309 DebugListItem item2 { };
3310 bool setWaitingForPID = false;
3312 #if defined(GDB_DEBUG_CONSOLE) || defined(GDB_DEBUG_GUI)
3313 #ifdef GDB_DEBUG_CONSOLE
3314 // _dpl2(_dpct, dplchan::gdbOutput, 0, output);
3317 #ifdef GDB_DEBUG_OUTPUT
3319 int len = strlen(output);
3327 for(c = 0; c < len / 1024; c++)
3329 strncpy(tmp, start, 1024);
3330 ide.outputView.gdbBox.Logf("out: %s\n", tmp);
3333 ide.outputView.gdbBox.Logf("out: %s\n", start);
3337 ide.outputView.gdbBox.Logf("out: %s\n", output);
3341 #ifdef GDB_DEBUG_CONSOLE
3342 strcpy(lastGdbOutput, output);
3344 #ifdef GDB_DEBUG_GUI
3345 if(ide.gdbDialog) ide.gdbDialog.AddOutput(output);
3352 if(strstr(output, "No debugging symbols found") || strstr(output, "(no debugging symbols found)"))
3355 ide.outputView.debugBox.Logf($"Target doesn't contain debug information!\n");
3358 if(!entryPoint && (t = strstr(output, "Entry point:")))
3360 char * addr = t + strlen("Entry point:");
3362 if(*t++ == ' ' && *t++ == '0' && *t == 'x')
3365 while(isxdigit(*++t));
3367 for(bp : sysBPs; bp.type == internalEntry)
3370 bp.enabled = entryPoint = true;
3378 if(TokenizeList(output, ',', outTokens) && !strcmp(outTokens[0], "^done"))
3380 //if(outTokens.count == 1)
3385 _ChangeState(loaded);
3386 targetProcessId = 0;
3387 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
3389 if(!strcmp(item.name, "reason"))
3391 char * reason = item.value;
3392 StripQuotes(reason, reason);
3393 if(!strcmp(reason, "exited-normally") || !strcmp(reason, "exited") || !strcmp(reason, "exited-signalled"))
3396 if(outTokens.count > 2 && TokenizeListItem(outTokens[2], item2))
3398 StripQuotes(item2.value, item2.value);
3399 if(!strcmp(item2.name, "exit-code"))
3400 exitCode = item2.value;
3406 HandleExit(reason, exitCode);
3410 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "kill reply (", item.name, "=", item.value, ") is unheard of");
3413 HandleExit(null, null);
3416 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
3418 if(!strcmp(item.name, "bkpt"))
3420 sentBreakInsert = false;
3426 bpItem = ParseBreakpoint(item.value, outTokens);
3427 //breakType = bpValidation;
3429 else if(!strcmp(item.name, "depth"))
3431 StripQuotes(item.value, item.value);
3432 frameCount = atoi(item.value);
3434 stackFrames.Free(Frame::Free);
3436 else if(!strcmp(item.name, "stack"))
3439 if(stackFrames.count)
3440 ide.callStackView.Logf("...\n");
3443 item.value = StripBrackets(item.value);
3444 TokenizeList(item.value, ',', subTokens);
3445 for(i = 0; i < subTokens.count; i++)
3447 if(TokenizeListItem(subTokens[i], item))
3449 if(!strcmp(item.name, "frame"))
3452 stackFrames.Add(frame);
3453 item.value = StripCurlies(item.value);
3454 ParseFrame(frame, item.value);
3455 if(frame.file && frame.from)
3456 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "unexpected frame file and from members present");
3460 if(activeFrameLevel == -1)
3462 if(ide.projectView.IsModuleInProject(frame.file));
3464 if(frame.level != 0)
3466 //stopItem.frame = frame;
3467 breakType = selectFrame;
3470 activeFrame = frame;
3471 activeFrameLevel = frame.level;
3474 ide.callStackView.Logf("%3d ", frame.level);
3475 if(!strncmp(frame.func, "__ecereMethod_", strlen("__ecereMethod_")))
3476 ide.callStackView.Logf($"%s Method, %s:%d\n", &frame.func[strlen("__ecereMethod_")], (s = CopySystemPath(frame.file)), frame.line);
3477 else if(!strncmp(frame.func, "__ecereProp_", strlen("__ecereProp_")))
3478 ide.callStackView.Logf($"%s Property, %s:%d\n", &frame.func[strlen("__ecereProp_")], (s = CopySystemPath(frame.file)), frame.line);
3479 else if(!strncmp(frame.func, "__ecereConstructor_", strlen("__ecereConstructor_")))
3480 ide.callStackView.Logf($"%s Constructor, %s:%d\n", &frame.func[strlen("__ecereConstructor_")], (s = CopySystemPath(frame.file)), frame.line);
3481 else if(!strncmp(frame.func, "__ecereDestructor_", strlen("__ecereDestructor_")))
3482 ide.callStackView.Logf($"%s Destructor, %s:%d\n", &frame.func[strlen("__ecereDestructor_")], (s = CopySystemPath(frame.file)), frame.line);
3484 ide.callStackView.Logf($"%s Function, %s:%d\n", frame.func, (s = CopySystemPath(frame.file)), frame.line);
3489 ide.callStackView.Logf("%3d ", frame.level);
3494 ide.callStackView.Logf($"inside %s, %s\n", frame.func, (s = CopySystemPath(frame.from)));
3498 ide.callStackView.Logf("%s\n", frame.func);
3500 ide.callStackView.Logf($"unknown source\n");
3504 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "stack content (", item.name, "=", item.value, ") is unheard of");
3507 if(activeFrameLevel == -1)
3509 activeFrameLevel = 0;
3510 activeFrame = stackFrames.first;
3512 ide.callStackView.Home();
3514 subTokens.RemoveAll();
3516 /*else if(!strcmp(item.name, "frame"))
3519 item.value = StripCurlies(item.value);
3520 ParseFrame(&frame, item.value);
3522 else if(!strcmp(item.name, "thread-ids"))
3524 ide.threadsView.Clear();
3525 item.value = StripCurlies(item.value);
3526 TokenizeList(item.value, ',', subTokens);
3527 for(i = subTokens.count - 1; ; i--)
3529 if(TokenizeListItem(subTokens[i], item))
3531 if(!strcmp(item.name, "thread-id"))
3534 StripQuotes(item.value, item.value);
3535 value = atoi(item.value);
3536 ide.threadsView.Logf("%3d \n", value);
3539 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "threads content (", item.name, "=", item.value, ") is unheard of");
3544 ide.threadsView.Home();
3546 subTokens.RemoveAll();
3547 //if(!strcmp(outTokens[2], "number-of-threads"))
3549 else if(!strcmp(item.name, "new-thread-id"))
3551 StripQuotes(item.value, item.value);
3552 activeThread = atoi(item.value);
3554 else if(!strcmp(item.name, "value"))
3556 StripQuotes(item.value, item.value);
3557 eval.result = CopyString(item.value);
3558 eval.active = false;
3560 else if(!strcmp(item.name, "addr"))
3562 for(i = 2; i < outTokens.count; i++)
3564 if(TokenizeListItem(outTokens[i], item))
3566 if(!strcmp(item.name, "total-bytes"))
3568 StripQuotes(item.value, item.value);
3569 eval.bytes = atoi(item.value);
3571 else if(!strcmp(item.name, "next-row"))
3573 StripQuotes(item.value, item.value);
3574 eval.nextBlockAddress = _strtoui64(item.value, null, 0);
3576 else if(!strcmp(item.name, "memory"))
3580 //StripQuotes(item.value, item.value);
3581 item.value = StripBrackets(item.value);
3582 // this should be treated as a list...
3583 item.value = StripCurlies(item.value);
3584 TokenizeList(item.value, ',', subTokens);
3585 for(j = 0; j < subTokens.count; j++)
3587 if(TokenizeListItem(subTokens[j], item))
3589 if(!strcmp(item.name, "data"))
3591 item.value = StripBrackets(item.value);
3592 StripQuotes2(item.value, item.value);
3593 eval.result = CopyString(item.value);
3594 eval.active = false;
3598 subTokens.RemoveAll();
3603 else if(!strcmp(item.name, "source-path") || !strcmp(item.name, "BreakpointTable"))
3604 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "command reply (", item.name, "=", item.value, ") is ignored");
3606 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "command reply (", item.name, "=", item.value, ") is unheard of");
3609 else if(!strcmp(outTokens[0], "^running"))
3611 waitingForPID = true;
3612 setWaitingForPID = true;
3613 ClearBreakDisplay();
3615 else if(!strcmp(outTokens[0], "^exit"))
3617 _ChangeState(terminated);
3618 // ide.outputView.debugBox.Logf("Exit\n");
3619 // ide.Update(null);
3621 serialSemaphore.Release();
3623 else if(!strcmp(outTokens[0], "^error"))
3627 sentBreakInsert = false;
3628 breakpointError = true;
3631 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
3633 if(!strcmp(item.name, "msg"))
3635 StripQuotes(item.value, item.value);
3638 eval.active = false;
3640 if(strstr(item.value, "No symbol") && strstr(item.value, "in current context"))
3641 eval.error = symbolNotFound;
3642 else if(strstr(item.value, "Cannot access memory at address"))
3643 eval.error = memoryCantBeRead;
3645 eval.error = unknown;
3647 else if(!strcmp(item.value, "Previous frame inner to this frame (corrupt stack?)"))
3650 else if(!strncmp(item.value, "Cannot access memory at address", 31))
3653 else if(!strcmp(item.value, "Cannot find bounds of current function"))
3655 _ChangeState(stopped);
3656 gdbHandle.Printf("-exec-continue\n");
3658 else if(!strcmp(item.value, "ptrace: No such process."))
3660 _ChangeState(loaded);
3661 targetProcessId = 0;
3663 else if(!strcmp(item.value, "Function \\\"WinMain\\\" not defined."))
3666 else if(!strcmp(item.value, "You can't do that without a process to debug."))
3668 _ChangeState(loaded);
3669 targetProcessId = 0;
3671 else if(strstr(item.value, "No such file or directory."))
3673 _ChangeState(loaded);
3674 targetProcessId = 0;
3676 else if(strstr(item.value, "During startup program exited with code "))
3678 _ChangeState(loaded);
3679 targetProcessId = 0;
3684 if(strlen(item.value) < MAX_F_STRING)
3687 ide.outputView.debugBox.Logf("GDB: %s\n", (s = CopyUnescapedString(item.value)));
3691 ide.outputView.debugBox.Logf("GDB: %s\n", item.value);
3697 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "error content (", item.name, "=", item.value, ") is unheard of");
3700 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "result-record: ", outTokens[0]);
3701 outTokens.RemoveAll();
3704 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "status-async-output: ", outTokens[0]);
3707 if(TokenizeList(output, ',', outTokens))
3709 if(!strcmp(outTokens[0], "=library-loaded"))
3710 FGODetectLoadedLibraryForAddedProjectIssues(outTokens, false);
3711 else if(!strcmp(outTokens[0], "=shlibs-added"))
3712 FGODetectLoadedLibraryForAddedProjectIssues(outTokens, true);
3713 else if(!strcmp(outTokens[0], "=thread-group-created") || !strcmp(outTokens[0], "=thread-group-added") ||
3714 !strcmp(outTokens[0], "=thread-group-started") || !strcmp(outTokens[0], "=thread-group-exited") ||
3715 !strcmp(outTokens[0], "=thread-created") || !strcmp(outTokens[0], "=thread-exited") ||
3716 !strcmp(outTokens[0], "=cmd-param-changed") || !strcmp(outTokens[0], "=library-unloaded") ||
3717 !strcmp(outTokens[0], "=breakpoint-modified"))
3718 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, outTokens[0], outTokens.count>1 ? outTokens[1] : "",
3719 outTokens.count>2 ? outTokens[2] : "", outTokens.count>3 ? outTokens[3] : "",
3720 outTokens.count>4 ? outTokens[4] : "", outTokens.count>5 ? outTokens[5] : "",
3721 outTokens.count>6 ? outTokens[6] : "", outTokens.count>7 ? outTokens[7] : "",
3722 outTokens.count>8 ? outTokens[8] : "", outTokens.count>9 ? outTokens[9] : "");
3724 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "notify-async-output: ", outTokens[0]);
3726 outTokens.RemoveAll();
3730 if(TokenizeList(output, ',', outTokens))
3732 if(!strcmp(outTokens[0],"*running"))
3734 waitingForPID = true;
3735 setWaitingForPID = true;
3737 else if(!strcmp(outTokens[0], "*stopped"))
3740 _ChangeState(stopped);
3742 for(tk = 1; tk < outTokens.count; tk++)
3744 if(TokenizeListItem(outTokens[tk], item))
3746 if(!strcmp(item.name, "reason"))
3748 char * reason = item.value;
3749 StripQuotes(reason, reason);
3750 if(!strcmp(reason, "exited-normally") || !strcmp(reason, "exited") || !strcmp(reason, "exited-signalled"))
3753 if(outTokens.count > tk+1 && TokenizeListItem(outTokens[tk+1], item2))
3756 StripQuotes(item2.value, item2.value);
3757 if(!strcmp(item2.name, "exit-code"))
3758 exitCode = item2.value;
3764 HandleExit(reason, exitCode);
3767 else if(!strcmp(reason, "breakpoint-hit") ||
3768 !strcmp(reason, "function-finished") ||
3769 !strcmp(reason, "end-stepping-range") ||
3770 !strcmp(reason, "location-reached") ||
3771 !strcmp(reason, "signal-received"))
3775 if(stopItem) _dpl(0, "problem");
3777 stopItem = GdbDataStop { };
3778 stopItem.reason = r == 'b' ? breakpointHit : r == 'f' ? functionFinished : r == 'e' ? endSteppingRange : r == 'l' ? locationReached : signalReceived;
3780 for(i = tk+1; i < outTokens.count; i++)
3782 TokenizeListItem(outTokens[i], item);
3783 StripQuotes(item.value, item.value);
3784 if(!strcmp(item.name, "thread-id"))
3785 stopItem.threadid = atoi(item.value);
3786 else if(!strcmp(item.name, "frame"))
3788 item.value = StripCurlies(item.value);
3789 ParseFrame(stopItem.frame, item.value);
3791 else if(stopItem.reason == breakpointHit && !strcmp(item.name, "bkptno"))
3792 stopItem.bkptno = atoi(item.value);
3793 else if(stopItem.reason == functionFinished && !strcmp(item.name, "gdb-result-var"))
3794 stopItem.gdbResultVar = CopyString(item.value);
3795 else if(stopItem.reason == functionFinished && !strcmp(item.name, "return-value"))
3796 stopItem.returnValue = CopyString(item.value);
3797 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-name"))
3798 stopItem.name = CopyString(item.value);
3799 else if(stopItem.reason == signalReceived && !strcmp(item.name, "signal-meaning"))
3800 stopItem.meaning = CopyString(item.value);
3801 else if(!strcmp(item.name, "stopped-threads"))
3802 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Advanced thread debugging not handled");
3803 else if(!strcmp(item.name, "core"))
3804 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": Information (core) not used");
3805 else if(!strcmp(item.name, "disp"))
3806 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, reason, ": (", item.name, "=", item.value, ")");
3808 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown ", reason, " item name (", item.name, "=", item.value, ")");
3811 if(stopItem.reason == signalReceived && !strcmp(stopItem.name, "SIGTRAP"))
3827 event = r == 'b' ? hit : r == 'f' ? functionEnd : r == 'e' ? stepEnd : r == 'l' ? locationReached : signal;
3831 else if(!strcmp(reason, "watchpoint-trigger"))
3832 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint trigger not handled");
3833 else if(!strcmp(reason, "read-watchpoint-trigger"))
3834 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason read watchpoint trigger not handled");
3835 else if(!strcmp(reason, "access-watchpoint-trigger"))
3836 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason access watchpoint trigger not handled");
3837 else if(!strcmp(reason, "watchpoint-scope"))
3838 _dpl2(_dpct, dplchan::gdbProtoIgnored, 0, "Reason watchpoint scope not handled");
3840 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown reason: ", reason);
3848 if(usingValgrind && event == none && !stopItem)
3849 event = valgrindStartPause;
3854 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, "Unknown exec-async-output: ", outTokens[0]);
3855 outTokens.RemoveAll();
3858 if(!strcmpi(output, "(gdb) "))
3862 Time startTime = GetTime();
3863 char exeFile[MAX_LOCATION];
3864 int oldProcessID = targetProcessId;
3865 GetLastDirectory(targetFile, exeFile);
3867 while(!targetProcessId/*true*/)
3869 targetProcessId = Process_GetChildExeProcessId(gdbProcessId, exeFile);
3870 if(targetProcessId) break;
3871 // Can't break on Peek(), GDB is giving us =library and other info before the process is listed in /proc
3872 // if(gdbHandle.Peek()) break;
3874 if(gdbHandle.Peek() && GetTime() - startTime > 2.5) // Give the process 2.5 seconds to show up in /proc
3879 _ChangeState(running);
3880 else if(!oldProcessID)
3882 ide.outputView.debugBox.Logf($"Debugger Error: No target process ID\n");
3883 // TO VERIFY: The rest of this block has not been thoroughly tested in this particular location
3884 gdbHandle.Printf("-gdb-exit\n");
3886 _ChangeState(terminated); //loaded;
3891 for(bp : ide.workspace.breakpoints)
3892 bp.inserted = false;
3895 bp.inserted = false;
3897 bpRunToCursor.inserted = false;
3899 ide.outputView.debugBox.Logf($"Debugging stopped\n");
3900 ClearBreakDisplay();
3902 #if defined(__unix__)
3903 if(!usingValgrind && FileExists(progFifoPath)) //fileCreated)
3905 progThread.terminate = true;
3908 fifoFile.CloseInput();
3915 DeleteFile(progFifoPath);
3916 progFifoPath[0] = '\0';
3923 serialSemaphore.Release();
3926 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown prompt", output);
3930 if(!strncmp(output, "&\"warning:", 10))
3933 content = strstr(output, "\"");
3934 StripQuotes(content, content);
3935 content = strstr(content, ":");
3941 ide.outputView.debugBox.LogRaw((s = CopyUnescapedString(content)));
3948 _dpl2(_dpct, dplchan::gdbProtoUnknown, 0, $"Unknown output: ", output);
3950 if(!setWaitingForPID)
3951 waitingForPID = false;
3952 setWaitingForPID = false;
3960 // From GDB Output functions
3961 void FGODetectLoadedLibraryForAddedProjectIssues(Array<char *> outTokens, bool shlibs)
3963 char path[MAX_LOCATION] = "";
3964 char file[MAX_FILENAME] = "";
3965 bool symbolsLoaded = false;
3966 DebugListItem item { };
3967 //_dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGODetectLoadedLibraryForAddedProjectIssues()");
3968 for(token : outTokens)
3970 if(TokenizeListItem(token, item))
3972 if(!strcmp(item.name, "target-name"))
3974 StripQuotes(item.value, path);
3975 MakeSystemPath(path);
3976 GetLastDirectory(path, file);
3978 else if(!strcmp(item.name, "symbols-loaded"))
3980 symbolsLoaded = (atoi(item.value) == 1);
3982 else if(!strcmp(item.name, "shlib-info"))
3984 DebugListItem subItem { };
3985 Array<char *> tokens { minAllocSize = 50 };
3986 item.value = StripBrackets(item.value);
3987 TokenizeList(item.value, ',', tokens);
3990 if(TokenizeListItem(t, subItem))
3992 if(!strcmp(subItem.name, "path"))
3994 StripQuotes(subItem.value, path);
3995 MakeSystemPath(path);
3996 GetLastDirectory(path, file);
3997 symbolsLoaded = true;
4008 if(path[0] && file[0])
4010 for(prj : ide.workspace.projects; prj != ide.workspace.projects.firstIterator.data)
4014 char prjTargetPath[MAX_LOCATION];
4015 char prjTargetFile[MAX_FILENAME];
4016 DirExpression targetDirExp = prj.GetTargetDir(currentCompiler, prj.config, bitDepth);
4017 strcpy(prjTargetPath, prj.topNode.path);
4018 PathCat(prjTargetPath, targetDirExp.dir);
4019 delete targetDirExp;
4020 prjTargetFile[0] = '\0';
4021 prj.CatTargetFileName(prjTargetFile, currentCompiler, prj.config);
4022 PathCat(prjTargetPath, prjTargetFile);
4023 MakeSystemPath(prjTargetPath);
4025 match = !fstrcmp(prjTargetFile, file);
4026 if(!match && (dot = strstr(prjTargetFile, ".so.")))
4028 char * dot3 = strstr(dot+4, ".");
4032 match = !fstrcmp(prjTargetFile, file);
4037 match = !fstrcmp(prjTargetFile, file);
4042 // TODO: nice visual feedback to better warn user. use some ide notification system or other means.
4043 /* -- 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)
4045 ide.outputView.debugBox.Logf($"Attention! No symbols for loaded library %s matched to the %s added project.\n", path, prj.topNode.name);
4047 match = !fstrcmp(prjTargetPath, path);
4048 if(!match && (dot = strstr(prjTargetPath, ".so.")))
4050 char * dot3 = strstr(dot+4, ".");
4054 match = !fstrcmp(prjTargetPath, path);
4059 match = !fstrcmp(prjTargetPath, path);
4063 projectsLibraryLoaded[prj.name] = true;
4065 ide.outputView.debugBox.Logf($"Loaded library %s doesn't match the %s target of the %s added project.\n", path, prjTargetPath, prj.topNode.name);
4072 void FGOBreakpointModified(Array<char *> outTokens)
4074 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::FGOBreakpointModified() -- TODO only if needed: support breakpoint modified");
4076 DebugListItem item { };
4077 if(outTokens.count > 1 && TokenizeListItem(outTokens[1], item))
4079 if(!strcmp(item.name, "bkpt"))
4081 GdbDataBreakpoint modBp = ParseBreakpoint(item.value, outTokens);
4089 ExpressionType ::DebugEvalExpTypeError(char * result)
4091 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::DebugEvalExpTypeError()");
4096 case symbolNotFound:
4097 return symbolErrorExp;
4098 case memoryCantBeRead:
4099 return memoryErrorExp;
4101 return unknownErrorExp;
4104 char * ::EvaluateExpression(char * expression, ExpressionType * error)
4107 _dpl2(_dpct, dplchan::debuggerWatches, 0, "Debugger::EvaluateExpression(", expression, ")");
4108 if(ide.projectView && ide.debugger.state == stopped)
4110 result = GdbEvaluateExpression(expression);
4111 *error = DebugEvalExpTypeError(result);
4116 *error = noDebuggerErrorExp;
4121 char * ::ReadMemory(uint64 address, int size, char format, ExpressionType * error)
4124 char * result = GdbReadMemoryString(address, size, format, 1, 1);
4125 _dpl2(_dpct, dplchan::debuggerCall, 0, "Debugger::ReadMemory(", address, ")");
4126 if(!result || !strcmp(result, "N/A"))
4127 *error = memoryErrorExp;
4129 *error = DebugEvalExpTypeError(result);
4134 class ValgrindLogThread : Thread
4140 static char output[4096];
4141 bool lastLineEmpty = true;
4142 Array<char> dynamicBuffer { minAllocSize = 4096 };
4143 File oldValgrindHandle = vgLogFile;
4144 incref oldValgrindHandle;
4147 while(debugger.state != terminated && vgLogFile && vgLogFile.input)
4152 result = vgLogFile.Read(output, 1, sizeof(output));
4154 if(debugger.state == terminated || !vgLogFile) // || vgLogFile.Eof()
4161 for(c = 0; c<result; c++)
4163 if(output[c] == '\n')
4165 int pos = dynamicBuffer.size;
4166 dynamicBuffer.size += c - start;
4167 memcpy(&dynamicBuffer[pos], output + start, c - start);
4168 if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
4169 dynamicBuffer.size++;
4170 dynamicBuffer[dynamicBuffer.count - 1] = '\0';
4172 // printf("%s\n", dynamicBuffer.array);
4174 if(strstr(&dynamicBuffer[0], "vgdb me ..."))
4175 debugger.serialSemaphore.Release();
4177 char * s = strstr(&dynamicBuffer[0], "==");
4179 s = strstr(s+2, "== ");
4183 if(s[0] == '\0' && !lastLineEmpty)
4186 lastLineEmpty = true;
4187 dynamicBuffer[0] = '\0';
4196 if(strstr(s, "vgdb me ..."))
4198 if(strstr(s, "(action on error) vgdb me ..."))
4199 ide.outputView.debugBox.Logf($"...breaked on Valgrind error (F5 to resume)\n");
4206 if(strstr(s, "TO DEBUG THIS PROCESS USING GDB: start GDB like this"))
4212 if(strstr(s, "and then give GDB the following command"))
4218 if(strstr(s, "/path/to/gdb") || strstr(s, "target remote | /usr/lib/valgrind/../../bin/vgdb --pid="))
4224 if(strstr(s, "--pid is optional if only one valgrind process is running"))
4230 if((s = strstr(s, "; rerun with -h for copyright info")))
4242 if(lastLineEmpty && t[0] != '\0')
4243 lastLineEmpty = false;
4246 ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
4248 dynamicBuffer.size = 0;
4254 int pos = dynamicBuffer.size;
4255 dynamicBuffer.size += c - start;
4256 memcpy(&dynamicBuffer[pos], output + start, c - start);
4259 else if(debugger.state == stopped)
4262 printf("Got end of file from GDB!\n");
4269 delete dynamicBuffer;
4270 _dpl2(_dpct, dplchan::debuggerCall, 0, "ValgrindLogThreadExit");
4271 //if(oldValgrindHandle == vgLogFile)
4272 debugger.GdbThreadExit/*ValgrindLogThreadExit*/();
4273 delete oldValgrindHandle;
4279 class ValgrindTargetThread : Thread
4285 static char output[4096];
4286 Array<char> dynamicBuffer { minAllocSize = 4096 };
4287 DualPipe oldValgrindHandle = vgTargetHandle;
4288 incref oldValgrindHandle;
4291 while(debugger.state != terminated && vgTargetHandle && !vgTargetHandle.Eof())
4295 result = vgTargetHandle.Read(output, 1, sizeof(output));
4297 if(debugger.state == terminated || !vgTargetHandle || vgTargetHandle.Eof())
4304 for(c = 0; c<result; c++)
4306 if(output[c] == '\n')
4308 int pos = dynamicBuffer.size;
4309 dynamicBuffer.size += c - start;
4310 memcpy(&dynamicBuffer[pos], output + start, c - start);
4311 if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
4312 // COMMENTED OUT DUE TO ISSUE #135, FIXED
4313 //if(dynamicBuffer.array[dynamicBuffer.count - 1] != '\r')
4314 dynamicBuffer.size++;
4315 dynamicBuffer[dynamicBuffer.count - 1] = '\0';
4317 // printf("%s\n", dynamicBuffer.array);
4319 ide.outputView.debugBox.Logf("%s\n", &dynamicBuffer[0]);
4321 dynamicBuffer.size = 0;
4327 int pos = dynamicBuffer.size;
4328 dynamicBuffer.size += c - start;
4329 memcpy(&dynamicBuffer[pos], output + start, c - start);
4335 printf("Got end of file from GDB!\n");
4339 delete dynamicBuffer;
4340 //if(oldValgrindHandle == vgTargetHandle)
4341 debugger.ValgrindTargetThreadExit();
4342 delete oldValgrindHandle;
4348 class GdbThread : Thread
4354 static char output[4096];
4355 Array<char> dynamicBuffer { minAllocSize = 4096 };
4356 DualPipe oldGdbHandle = gdbHandle;
4357 incref oldGdbHandle;
4360 while(debugger.state != terminated && gdbHandle && !gdbHandle.Eof())
4364 result = gdbHandle.Read(output, 1, sizeof(output));
4366 if(debugger.state == terminated || !gdbHandle || gdbHandle.Eof())
4373 for(c = 0; c<result; c++)
4375 if(output[c] == '\n')
4377 int pos = dynamicBuffer.size;
4378 dynamicBuffer.size += c - start;
4379 memcpy(&dynamicBuffer[pos], output + start, c - start);
4380 if(dynamicBuffer.count && dynamicBuffer[dynamicBuffer.count - 1] != '\r')
4381 // COMMENTED OUT DUE TO ISSUE #135, FIXED
4382 //if(dynamicBuffer.array[dynamicBuffer.count - 1] != '\r')
4383 dynamicBuffer.size++;
4384 dynamicBuffer[dynamicBuffer.count - 1] = '\0';
4386 // _dpl(0, dynamicBuffer.array);
4388 debugger.GdbThreadMain(&dynamicBuffer[0]);
4389 dynamicBuffer.size = 0;
4395 int pos = dynamicBuffer.size;
4396 dynamicBuffer.size += c - start;
4397 memcpy(&dynamicBuffer[pos], output + start, c - start);
4403 _dpl(0, "Got end of file from GDB!");
4407 delete dynamicBuffer;
4408 //if(oldGdbHandle == gdbHandle)
4409 debugger.GdbThreadExit();
4410 delete oldGdbHandle;
4416 static define createFIFOMsg = $"err: Unable to create FIFO %s\n";
4417 static define openFIFOMsg = $"err: Unable to open FIFO %s for read\n";
4419 #if defined(__unix__)
4424 #include <sys/types.h>
4429 class ProgramThread : Thread
4435 bool fileCreated = false;
4437 static char output[1000];
4440 /*if(!mkfifo(progFifoPath, mask))
4447 ide.outputView.debugBox.Logf($"err: Unable to create FIFO %s\n", progFifoPath);
4451 if(FileExists(progFifoPath)) //fileCreated)
4453 fifoFile = FileOpen(progFifoPath, read);
4457 ide.outputView.debugBox.Logf(openFIFOMsg, progFifoPath);
4462 fd = fileno((FILE *)fifoFile.input);
4463 //fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
4467 while(!terminate && fifoFile && !fifoFile.Eof())
4470 struct timeval time;
4478 selectResult = select(fd + 1, &rs, null, null, &time);
4479 if(FD_ISSET(fd, &rs))
4481 int result = (int)read(fd, output, sizeof(output)-1);
4482 if(!result || (result < 0 && errno != EAGAIN))
4486 output[result] = '\0';
4487 if(strcmp(output,"&\"warning: GDB: Failed to set controlling terminal: Invalid argument\\n\"\n"))
4490 ide.outputView.debugBox.Log(output);
4499 //fifoFile.CloseInput();
4502 ide.outputView.debugBox.Log("\n");
4506 if(FileExists(progFifoPath)) //fileCreated)
4508 DeleteFile(progFifoPath);
4509 progFifoPath[0] = '\0';
4517 class Argument : struct
4519 Argument prev, next;
4521 property char * name { set { delete name; if(value) name = CopyString(value); } }
4523 property char * val { set { delete val; if(value) val = CopyString(value); } }
4537 class Frame : struct
4542 property char * addr { set { delete addr; if(value) addr = CopyString(value); } }
4544 property char * func { set { delete func; if(value) func = CopyString(value); } }
4548 property char * from { set { delete from; if(value) from = CopyUnescapedUnixPath(value); } }
4550 property char * file { set { delete file; if(value) file = CopyUnescapedUnixPath(value); } }
4551 char * absoluteFile;
4552 property char * absoluteFile { set { delete absoluteFile; if(value) absoluteFile = CopyUnescapedUnixPath(value); } }
4561 delete absoluteFile;
4562 args.Free(Argument::Free);
4571 class GdbDataStop : struct
4573 DebuggerReason reason;
4588 char * gdbResultVar;
4598 if(reason == signalReceived)
4603 else if(reason == functionFinished)
4605 delete gdbResultVar;
4609 if(frame) frame.Free();
4618 class GdbDataBreakpoint : struct
4622 property char * number { set { delete number; if(value) number = CopyString(value); } }
4624 property char * type { set { delete type; if(value) type = CopyString(value); } }
4626 property char * disp { set { delete disp; if(value) disp = CopyString(value); } }
4629 property char * addr { set { delete addr; if(value) addr = CopyString(value); } }
4631 property char * func { set { delete func; if(value) func = CopyString(value); } }
4633 property char * file { set { delete file; if(value) file = CopyUnescapedUnixPath(value); } }
4635 property char * fullname { set { delete fullname; if(value) fullname = CopyUnescapedUnixPath(value); } }
4638 property char * at { set { delete at; if(value) at = CopyString(value); } }
4641 Array<GdbDataBreakpoint> multipleBPs;
4646 PrintLn("{", "#", number, " T", type, " D", disp, " E", enabled, " H", times, " (", func, ") (", file, ":", line, ") (", fullname, ") (", addr, ") (", at, ")", "}");
4657 if(multipleBPs) multipleBPs.Free();
4663 ~GdbDataBreakpoint()
4669 class Breakpoint : struct
4674 property char * function { set { delete function; if(value) function = CopyString(value); } }
4675 char * relativeFilePath;
4676 property char * relativeFilePath { set { delete relativeFilePath; if(value) relativeFilePath = CopyString(value); } }
4677 char * absoluteFilePath;
4678 property char * absoluteFilePath { set { delete absoluteFilePath; if(value) absoluteFilePath = CopyString(value); } }
4680 property char * location { set { delete location; if(value) location = CopyString(value); } }
4689 BreakpointType type;
4691 GdbDataBreakpoint bp;
4694 property char * address { set { delete address; if(value) address = CopyString(value); } }
4696 void ParseLocation()
4698 char * prjName = null;
4699 char * filePath = null;
4702 char fullPath[MAX_LOCATION];
4703 if(location[0] == '(' && location[1] && (file = strchr(location+2, ')')) && file[1])
4705 prjName = new char[file-location];
4706 strncpy(prjName, location+1, file-location-1);
4707 prjName[file-location-1] = '\0';
4712 if((line = strchr(file+1, ':')))
4714 filePath = new char[strlen(file)+1];
4715 strncpy(filePath, file, line-file);
4716 filePath[line-file] = '\0';
4720 filePath = CopyString(file);
4721 property::relativeFilePath = filePath;
4724 for(prj : ide.workspace.projects)
4726 if(!strcmp(prjName, prj.name))
4728 if(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
4730 property::absoluteFilePath = fullPath;
4737 this.line = atoi(line);
4741 Project prj = ide.project;
4742 if(ProjectGetAbsoluteFromRelativePath(prj, filePath, fullPath))
4744 property::absoluteFilePath = fullPath;
4748 if(!absoluteFilePath)
4749 property::absoluteFilePath = "";
4754 char * CopyLocationString(bool removePath)
4757 char * file = relativeFilePath ? relativeFilePath : absoluteFilePath;
4758 bool removingPath = removePath && file;
4761 char * fileName = new char[MAX_FILENAME];
4762 GetLastDirectory(file, fileName);
4768 location = PrintString(file, ":", function);
4770 location = CopyString(function);
4773 location = PrintString(file, ":", line);
4779 char * CopyUserLocationString()
4782 char * loc = CopyLocationString(false);
4784 if(absoluteFilePath)
4786 for(p : ide.workspace.projects; p != ide.workspace.projects.firstIterator.data)
4788 if(p.topNode.FindByFullPath(absoluteFilePath, false))
4797 location = PrintString("(", prj.name, ")", loc);
4807 if(relativeFilePath && relativeFilePath[0])
4809 char * location = CopyUserLocationString();
4810 f.Printf(" * %d,%d,%d,%d,%s\n", enabled ? 1 : 0, ignore, level, line, location);
4813 f.Printf(" ~ %s\n", condition.expression);
4821 delete relativeFilePath;
4822 delete absoluteFilePath;
4842 class Watch : struct
4853 f.Printf(" ~ %s\n", expression);
4877 class DebugListItem : struct
4883 struct DebugEvaluationData
4888 uint64 nextBlockAddress;
4890 DebuggerEvaluationError error;
4893 class CodeLocation : struct
4896 char * absoluteFile;
4899 CodeLocation ::ParseCodeLocation(char * location)
4903 char * colon = null;
4905 char loc[MAX_LOCATION];
4906 strcpy(loc, location);
4907 for(temp = loc; temp = strstr(temp, ":"); temp++)
4915 int line = atoi(colon);
4918 CodeLocation codloc { line = line };
4919 codloc.file = CopyString(loc);
4920 codloc.absoluteFile = ide.workspace.GetAbsolutePathFromRelative(loc);
4932 delete absoluteFile;
4941 void GDBFallBack(Expression exp, String expString)
4944 ExpressionType evalError = dummyExp;
4945 result = Debugger::EvaluateExpression(expString, &evalError);
4948 exp.constant = result;
4949 exp.type = constantExp;
4953 static Project WorkspaceGetFileOwner(char * absolutePath)
4955 Project owner = null;
4956 for(prj : ide.workspace.projects)
4958 if(prj.topNode.FindByFullPath(absolutePath, false))
4965 WorkspaceGetObjectFileNode(absolutePath, &owner);
4969 static ProjectNode WorkspaceGetObjectFileNode(char * filePath, Project * project)
4971 ProjectNode node = null;
4972 char ext[MAX_EXTENSION];
4973 GetExtension(filePath, ext);
4976 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
4979 char fileName[MAX_FILENAME];
4980 GetLastDirectory(filePath, fileName);
4983 DotMain dotMain = DotMain::FromFileName(fileName);
4984 for(prj : ide.workspace.projects)
4986 if((node = prj.FindNodeByObjectFileName(fileName, type, dotMain, null)))
4999 static ProjectNode ProjectGetObjectFileNode(Project project, char * filePath)
5001 ProjectNode node = null;
5002 char ext[MAX_EXTENSION];
5003 GetExtension(filePath, ext);
5006 IntermediateFileType type = IntermediateFileType::FromExtension(ext);
5009 char fileName[MAX_FILENAME];
5010 GetLastDirectory(filePath, fileName);
5013 DotMain dotMain = DotMain::FromFileName(fileName);
5014 node = project.FindNodeByObjectFileName(fileName, type, dotMain, null);
5021 static void WorkspaceGetRelativePath(char * absolutePath, char * relativePath, Project * owner)
5023 Project prj = WorkspaceGetFileOwner(absolutePath);
5027 prj = ide.workspace.projects.firstIterator.data;
5030 MakePathRelative(absolutePath, prj.topNode.path, relativePath);
5031 MakeSlashPath(relativePath);
5034 relativePath[0] = '\0';
5037 static bool ProjectGetAbsoluteFromRelativePath(Project project, char * relativePath, char * absolutePath)
5039 ProjectNode node = project.topNode.FindWithPath(relativePath, false);
5041 node = ProjectGetObjectFileNode(project, relativePath);
5044 strcpy(absolutePath, node.project.topNode.path);
5045 PathCat(absolutePath, relativePath);
5046 MakeSlashPath(absolutePath);
5048 return node != null;