Skip to content

Commit

Permalink
Fixes for attached debugging and related improvements. (#784)
Browse files Browse the repository at this point in the history
'launch' and 'attach' modes are working with these changes. The root problems were related to the version of the attached project not being detected properly and file paths not being correctly calculated when attached. The networking code that had version-dependent behavior is now a bit more robust and won't break if minor versions were to ever exceed 1 digit.
When using 'attach' mode, the version info wasn't available at all, causing most (all?) network messages to be ignored.
  • Loading branch information
ecosky authored Feb 22, 2025
1 parent 53f48ed commit 0352112
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/debugger/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class GodotDebugger implements DebugAdapterDescriptorFactory, DebugConfig
log.info(`Project version identified as ${projectVersion}`);

if (projectVersion.startsWith("4")) {
this.session = new Godot4DebugSession();
this.session = new Godot4DebugSession(projectVersion);
} else {
this.session = new Godot3DebugSession();
}
Expand Down
5 changes: 4 additions & 1 deletion src/debugger/godot4/debug_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ export class GodotDebugSession extends LoggingDebugSession {

public variables_manager: VariablesManager;

public constructor() {
public constructor(projectVersion : string) {
super();

this.setDebuggerLinesStartAt1(false);
this.setDebuggerColumnsStartAt1(false);

this.controller.setProjectVersion(projectVersion);
}

public dispose() {
Expand Down Expand Up @@ -91,6 +93,7 @@ export class GodotDebugSession extends LoggingDebugSession {

this.mode = "attach";

this.debug_data.projectPath = args.project;
this.exception = false;
await this.controller.attach(args);

Expand Down
17 changes: 13 additions & 4 deletions src/debugger/godot4/server_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,19 @@ export class ServerController {
private steppingOut = false;
private didFirstOutput = false;
private partialStackVars: GodotPartialStackVars;
private connectedVersion = "";
private projectVersionMajor: number;
private projectVersionMinor : number;
private projectVersionPoint : number;

public constructor(public session: GodotDebugSession) {}

public setProjectVersion(projectVersion: string) {
const versionParts = projectVersion.split('.').map(Number);
this.projectVersionMajor = versionParts[0] || 0;
this.projectVersionMinor = versionParts[1] || 0;
this.projectVersionPoint = versionParts[2] || 0;
}

public break() {
this.send_command("break");
}
Expand Down Expand Up @@ -204,7 +213,7 @@ export class ServerController {
}
}

this.connectedVersion = result.version;
this.setProjectVersion(result.version);

let command = `"${godotPath}" --path "${args.project}"`;
const address = args.address.replace("tcp://", "");
Expand Down Expand Up @@ -381,7 +390,7 @@ export class ServerController {
const command = new Command();
let i = 0;
command.command = dataset[i++];
if (this.connectedVersion[2] >= "2") {
if (this.projectVersionMinor >= 2) {
command.threadId = dataset[i++];
}
command.parameters = dataset[i++];
Expand Down Expand Up @@ -691,7 +700,7 @@ export class ServerController {

private send_command(command: string, parameters?: any[]) {
const commandArray: any[] = [command];
if (this.connectedVersion[2] >= "2") {
if (this.projectVersionMinor >= 2) {
commandArray.push(this.threadId);
}
commandArray.push(parameters ?? []);
Expand Down

0 comments on commit 0352112

Please sign in to comment.