Skip to content

Commit 70a47d9

Browse files
authored
Merge pull request #38 from nberth/cobol-statement-in-stack
Show current COBOL statement in stackframe summary
2 parents 29f0253 + 9fac41f commit 70a47d9

File tree

9 files changed

+45
-51
lines changed

9 files changed

+45
-51
lines changed

.vscode-test-workspace/.dummy

Whitespace-only changes.

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// "--user-data-dir=${workspaceFolder}/.vscode-test/user-data",
1515
"--extensionDevelopmentPath=${workspaceFolder}",
1616
"--trace-deprecation",
17-
"${workspaceFolder}/.vscode-test-workspace",
17+
"${workspaceFolder}/test/resources",
1818
],
1919
"autoAttachChildProcesses": true,
2020
"sourceMaps": true,

.vscode/tasks.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
"command": "npm",
77
"type": "shell",
88
"presentation": {
9-
"reveal": "always",
10-
"panel": "new"
9+
"reveal": "silent",
10+
"revealProblems": "onProblem",
11+
"panel": "dedicated"
1112
},
1213
"args": [
1314
"run",
1415
"compile",
1516
"--loglevel",
1617
"silent"
1718
],
18-
"isBackground": true,
19+
"isBackground": false,
1920
"problemMatcher": "$tsc-watch",
2021
"group": {
2122
"kind": "build",

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Next
22

3+
* Show COBOL statements in entries of stackframe summary [PR #38](https://github.com/ocamlpro/superbol-vscode-debug/pull/38)
34
* Remove `gdbpath` and `libcobpath` from launch configurations (these are provided in extension settings) [PR #36](https://github.com/ocamlpro/superbol-vscode-debug/pull/36)
45
* Fix enforcement of a default `preLaunchTask` that is not available [PR #34](https://github.com/ocamlpro/superbol-vscode-debug/pull/34)
56
* Support cases where the COBOL source code and the corresponding C files are in distinct directories [PR #29](https://github.com/ocamlpro/superbol-vscode-debug/pull/29)

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/debugger.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {MINode} from "./parser.mi2";
22
import {DebugProtocol} from "@vscode/debugprotocol/lib/debugProtocol";
33
import {removeLeadingZeroes} from "./functions";
4-
import {SourceMap} from "./parser.c";
4+
import {SourceMap, Line} from "./parser.c";
55

66
export interface Breakpoint {
77
file?: string;
@@ -19,11 +19,8 @@ export interface Thread {
1919

2020
export interface Stack {
2121
level: number;
22-
address: string;
2322
function: string;
24-
fileName: string;
25-
file: string;
26-
line: number;
23+
line: Line;
2724
}
2825

2926
const repeatTimeRegex = /(\"\,\s|^)\'(\s|0)\'\s\<repeats\s(\d+)\stimes\>/i;

src/gdb.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -391,23 +391,21 @@ export class GDBDebugSession extends DebugSession {
391391

392392
protected stackTraceRequest(response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments): void {
393393
this.miDebugger.getStack(args.levels, args.threadId).then(stack => {
394-
const ret: StackFrame[] = [];
395-
stack.forEach(element => {
396-
let source: Source = undefined;
397-
const file = element.file;
398-
if (file) {
399-
source = new Source(element.fileName, file);
400-
}
401-
402-
ret.push(new StackFrame(
394+
const ret = stack.map(element => {
395+
const file = element.line.fileCobol;
396+
const fileBasename = path.basename(file);
397+
const cobolLine = element.line.cobolLine?.trim();
398+
const frameDescr = cobolLine
399+
? `${element.function} (${cobolLine})`
400+
: `${element.function}`;
401+
return new StackFrame(
403402
this.threadAndLevelToFrameId(args.threadId, element.level),
404-
element.function + "@" + element.address,
405-
source,
406-
element.line,
407-
0));
403+
frameDescr, // + "@" + element.address,
404+
file ? new Source(fileBasename, file) : undefined,
405+
element.line.lineCobol, 0);
408406
});
409407
response.body = {
410-
stackFrames: ret
408+
stackFrames: Array.from(ret)
411409
};
412410
this.sendResponse(response);
413411
}, (err: Error) => {

src/mi2.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,11 @@ export class MI2 extends EventEmitter implements IDebugger {
4646
constructor(public gdbpath: string, public gdbArgs: string[], procEnv: NodeJS.ProcessEnv, public noDebug: boolean, public gdbtty: boolean, public cobcrunPath: string, public useCobcrun: boolean, public sourceDirs: string[]) {
4747
super();
4848
if (procEnv) {
49-
const env = {};
50-
// Duplicate process.env so we don't override it
51-
for (const key in process.env)
52-
if (key in process.env) {
53-
env[key] = process.env[key];
54-
}
55-
// Overwrite with user specified variables
56-
for (const key in procEnv) {
57-
if (key in procEnv) {
58-
if (procEnv === null) {
59-
delete env[key];
60-
} else {
61-
env[key] = procEnv[key];
62-
}
63-
}
64-
}
65-
this.procEnv = env;
49+
this.procEnv = {...process.env, ...procEnv};
6650
}
6751
}
6852

6953
load(cwd: string, target: string, targetargs: string, group: string[], gdbtty: boolean): Thenable<unknown> {
70-
group.map(e => { path.join(cwd, e); });
71-
7254
return new Promise(async (resolve, reject) => {
7355
if (!fs.existsSync(cwd)) {
7456
reject(new Error("cwd does not exist."));
@@ -123,7 +105,6 @@ export class MI2 extends EventEmitter implements IDebugger {
123105
if (!path.isAbsolute(target)) {
124106
target = path.join(cwd, target);
125107
}
126-
group.map(e => { path.join(cwd, e) });
127108

128109
return new Promise((resolve, reject) => {
129110
if (!fs.existsSync(cwd)) {
@@ -744,9 +725,7 @@ export class MI2 extends EventEmitter implements IDebugger {
744725
const stack = <Stack[]>result.result("stack");
745726
return stack.map(element => {
746727
const level = MINode.valueOf(element, "@frame.level");
747-
const addr = MINode.valueOf(element, "@frame.addr");
748728
const func = MINode.valueOf(element, "@frame.func");
749-
const filename = MINode.valueOf(element, "@frame.file");
750729
let file: string = MINode.valueOf(element, "@frame.fullname");
751730
if (file) {
752731
file = path.normalize(file);
@@ -759,14 +738,10 @@ export class MI2 extends EventEmitter implements IDebugger {
759738
line = parseInt(lnstr);
760739
}
761740

762-
const map = this.map.getLineCobol(file, line);
763741
return {
764-
address: addr,
765-
fileName: path.basename(map.fileCobol),
766-
file: map.fileCobol,
767742
function: func || from,
768743
level: level,
769-
line: map.lineCobol
744+
line: this.map.getLineCobol(file, line)
770745
};
771746
});
772747
}

src/parser.c.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,29 @@ function cobEncodeInvalidChars (s: string): string {
3939
return s.replace("-","__");
4040
}
4141

42+
// Minimalistic one-entry cache.
43+
let currentCOBOLFileName: string = null;
44+
let currentCOBOLFileContents: string[] = [];
45+
46+
function lookupLineInCobolFile(fileCobol: string, lineCobol: number) : string | undefined {
47+
if (fileCobol && currentCOBOLFileName != fileCobol) {
48+
currentCOBOLFileName = fileCobol;
49+
try {
50+
currentCOBOLFileContents = fs.readFileSync(fileCobol).toString().split('\n');
51+
} catch (e) {
52+
log.debug(e.message);
53+
currentCOBOLFileContents = [];
54+
}
55+
}
56+
if (currentCOBOLFileContents) {
57+
return currentCOBOLFileContents[lineCobol - 1];
58+
}
59+
return undefined;
60+
}
61+
4262
export class Line {
4363
endPerformLine: number; // 002 - stepOver in routines with "perform"
64+
public cobolLine: string | undefined;
4465

4566
public constructor
4667
(public fileCobol: string,
@@ -50,6 +71,7 @@ export class Line {
5071
public lineC: number,
5172
public functionName: string) {
5273
this.endPerformLine = -1; // 002 - stepOver in routines with "perform"
74+
this.cobolLine = lookupLineInCobolFile (fileCobol, lineCobol);
5375
}
5476

5577
public toString(): string {

0 commit comments

Comments
 (0)