Messaging over debug channel.

This commit is contained in:
Ben Vanik 2013-12-22 00:21:35 -08:00
parent a9378eb7eb
commit 80d8dc02aa
13 changed files with 319 additions and 20 deletions

View file

@ -1,4 +1,4 @@
<div class="debugger-main">
<div class="debugger-main" ng-controller="CodeTabController">
<div class="debugger-header">
debug header/toolbar/etc
<div ui-view></div>

View file

@ -0,0 +1,32 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
'use strict';
var module = angular.module('xe.ui.code', [
'xe.log',
'xe.session'
]);
module.controller('CodeTabController', function(
$rootScope, $scope, app, log) {
$rootScope.$on('refresh', function() {
var dataSource = app.session.dataSource;
dataSource.getModuleList().then(function(list) {
console.log(list);
}, function(e) {
log('Unable to fetch module list');
});
console.log('refresh');
});
});

View file

@ -13,12 +13,15 @@
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<div class="btn-group navbar-btn">
<button type="button" class="btn btn-default" ng-click="connectClicked()" ng-disabled="app.loading">
<button type="button" class="btn btn-default" ng-click="connect()" ng-disabled="app.loading">
<span class="glyphicon glyphicon-link"></span> Connect
</button>
<button type="button" class="btn btn-default" ng-click="openClicked()" ng-disabled="app.loading">
<button type="button" class="btn btn-default" ng-click="open()" ng-disabled="app.loading">
<span class="glyphicon glyphicon-file"></span> Open
</button>
<button type="button" class="btn btn-default" ng-click="refresh()" ng-disabled="app.loading">
<span class="glyphicon glyphicon-refresh"></span> Refresh
</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" ng-disabled="app.loading">
<span class="glyphicon glyphicon-cog"></span> <span class="caret"></span>
</button>

View file

@ -13,9 +13,13 @@ var module = angular.module('xe.ui.navbar', []);
module.controller('NavbarController', function(
$scope, $state, app, log) {
$rootScope, $scope, $state, app, log) {
$scope.connectClicked = function() {
$scope.refresh = function() {
$rootScope.$emit('refresh');
};
$scope.connect = function() {
// TODO(benvanik): show a fancy dialog or something.
var oldSession = app.session;
app.connect().then(function(session) {
@ -34,7 +38,7 @@ module.controller('NavbarController', function(
});
};
$scope.openClicked = function() {
$scope.open = function() {
var inputEl = document.createElement('input');
inputEl.type = 'file';
inputEl.accept = '.xe-trace,application/x-extension-xe-trace';

View file

@ -31,6 +31,7 @@
<script src="src/session.js"></script>
<script src="assets/ui/navbar.js"></script>
<script src="assets/ui/console/console.js"></script>
<script src="assets/ui/code/code-tab.js"></script>
<script src="debugger.js"></script>
</body>

View file

@ -17,6 +17,7 @@ var module = angular.module('app', [
'xe.log',
'xe.router',
'xe.session',
'xe.ui.code',
'xe.ui.console',
'xe.ui.navbar'
]);

View file

@ -12,20 +12,88 @@
var module = angular.module('xe.datasources', []);
var DataSource = function(source) {
this.source = source;
this.online = false;
this.status = 'disconnected';
};
DataSource.prototype.open = function() {};
DataSource.prototype.dispose = function() {};
module.service('DataSource', function($q) {
var DataSource = function(source) {
this.source = source;
this.online = false;
this.status = 'disconnected';
};
DataSource.prototype.open = function() {};
DataSource.prototype.dispose = function() {};
DataSource.prototype.issue = function(command) {};
DataSource.prototype.addBreakpoint = function(breakpoint) {
return this.addBreakpoints([breakpoint]);
};
module.service('RemoteDataSource', function($q) {
DataSource.prototype.addBreakpoints = function(breakpoints) {
if (!breakpoints.length) {
var d = $q.defer();
d.resolve();
return d.promise;
}
return this.issue({
command: 'cpu.add_breakpoints',
breakpoints: breakpoints.map(function(breakpoint) {
return breakpoint.toJSON();
})
});
};
DataSource.prototype.removeBreakpoint = function(breakpointId) {
return this.removeBreakpoints([breakpointId]);
};
DataSource.prototype.removeBreakpoints = function(breakpointIds) {
return this.issue({
command: 'cpu.remove_breakpoints',
breakpointIds: breakpointIds
});
};
DataSource.prototype.removeAllBreakpoints = function() {
return this.issue({
command: 'cpu.remove_all_breakpoints'
});
};
DataSource.prototype.getModuleList = function() {
return this.issue({
command: 'cpu.get_module_list'
});
};
DataSource.prototype.getModule = function(moduleId) {
return this.issue({
command: 'cpu.get_module',
moduleId: moduleId
});
};
DataSource.prototype.getFunctionList = function(moduleId) {
return this.issue({
command: 'cpu.get_function_list',
moduleId: moduleId
});
};
DataSource.prototype.getFunction = function(address) {
return this.issue({
command: 'cpu.get_function',
address: address
});
};
return DataSource;
});
module.service('RemoteDataSource', function($q, DataSource) {
var RemoteDataSource = function(url) {
DataSource.call(this, url);
this.url = url;
this.socket = null;
this.nextRequestId_ = 1;
this.pendingRequests_ = {};
};
inherits(RemoteDataSource, DataSource);
@ -62,12 +130,28 @@ module.service('RemoteDataSource', function($q) {
this.socket.onmessage = (function(e) {
console.log('message', e.data);
var json = JSON.parse(e.data);
if (json.requestId) {
// Response to a previous request.
var request = this.pendingRequests_[json.requestId];
if (request) {
delete this.pendingRequests_[json.requestId];
if (json.status) {
request.deferred.resolve(json.result);
} else {
request.deferred.reject(json.result);
}
}
} else {
// Notification.
}
}).bind(this);
return d.promise;
};
RemoteDataSource.prototype.dispose = function() {
this.pendingRequests_ = {};
this.online = false;
this.status = 'disconnected';
if (this.socket) {
@ -77,11 +161,20 @@ module.service('RemoteDataSource', function($q) {
DataSource.prototype.dispose.call(this);
};
RemoteDataSource.prototype.issue = function(command) {
var d = $q.defer();
command.requestId = this.nextRequestId_++;
this.socket.send(JSON.stringify(command));
command.deferred = d;
this.pendingRequests_[command.requestId] = command;
return d.promise;
};
return RemoteDataSource;
});
module.service('FileDataSource', function($q) {
module.service('FileDataSource', function($q, DataSource) {
var FileDataSource = function(file) {
DataSource.call(this, file.name);
this.file = file;