Skip to content

Commit f7b4f9e

Browse files
authored
Merge pull request #343 from intersystems-community/debugger-fixes
Fix issues with debugger
2 parents af4c0bd + 5ee31a1 commit f7b4f9e

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class AtelierAPI {
123123
return !!this._config.active && host.length > 0 && port > 0;
124124
}
125125

126-
private get cookies(): string[] {
126+
public get cookies(): string[] {
127127
return this.cache.get("cookies", []);
128128
}
129129

src/debug/debugSession.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
8585

8686
private _evalResultProperties = new Map<number, xdebug.EvalResultProperty>();
8787

88+
private cookies: string[] = [];
89+
8890
public constructor() {
8991
super();
9092

9193
const api = new AtelierAPI();
94+
this.cookies = api.cookies;
9295
if (!api.active) {
9396
throw new Error("Connection not active");
9497
}
@@ -114,7 +117,11 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
114117
supportsStepBack: false,
115118
};
116119

117-
const socket = new WebSocket(this._url);
120+
const socket = new WebSocket(this._url, {
121+
headers: {
122+
cookie: this.cookies,
123+
},
124+
});
118125

119126
const disposeConnection = (error?: Error): void => {
120127
this.sendEvent(new ThreadEvent("exited", this._connection.id));
@@ -130,24 +137,30 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
130137
this.sendEvent(new OutputEvent(data, "stdout"));
131138
});
132139

133-
await this._connection.waitForInitPacket();
140+
try {
141+
await this._connection.waitForInitPacket();
134142

135-
await this._connection.sendFeatureSetCommand("max_data", 8192);
136-
await this._connection.sendFeatureSetCommand("max_children", 32);
137-
await this._connection.sendFeatureSetCommand("max_depth", 2);
138-
await this._connection.sendFeatureSetCommand("notify_ok", 1);
143+
await this._connection.sendFeatureSetCommand("max_data", 8192);
144+
await this._connection.sendFeatureSetCommand("max_children", 32);
145+
await this._connection.sendFeatureSetCommand("max_depth", 2);
146+
await this._connection.sendFeatureSetCommand("notify_ok", 1);
139147

140-
this.sendResponse(response);
148+
this.sendResponse(response);
141149

142-
this.sendEvent(new InitializedEvent());
150+
this.sendEvent(new InitializedEvent());
151+
} catch (error) {
152+
response.success = false;
153+
response.message = "Debugger can not start";
154+
this.sendResponse(response);
155+
}
143156
}
144157

145158
protected async launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): Promise<void> {
146159
// this._args = args;
147160

148161
try {
149162
const debugTarget = `${this._namespace}:${args.program}`;
150-
await this._connection.sendFeatureSetCommand("debug_target", debugTarget);
163+
await this._connection.sendFeatureSetCommand("debug_target", debugTarget, true);
151164

152165
this._debugTargetSet.notify();
153166
} catch (error) {

src/debug/xdebugConnection.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,14 @@ export class Connection extends DbgpConnection {
719719
* - show_hidden
720720
* - notify_ok
721721
*/
722-
public async sendFeatureSetCommand(feature: string, value: string | number): Promise<FeatureSetResponse> {
723-
return new FeatureSetResponse(await this._enqueueCommand("feature_set", `-n ${feature} -v ${value}`), this);
722+
public async sendFeatureSetCommand(
723+
feature: string,
724+
value: string | number,
725+
base64 = false
726+
): Promise<FeatureSetResponse> {
727+
const v =
728+
typeof value === "string" && base64 ? `-v_base64 ${Buffer.from(value).toString("base64")}` : `-v ${value}`;
729+
return new FeatureSetResponse(await this._enqueueCommand("feature_set", `-n ${feature} ${v}`), this);
724730
}
725731

726732
// ---------------------------- breakpoints ------------------------------------

0 commit comments

Comments
 (0)