Skip to content

Commit 5905687

Browse files
author
Your Name
committed
Changes so that breakpoint cmdlets return the breakpiont id.
1 parent 9031824 commit 5905687

7 files changed

Lines changed: 37 additions & 19 deletions

File tree

src/breakpoints/bp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export abstract class Bp {
3737
public conditions: string[] = [];
3838
public commands: string[] = [];
3939

40+
public static idToVar(id: number): Var {
41+
return new Var(uint64(id.toString()), `#${id}`);
42+
}
43+
4044
protected constructor(
4145
index: number,
4246
address: Var | null,

src/breakpoints/regs.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Var } from '../vars/var.js';
2+
import { Bp } from './bp.js';
23

34
enum PseudoRegNames {
45
TID = 'tid',
@@ -57,10 +58,7 @@ export class Regs {
5758
}
5859

5960
public static setBreakpointId(breakpointId: number) {
60-
this.pseudoRegs[PseudoRegNames.BP] = new Var(
61-
uint64(breakpointId.toString()),
62-
`#${breakpointId}`,
63-
);
61+
this.pseudoRegs[PseudoRegNames.BP] = Bp.idToVar(breakpointId);
6462
}
6563

6664
public static get(name: string): Var {

src/breakpoints/replace.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export class BpReplacement extends Bp {
4646
const idxString = Output.green(`#${this.index.toString()}.`.padEnd(4, ' '));
4747
const targetString = `target: ${Output.blue(this.target.getLiteral())}`;
4848
const addressString = `address: ${Output.blue(this.literal)}`;
49-
return `${idxString} ${addressString} -> ${targetString}`;
49+
let tranmpolineString = '';
50+
if (this.trampoline !== null) {
51+
tranmpolineString = `trampoline: ${Output.blue(Format.toHexString(this.trampoline.toPointer()))}`;
52+
}
53+
return `${idxString} ${addressString} -> ${targetString} [${tranmpolineString}]`;
5054
}
5155
}

src/cmdlets/breakpoints/code.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BpType } from '../../breakpoints/bp.js';
1+
import { Bp, BpType } from '../../breakpoints/bp.js';
22
import { Bps } from '../../breakpoints/bps.js';
33
import {
44
BpCodeInstruction,
@@ -52,7 +52,7 @@ abstract class CodeBpCmdLet extends TypedBpCmdLet {
5252
throw new Error(`unexpected breakpoint type: ${this.bpType}`);
5353
}
5454

55-
return addr;
55+
return Bp.idToVar(idx);
5656
}
5757

5858
protected runModify(tokens: Token[]): Var | null {
@@ -81,7 +81,7 @@ abstract class CodeBpCmdLet extends TypedBpCmdLet {
8181
Output.writeln(`Modified ${bp.toString()}`);
8282
this.editBreakpoint(bp, conditional);
8383

84-
return addr ?? Var.ZERO;
84+
return Bp.idToVar(index);
8585
}
8686

8787
protected override usageCreate(): string {

src/cmdlets/breakpoints/mem.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BpType } from '../../breakpoints/bp.js';
1+
import { Bp, BpType } from '../../breakpoints/bp.js';
22
import { Bps } from '../../breakpoints/bps.js';
33
import { BpReadMemory, BpWriteMemory } from '../../breakpoints/memory.js';
44
import { CmdLetBase } from '../../commands/cmdlet.js';
@@ -46,7 +46,7 @@ abstract class MemoryBpCmdLet extends TypedBpCmdLet {
4646
throw new Error(`unexpected breakpoint type: ${this.bpType}`);
4747
}
4848

49-
return addr ?? Var.ZERO;
49+
return Bp.idToVar(idx);
5050
}
5151

5252
protected runModify(tokens: Token[]): Var | null {
@@ -75,7 +75,7 @@ abstract class MemoryBpCmdLet extends TypedBpCmdLet {
7575
Output.writeln(`Modified ${bp.toString()}`);
7676
this.editBreakpoint(bp, conditional);
7777

78-
return addr ?? Var.ZERO;
78+
return Bp.idToVar(index);
7979
}
8080

8181
protected override usageCreate(): string {

src/cmdlets/breakpoints/replace.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Token } from '../../io/token.js';
22
import { Var } from '../../vars/var.js';
33
import { TypedBpCmdLet } from './bp.js';
4-
import { BpType } from '../../breakpoints/bp.js';
4+
import { Bp, BpType } from '../../breakpoints/bp.js';
55
import { Bps } from '../../breakpoints/bps.js';
66
import { BpReplacement } from '../../breakpoints/replace.js';
77
import { Output } from '../../io/output.js';
@@ -20,16 +20,28 @@ export class ReplaceCmdLet extends TypedBpCmdLet {
2020
const index = Bps.getNextFreeIndex(this.bpType);
2121
const bp = new BpReplacement(index, address, target);
2222
Bps.add(bp);
23-
Output.writeln(`Created ${bp.toString()}`);
2423
bp.enable();
25-
return bp.trampoline;
24+
Output.writeln(`Created ${bp.toString()}`);
25+
return Bp.idToVar(index);
2626
} catch (error) {
2727
throw new Error(`failed to replace ${address} with ${target}, ${error}`);
2828
}
2929
}
3030

31-
protected override runModify(_tokens: Token[]): Var | null {
32-
return null;
31+
/*
32+
* This function doesn't actually modify the breakpoint, but rather since it
33+
* is called berfore runShow in the parent it allows us to match those same
34+
* arguments and overload it to return the trampoline address in the event
35+
* that a breakpoint id was specified.
36+
*/
37+
protected override runModify(tokens: Token[]): Var | null {
38+
const vars = this.transform(tokens, [this.parseIndex]);
39+
if (vars === null) return null;
40+
const [index] = vars as [number];
41+
const bp = Bps.get(this.bpType, index) as BpReplacement;
42+
if (bp === null) throw new Error(`breakpoint #${index} doesn't exist`);
43+
Output.writeln(bp.toString());
44+
return bp.trampoline;
3345
}
3446

3547
protected override usageCreate(): string {

src/cmdlets/breakpoints/trace.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BpType } from '../../breakpoints/bp.js';
1+
import { Bp, BpType } from '../../breakpoints/bp.js';
22
import { Bps } from '../../breakpoints/bps.js';
33
import {
44
BpBlockTrace,
@@ -68,7 +68,7 @@ abstract class TraceBpCmdLet extends TypedBpCmdLet {
6868
throw new Error(`unexpected breakpoint type: ${this.bpType}`);
6969
}
7070

71-
return addr ?? Var.ZERO;
71+
return Bp.idToVar(idx);
7272
}
7373

7474
protected runModify(tokens: Token[]): Var | null {
@@ -100,7 +100,7 @@ abstract class TraceBpCmdLet extends TypedBpCmdLet {
100100
Output.writeln(`Modified ${bp.toString()}`);
101101
this.editBreakpoint(bp, conditional);
102102

103-
return addr ?? Var.ZERO;
103+
return Bp.idToVar(index);
104104
}
105105

106106
protected override usageCreate(): string {

0 commit comments

Comments
 (0)