Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement goto for memory #98

Merged
merged 4 commits into from
May 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/client/app/project/memory/MemoryComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import {Component, OnInit} from "angular2/core";
import {MemoryService} from "./MemoryService";
import {MemoryFrame} from "../../../../common/MemoryFrame";

const HELLO_WORLD_ADDRESS: number = 4874208;
const BYTES_PER_CELL: number = 4;
const CELLS_PER_ROW: number = 10;
const ROWS: number = 10;
const MEMORY_FRAME_SIZE: number = ROWS * CELLS_PER_ROW * BYTES_PER_CELL;

@Component({
selector: 'lea-memory',
templateUrl: 'client/app/project/memory/memory.html'
Expand All @@ -16,7 +10,7 @@ export class MemoryComponent implements OnInit{
private matrix: Array<Array<string>> = [];

public constructor(private memoryService: MemoryService) {
for(let i: number = 0; i < ROWS; i++) {
for(let i: number = 0; i < this.memoryService.ROWS; i++) {
this.matrix[i] = [];
}
}
Expand All @@ -27,11 +21,11 @@ export class MemoryComponent implements OnInit{
let offset = parseInt(block.offset.substring(2), 16);
for(let i: number = 0; i < block.contents.length; i += 2) {
let positionOffset = offset + (i/2);
let rowOffset = Math.floor(positionOffset / (BYTES_PER_CELL * CELLS_PER_ROW));
let colOffset = Math.floor((positionOffset - rowOffset * (BYTES_PER_CELL * CELLS_PER_ROW)) / BYTES_PER_CELL);
let localOffset = positionOffset % BYTES_PER_CELL;
let rowOffset = Math.floor(positionOffset / (this.memoryService.BYTES_PER_CELL * this.memoryService.CELLS_PER_ROW));
let colOffset = Math.floor((positionOffset - rowOffset * (this.memoryService.BYTES_PER_CELL * this.memoryService.CELLS_PER_ROW)) / this.memoryService.BYTES_PER_CELL);
let localOffset = positionOffset % this.memoryService.BYTES_PER_CELL;
//console.log('pos: %s, row: %s, col: %s, loc: %s', positionOffset, rowOffset, colOffset, localOffset);
if(rowOffset < 0 || rowOffset >= ROWS || colOffset < 0 || colOffset >= ROWS)
if(rowOffset < 0 || rowOffset >= this.memoryService.ROWS || colOffset < 0 || colOffset >= this.memoryService.ROWS)
continue;
if(!this.matrix[rowOffset][colOffset]) {
this.matrix[rowOffset][colOffset] = '0xjjjjjjjj';
Expand All @@ -43,19 +37,18 @@ export class MemoryComponent implements OnInit{
}
});
});
this.memoryService.updateMemoryFrame(new MemoryFrame(HELLO_WORLD_ADDRESS, MEMORY_FRAME_SIZE));
}

private moveUp() {
let jumpAddress = this.memoryService.MemoryFrame.start + MEMORY_FRAME_SIZE;
let jumpAddress = this.memoryService.MemoryFrame.start + this.memoryService.MEMORY_FRAME_SIZE;
if(jumpAddress < 0) {
jumpAddress = 0;
}
this.memoryService.updateMemoryFrame(new MemoryFrame(jumpAddress, MEMORY_FRAME_SIZE));
this.memoryService.updateMemoryFrame(new MemoryFrame(jumpAddress, this.memoryService.MEMORY_FRAME_SIZE));
}

private moveDown() {
this.memoryService.updateMemoryFrame(new MemoryFrame(this.memoryService.MemoryFrame.start - MEMORY_FRAME_SIZE, MEMORY_FRAME_SIZE));
this.memoryService.updateMemoryFrame(new MemoryFrame(this.memoryService.MemoryFrame.start - this.memoryService.MEMORY_FRAME_SIZE, this.memoryService.MEMORY_FRAME_SIZE));
}


Expand Down
33 changes: 30 additions & 3 deletions src/client/app/project/memory/MemoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import {AnswerContext} from "../../../../common/AnswerContext";

@Injectable()
export class MemoryService {
private _frame: MemoryFrame;

private _blocks: BehaviorSubject<Array<MemoryBlock>>;
public memoryBlocksChanged$;
private _frame: MemoryFrame;
private _frameSubject: BehaviorSubject<MemoryFrame>;
public memoryFrameChanged$;

public constructor(private socketService: SocketService) {
this._blocks = new BehaviorSubject<Array<MemoryBlock>>([]);
this.memoryBlocksChanged$ = this._blocks.asObservable();
this._frameSubject = new BehaviorSubject<MemoryFrame>(null);
this.memoryFrameChanged$ = this._frameSubject.asObservable();
this.socketService.subscribeToContext('memoryUpdate', (context: AnswerContext) => {
console.log(context.payload);
this._blocks.next(context.payload);
});
this.updateMemoryFrame(new MemoryFrame(this.HELLO_WORLD_ADDRESS, this.MEMORY_FRAME_SIZE));
}

public get MemoryFrame() : MemoryFrame {
Expand All @@ -27,9 +32,31 @@ export class MemoryService {

public updateMemoryFrame(frame: MemoryFrame) {
this._frame = frame;
this._frameSubject.next(frame);
this.socketService.sendCommand('changeMemoryFrame', frame, () => {

});
}


public goto(start: number) {
let frame = new MemoryFrame(start, this.MEMORY_FRAME_SIZE);
this.updateMemoryFrame(frame);
// highlight memory panel could be triggered here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #99

}

public get HELLO_WORLD_ADDRESS() : number {
return 4874208
}
public get BYTES_PER_CELL() : number {
return 4;
}
public get CELLS_PER_ROW() : number {
return 10;
}
public get ROWS() : number {
return 10;
}
public get MEMORY_FRAME_SIZE() : number{
return this.ROWS * this.CELLS_PER_ROW * this.BYTES_PER_CELL;
}
}
1 change: 0 additions & 1 deletion src/client/app/project/registers/RegisterPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export class RegisterPipe implements PipeTransform {
}
let binary:string = registerContent.toString(16);
for (let i = binary.length; i < 8;++i) {
console.log(binary);
binary = '0' + binary;
}
return '0x' + binary;
Expand Down
7 changes: 6 additions & 1 deletion src/client/app/project/registers/RegistersComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {SocketService} from "../socket/SocketService";
import {Register} from "../../../../common/Debugger";
import {RegisterPipe} from './RegisterPipe'
import {AnswerContext} from "../../../../common/AnswerContext";
import {MemoryService} from "../memory/MemoryService";

const INTEGER_REGISTER_NAMES: string[] = [
'zero', 'at', 'v0', 'v1', 'a0', 'a1', 'a2', 'a3',
Expand All @@ -20,11 +21,15 @@ const INTEGER_REGISTER_NAMES: string[] = [
export class RegistersComponent {
private integerRegisters: Register[] = [];

constructor(private socketService: SocketService) {
constructor(private socketService: SocketService, private memoryService: MemoryService) {
socketService.subscribeToContext('registerUpdate', (answer: AnswerContext) => {
this.integerRegisters = answer.payload.filter((register: Register) => {
return INTEGER_REGISTER_NAMES.indexOf(register.name) > 0;
});
});
}

private gotoInMemory(register: Register) {
this.memoryService.goto(register.value);
}
}
2 changes: 1 addition & 1 deletion src/client/app/project/registers/registers.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h4>Registers</h4>
<table>
<tr *ngFor="#register of integerRegisters">
<td>{{register.name}}</td><td>{{register.value | register }}</td>
<td>{{register.name}}</td><td>{{register.value | register }}</td><td><span (click)="gotoInMemory(register)">[Go]</span></td>
</tr>
</table>
21 changes: 17 additions & 4 deletions src/server/commands/RunCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ export class RunCommand extends AbstractCommand<RunPayload> {
this.sendProgramStoppedEvent(new SourceLocation(basename(stoppedEvent.frame.filename), stoppedEvent.frame.line), stoppedEvent.breakpointId);
});
mips.on('exit', (code: number, signal: string) => {
executionContext.socketSession.emit('exit', {
code: code,
signal: signal
}, []);
this.sendExitEvent(code, signal);
});
}

Expand All @@ -94,6 +91,22 @@ export class RunCommand extends AbstractCommand<RunPayload> {
});
}

private sendExitEvent(code, signal) {
this.executionContext.socketSession.mipsSession.readMemory(this.executionContext.socketSession.memoryFrame, (err, memoryBlocks?: dbgmits.IMemoryBlock[]) => {
if(err) {
console.error(err);
return this.executionContext.socketSession.emit('exit', {
code: code,
signal: signal
}, []);
}
this.executionContext.socketSession.emit('exit', {
code: code,
signal: signal
}, [new AnswerContext("memoryUpdate", memoryBlocks)]);
});
}

public canUse(payload:any):payload is RunPayload {
return typeof payload.project !== 'undefined'
&& payload.project.files instanceof Array
Expand Down