Skip to content

Commit

Permalink
Implement correct RX data breakpoint descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
HampusAdolfsson committed Nov 6, 2023
1 parent f0aef99 commit 74bbac1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/dap/breakpoints/breakpointCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum BreakpointCategory {
// Data breakpoints
STD_DATA2 = "STD_DATA2",
EMUL_DATA = "EMUL_DATA",
EMUL_DATA_BREAK = "EMUL_DATA_BREAK", //RX
// Log breakpoints
STD_LOG2 = "STD_LOG2",
}
8 changes: 8 additions & 0 deletions src/dap/breakpoints/breakpointDescriptorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LocEtcDescriptor } from "./descriptors/locEtcDescriptor";
import { LocOnlyDescriptor } from "./descriptors/locOnlyDescriptor";
import { EmulDataBreakpointDescriptor } from "./descriptors/emulDataBreakpointDescriptor";
import { LogDescriptor } from "./descriptors/logDescriptor";
import { EmulDataBreakBreakpointDescriptor } from "./descriptors/emulDataBreakBreakpointDescriptor";

/**
* Creates code breakpoint descriptors. Does not registers them in the cspy backend.
Expand Down Expand Up @@ -108,6 +109,13 @@ export class EmulDataBreakpointDescriptorFactory extends DataBreakpointDescripto
}
}

export class EmulDataBreakBreakpointDescriptorFactory extends DataBreakpointDescriptorFactory {

override createOnUle(ule: string, access: AccessType): LocOnlyDescriptor {
return new EmulDataBreakBreakpointDescriptor([BreakpointCategory.EMUL_DATA_BREAK, ule, access]);
}
}

// Log Breakpoints

export class StdLog2BreakpointDescriptorFactory implements LogBreakpointDescriptorFactory {
Expand Down
4 changes: 2 additions & 2 deletions src/dap/breakpoints/cspyDriver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { CodeBreakpointDescriptorFactory, DataBreakpointDescriptorFactory, EmulCodeBreakpointDescriptorFactory, EmulDataBreakpointDescriptorFactory, HwCodeBreakpointDescriptorFactory, LogBreakpointDescriptorFactory, StdCode2BreakpointDescriptorFactory, StdData2BreakpointDescriptorFactory, StdLog2BreakpointDescriptorFactory, EmuHwCodeBreakpointDescriptorFactory, EmuSwCodeBreakpointDescriptorFactory } from "./breakpointDescriptorFactory";
import { CodeBreakpointDescriptorFactory, DataBreakpointDescriptorFactory, EmulCodeBreakpointDescriptorFactory, EmulDataBreakpointDescriptorFactory, HwCodeBreakpointDescriptorFactory, LogBreakpointDescriptorFactory, StdCode2BreakpointDescriptorFactory, StdData2BreakpointDescriptorFactory, StdLog2BreakpointDescriptorFactory, EmuHwCodeBreakpointDescriptorFactory, EmuSwCodeBreakpointDescriptorFactory, EmulDataBreakBreakpointDescriptorFactory } from "./breakpointDescriptorFactory";
import { logger } from "@vscode/debugadapter/lib/logger";
import { BreakpointType } from "./cspyBreakpointService";

Expand Down Expand Up @@ -118,7 +118,7 @@ class AvrEmuDriver implements CSpyDriver {

class RxEmuDriver implements CSpyDriver {
readonly codeBreakpointFactories: ReadonlyMap<BreakpointType, CodeBreakpointDescriptorFactory>;
readonly dataBreakpointFactory = new StdData2BreakpointDescriptorFactory();
readonly dataBreakpointFactory = new EmulDataBreakBreakpointDescriptorFactory();
readonly logBreakpointFactory = new StdLog2BreakpointDescriptorFactory();

constructor(public readonly libraryBaseNames: string[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { AccessType } from "./accessType";
import { DescriptorReader } from "./descriptorReader";
import { DescriptorWriter } from "./descriptorWriter";
import { LocOnlyDescriptor } from "./locOnlyDescriptor";

/**
* Breakpoint descriptor for EMUL_DATA_BREAK breakpoints, used by RX drivers.
*/
export class EmulDataBreakBreakpointDescriptor extends LocOnlyDescriptor {
private readonly adrCondition: number;
private readonly adrMaskStr: string;
private readonly adrMaskCompare: number;
private readonly adrRange: number;
private readonly adrEndLocStr: string;
private readonly datAccess: number;
private readonly datAccessSize: number;
private readonly datDataStr: string;
private readonly datMaskCheck: number;
private readonly datMaskStr: string;
private readonly datMaskCompare: number;

/**
* Typescript doesn't support multiple constructors, so we have to fuse them together like this.
* constructor(reader: DescriptorReader)
* Constructs a new descriptor by deserializing from the given reader.
* constructor([categoryId: string, ule: string, accessType: AccessType])
* Creates a new descriptor from scratch using the given category id, ule and access type. Other attributes
* will be given their default values.
*/
constructor(arg: DescriptorReader | [string, string, AccessType]) {
if (arg instanceof DescriptorReader) {
const reader = arg;
super(reader);
this.adrCondition = reader.readInteger();
this.adrMaskStr = reader.readString();
this.adrMaskCompare = reader.readInteger();
this.adrRange = reader.readInteger();
this.adrEndLocStr = reader.readString();
this.datAccess = reader.readInteger();
this.datAccessSize = reader.readInteger();
this.datDataStr = reader.readString();
this.datMaskCheck = reader.readInteger();
this.datMaskStr = reader.readString();
this.datMaskCompare = reader.readInteger();
} else {
const [categoryId, ule, accessType] = arg;
super([categoryId, ule]);
this.adrCondition = 0;
this.adrMaskStr = "0x0";
this.adrMaskCompare = 0;
this.adrRange = 0;
this.adrEndLocStr = "";
this.datAccess = AccessTypeToInt(accessType);
this.datAccessSize = 0;
this.datDataStr = "";
this.datMaskCheck = 0;
this.datMaskStr = "";
this.datMaskCompare = 0;
}
}

override serialize(writer: DescriptorWriter) {
super.serialize(writer);
writer.writeInteger(this.adrCondition);
writer.writeString(this.adrMaskStr);
writer.writeInteger(this.adrMaskCompare);
writer.writeInteger(this.adrRange);
writer.writeString(this.adrEndLocStr);
writer.writeInteger(this.datAccess);
writer.writeInteger(this.datAccessSize);
writer.writeString(this.datDataStr);
writer.writeInteger(this.datMaskCheck);
writer.writeString(this.datMaskStr);
writer.writeInteger(this.datMaskCompare);
}
}

// Matches the constants in RX's TdEmu.h
function AccessTypeToInt(type: AccessType) {
switch (type) {
case AccessType.ReadWrite:
return 2;
case AccessType.Write:
return 1;
case AccessType.Read:
default:
return 0;
}
}

0 comments on commit 74bbac1

Please sign in to comment.