Skip to content

Commit f9a6718

Browse files
minor fixes on readMemory handling
1 parent 8431524 commit f9a6718

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/views/component-viewer/scvd-debug-target.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class ScvdDebugTarget {
208208
/**
209209
* Decode a (possibly unpadded) base64 string from GDB into bytes.
210210
*/
211-
public decodeGdbData(data: string): Uint8Array {
211+
public decodeGdbData(data: string): Uint8Array | undefined {
212212
// Fix missing padding: base64 length must be a multiple of 4
213213
const padLength = (4 - (data.length % 4)) % 4;
214214
const padded = data + '='.repeat(padLength);
@@ -229,7 +229,8 @@ export class ScvdDebugTarget {
229229
return bytes;
230230
}
231231

232-
throw new Error('No base64 decoder available in this environment');
232+
console.error('ScvdDebugTarget.decodeGdbData: no base64 decoder available in this environment');
233+
return undefined;
233234
}
234235

235236
public async readMemory(address: number | bigint, size: number): Promise<Uint8Array | undefined> {
@@ -251,11 +252,11 @@ export class ScvdDebugTarget {
251252
}
252253
// Convert String data to Uint8Array
253254
const byteArray = this.decodeGdbData(dataAsString);
254-
255-
if (byteArray.length !== size) {
256-
return byteArray;
255+
if (byteArray === undefined) {
256+
return undefined;
257257
}
258-
return byteArray;
258+
259+
return byteArray.length === size ? byteArray : undefined;
259260
}
260261

261262
public readUint8ArrayStrFromPointer(address: number | bigint, bytesPerChar: number, maxLength: number): Promise<Uint8Array | undefined> {

src/views/component-viewer/test/integration/scvd-debug-target.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('scvd-debug-target', () => {
187187
errorSpy.mockRestore();
188188

189189
accessMock.evaluateMemory.mockResolvedValue('AQID'); // len 3 vs requested 4
190-
await expect(target.readMemory(0x0, 4)).resolves.toEqual(new Uint8Array([1, 2, 3]));
190+
await expect(target.readMemory(0x0, 4)).resolves.toBeUndefined();
191191
});
192192

193193
it('calculates memory usage and overflow bit', async () => {

0 commit comments

Comments
 (0)