Skip to content

Commit

Permalink
fix: Special case to handle S05 as exception
Browse files Browse the repository at this point in the history
Emulator currently returns this as default for exceptions, but 05 is
treated as a breakpoint.
  • Loading branch information
grahambates committed Nov 15, 2023
1 parent b63a8b3 commit a2c5b50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Force kill emulator if SIGKILL doesn't work
- Handle unsupported message types 'S' for stop codes and 'O' for output
- Special case to handle S05 as exception. Ideally the emulator would return appropriate codes for each exception type,
but at least for now this prevents it being treated as a breakpoint.

## [1.0.4] - 2023-11-09

Expand Down
16 changes: 15 additions & 1 deletion src/gdbClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class GdbClient {
private frameMutex = new Mutex();
private eventEmitter: EventEmitter;
private responseCallback?: (message: string) => void;
private haltStatus: HaltEvent | undefined;

constructor(socket?: Socket) {
this.eventEmitter = new EventEmitter();
Expand Down Expand Up @@ -150,6 +151,9 @@ export class GdbClient {
}

public async getHaltStatus(): Promise<HaltEvent | null> {
if (this.haltStatus) {
return this.haltStatus;
}
const response = await this.request("?");
return response.indexOf("OK") < 0 ? this.parseHaltStatus(response) : null;
}
Expand Down Expand Up @@ -336,7 +340,8 @@ export class GdbClient {
if (!message.startsWith("Te") || !message.includes("tframes")) {
logger.log(`[GDB] STOP: ${message}`);
}
this.sendEvent("stop", this.parseHaltStatus(message));
this.haltStatus = this.parseHaltStatus(message);
this.sendEvent("stop", this.haltStatus);
break;
case "W":
logger.log(`[GDB] END`);
Expand All @@ -354,6 +359,15 @@ export class GdbClient {
}

private parseHaltStatus(message: string): HaltEvent {
// Special case to treat S05 as exception:
// Emulator currently returns this code for non-specified exceptions, but normally 05 is treated as a breakpoint.
// We can differentiate because actual breakpoints use T05swbreak.
if (message === "S05") {
return {
signal: HaltSignal.SEGV,
label: "Exception",
};
}
const code = parseInt(message.substring(1, 3), 16) as HaltSignal;
const details = signalLabels[code] || "Exception";
const threadMatch = message.match(/thread:(\d+)/);
Expand Down

0 comments on commit a2c5b50

Please sign in to comment.