MCPcopy Create free account
hub / github.com/Marus/cortex-debug / startGdb

Method startGdb

src/gdb.ts:858–911  ·  view source on GitHub ↗
(response: DebugProtocol.LaunchResponse)

Source from the content-addressed store, hash-verified

856
857 private gdbInitCommands: string[] = [];
858 private startGdb(response: DebugProtocol.LaunchResponse): Promise<void> {
859 const gdbExePath = this.args.gdbPath;
860 const gdbargs = ['-q', '--interpreter=mi2'].concat(this.args.debuggerArgs || []);
861 if (!this.args.symbolFiles) {
862 if (!path.isAbsolute(this.args.executable)) {
863 this.args.executable = path.join(this.args.cwd, this.args.executable);
864 }
865 }
866 const dbgMsg = 'Launching GDB: ' + quoteShellCmdLine([gdbExePath, ...gdbargs]) + '\n';
867 this.handleMsg('log', dbgMsg);
868 if (!this.args.showDevDebugOutput) {
869 this.handleMsg('stdout', ' IMPORTANT: Set "showDevDebugOutput": "raw" in "launch.json" to see verbose GDB transactions ' +
870 'here. Very helpful to debug issues or report problems\n');
871 }
872 if (this.args.showDevDebugOutput && this.args.chainedConfigurations && this.args.chainedConfigurations.enabled) {
873 const str = JSON.stringify({chainedConfigurations: this.args.chainedConfigurations}, null, 4);
874 this.handleMsg('log', str + '\n');
875 }
876
877 this.miDebugger = new MI2(gdbExePath, gdbargs);
878 this.miDebugger.debugOutput = this.args.showDevDebugOutput as ADAPTER_DEBUG_MODE;
879 this.miDebugger.on('launcherror', (err) => {
880 const msg = 'Could not start GDB process, does the program exist in filesystem?\n' + err.toString() + '\n';
881 this.launchErrorResponse(response, 103, msg);
882 this.quitEvent();
883 });
884 this.initDebugger();
885 this.gdbInitCommands = [
886 'interpreter-exec console "set print demangle on"',
887 'interpreter-exec console "set print asm-demangle on"',
888 'enable-pretty-printing',
889 `interpreter-exec console "source ${this.args.extensionPath}/support/gdbsupport.init"`,
890 `interpreter-exec console "source ${this.args.extensionPath}/support/gdb-swo.init"`,
891 ...this.formatRadixGdbCommand()
892 ];
893 if (this.args.symbolFiles) {
894 for (const symF of this.args.symbolFiles) {
895 let cmd = `interpreter-exec console "add-symbol-file \\"${symF.file}\\""`;
896 cmd += symF.offset ? ` -o ${hexFormat(symF.offset)}"` : '';
897 cmd += (typeof symF.textaddress === 'number') ? ` ${hexFormat(symF.textaddress)}"` : '';
898 for (const section of symF.sections) {
899 cmd += ` -s ${section.name} ${section.address}`;
900 }
901 this.gdbInitCommands.push(cmd);
902 }
903 if (this.gdbInitCommands.length === 0) {
904 this.handleMsg('log', 'Info: GDB may not start since there were no files with symbols in "symbolFiles?\n');
905 }
906 } else {
907 this.gdbInitCommands.push(`file-exec-and-symbols "${this.args.executable}"`);
908 }
909 const ret = this.miDebugger.start(this.args.cwd, this.gdbInitCommands);
910 return ret;
911 }
912
913 public startGdbForLiveWatch(liveGdb: LiveWatchMonitor): Promise<void> {
914 const mi2 = new MI2(this.miDebugger.application, this.miDebugger.args, true);

Callers 1

Calls 9

handleMsgMethod · 0.95
launchErrorResponseMethod · 0.95
quitEventMethod · 0.95
initDebuggerMethod · 0.95
formatRadixGdbCommandMethod · 0.95
quoteShellCmdLineFunction · 0.90
hexFormatFunction · 0.90
toStringMethod · 0.80
startMethod · 0.65

Tested by

no test coverage detected