Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix & support for multiple terminals #6

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@ Add `gdbtty` property to your `launch.json`. Here’s an example:
```
![GdbTTY](gdbttydisplay.png)

* Linux Requirements: `xterm`

How to install xterm on Ubuntu:
```
sudo apt-get install xterm
```

On Linux you can see the output of the application in Vs Code itself. Add `gdbtty` property with `vscode` value to your `launch.json`. Here is an example:
```json
{
Expand All @@ -179,8 +172,9 @@ On Linux you can see the output of the application in Vs Code itself. Add `gdbtt
```
![GdbTTY](gdbttyvscode.png)

### Documentation
You can also use these options with `gdbtty`: `xterm`, `gnome-terminal`, `konsole` and `xfce4-terminal`.

### Documentation
For a more in depth documentation please check the [Superbol Documentation](https://ocamlpro.com/superbol/)
nberth marked this conversation as resolved.
Show resolved Hide resolved

### Troubleshooting
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
true,
false,
"vscode",
"xterm",
"gnome-terminal",
"xfce4-terminal",
"konsole",
"external"
]
}
Expand Down
121 changes: 105 additions & 16 deletions src/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ export class MI2 extends EventEmitter implements IDebugger {
try_find++;
if (xterm_device != "") break;
}
if (xterm_device === "") this.log("stderr", "tty: Install 'xterm' to use gdb's tty option\n");
if (xterm_device === "") this.log("stderr", "tty: Install a terminal to use gdb's tty option\n");
}
if (xterm_device.includes("pts")) {
this.gdbArgs.push("--tty=" + xterm_device);
Expand Down Expand Up @@ -991,24 +991,113 @@ export class MI2 extends EventEmitter implements IDebugger {
return strCode;
}

isTerminalInstalled(terminalCommand: string): boolean {
try {
ChildProcess.execSync(`command -v ${terminalCommand}`);
return true;
} catch (error) {
return false;
}
}

createXFCETerminal(sleepVal, target) {
let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target;
let param = "bash -c 'echo \"GnuCOBOL DEBUG\"; sleep " + sleepVal + ";'";
const xfce4_terminal_args = [
"--title", "GnuCOBOL Debug - " + dispTarget,
"--font=DejaVu Sans Mono 14",
"--command", param
]
const xfce_process = ChildProcess.spawn("xfce4-terminal", xfce4_terminal_args, {
detached: true,
stdio: 'ignore'
});
xfce_process.unref();
}

createKDETerminal(sleepVal, target) {
let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target;
let param = "bash -c 'echo \"GnuCOBOL DEBUG\"; sleep " + sleepVal + ";'";
const konsole_args = [
"--title", "GnuCOBOL Debug - " + dispTarget,
"--separate",
"--nofork",
"--hold",
"-e",
param
]
const kde_process = ChildProcess.spawn("konsole", konsole_args, {
detached: true,
stdio: 'ignore'
});
kde_process.unref();
}

createGNOMETerminal(sleepVal, target) {
let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target;
const gnome_terminal_args = [
"--title", "GnuCOBOL Debug - " + dispTarget,
"--",
"bash", "-c","echo 'GnuCOBOL DEBUG';" + "sleep " + sleepVal + ";"
]
const gnome_process = ChildProcess.spawn("gnome-terminal", gnome_terminal_args, {
detached: true,
stdio: 'ignore',
});
gnome_process.unref();
}

createXtermTerminal(sleepVal, target) {
let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target;
const xterm_args = [
"-title", "GnuCOBOL Debug - " + dispTarget,
"-fa", "DejaVu Sans Mono",
"-fs", "14",
"-e", "/usr/bin/tty;" +
"echo 'GnuCOBOL DEBUG';" +
"sleep " + sleepVal + ";"
]
const xterm_process = ChildProcess.spawn("xterm", xterm_args, {
detached: true,
stdio: 'ignore',
});
xterm_process.unref();
}

// Opens a terminal to show the application screen - gdbtty
createTerminal(gdbtty, sleepVal, target) {
let findTerminal = true;
if (gdbtty != "vscode") {
let dispTarget = (target.length > 50) ? "..." + target.substr(target.length - 50, target.length) : target;
const xterm_args = [
"-title", "GnuCOBOL Debug - " + dispTarget,
"-fa", "DejaVu Sans Mono",
"-fs", "14",
"-e", "/usr/bin/tty;" +
"echo 'GnuCOBOL DEBUG';" +
"sleep " + sleepVal + ";"
]

const xterm_process = ChildProcess.spawn("xterm", xterm_args, {
detached: true,
stdio: 'ignore',
});
xterm_process.unref();
if (typeof gdbtty === 'string' && gdbtty!="external") {
if(this.isTerminalInstalled(gdbtty)){
findTerminal = false;
switch (gdbtty) {
case "xterm":
this.createXtermTerminal(sleepVal, target);
break;
case "gnome-terminal":
this.createGNOMETerminal(sleepVal, target);
break;
case "konsole":
this.createKDETerminal(sleepVal, target);
break;
case "xfce4-terminal":
this.createXFCETerminal(sleepVal, target);
break;
}
}
}
if(findTerminal){
if(this.isTerminalInstalled("xterm")){
this.createXtermTerminal(sleepVal, target);
}else if(this.isTerminalInstalled("gnome-terminal")){
this.createGNOMETerminal(sleepVal, target);
}else if(this.isTerminalInstalled("xfce4-terminal")){
this.createXFCETerminal(sleepVal, target);
}else if(this.isTerminalInstalled("konsole")){
this.createKDETerminal(sleepVal, target);
}
}
} else {
let terminal = this.selectTerminal();
if (!terminal) {
Expand Down
11 changes: 9 additions & 2 deletions src/parser.c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const versionRegex = /\/\*\sGenerated by\s+cobc\s([0-9a-z\-\.]+)\s+\*\//i;
const subroutineRegex = /\sPerform\s/i;
const frame_ptrFindRegex = /frame\_ptr\-\-\;/;
const fixOlderFormat = /cob\_trace\_stmt/;
const programExit = /\/\*\sProgram\s\exit\s+\*\//i;

globalThis.varOccurs = [];

Expand Down Expand Up @@ -75,6 +76,8 @@ export class SourceMap {

private parse(fileC: string): void {
let nat = fileC;
let hasProgramExit = false;

if (!nativePath.isAbsolute(fileC)) {
nat = nativePathFromPath.resolve(this.cwd, fileC);
fileC = nativePath.resolve(this.cwd, fileC);
Expand Down Expand Up @@ -116,9 +119,9 @@ export class SourceMap {
}
// fix new codegen
match = procedureFixRegex.exec(line);
if (match && this.lines.length > 0) {
if (match && this.lines.length > 0 && !hasProgramExit) {
let isOldFormat = fixOlderFormat.exec(this.lineBefore);
if(this.isVersion2_2_or_3_1_1 || !isOldFormat){ // Is it in the old format?
if(fileNameCompare(this.lines[this.lines.length - 1].fileCobol, fileCobol) && (this.isVersion2_2_or_3_1_1 || !isOldFormat)){ // Is it in the old format?
let line = this.lines.pop();
line.lineC = parseInt(match[1]);
this.lines.push(line);
Expand Down Expand Up @@ -173,6 +176,10 @@ export class SourceMap {
}
}
this.lineBefore = line;
match = programExit.exec(line);
if (match) {
hasProgramExit=true;;
}
lineNumber++;
}
}
Expand Down