[qwaq] Rework def views to support multi-row defs

Needed for structured types (arrays, structs, etc). The multiple rows
aren't implemented yet, but the initial groundwork is done.
This commit is contained in:
Bill Currie 2021-06-01 23:52:04 +09:00
parent dc5ebd5c3d
commit 53b553e892
31 changed files with 154 additions and 108 deletions

View file

@ -5,6 +5,8 @@
#include "ruamoko/qwaq/ui/tableview.h"
#include "ruamoko/qwaq/debugger/debug.h"
@class DefView;
@interface LocalsData : Object <TableViewDataSource>
{
qdb_target_t target;
@ -13,6 +15,8 @@
qdb_function_t *func;
qdb_auxfunction_t *aux_func;
qdb_def_t *defs;
DefView **def_views;
int *def_rows;
void *data;
}
+(LocalsData *)withTarget:(qdb_target_t)target;

View file

@ -1,9 +1,9 @@
#include <stdlib.h>
#include <string.h>
#include <types.h>
#include "ruamoko/qwaq/debugger/views/defview.h"
#include "ruamoko/qwaq/debugger/views/nameview.h"
#include "ruamoko/qwaq/debugger/localsdata.h"
#include "ruamoko/qwaq/debugger/typeencodings.h"
@implementation LocalsData
@ -26,11 +26,24 @@
return [[[self alloc] initWithTarget:target] autorelease];
}
static void
free_defs (LocalsData *self)
{
obj_free (self.defs);
self.defs = nil;
for (int i = 0; i < self.aux_func.num_locals; i++) {
[self.def_views[i] release];
}
obj_free (self.def_views);
self.def_views = nil;
obj_free (self.def_rows);
self.def_rows = nil;
}
-(void)dealloc
{
if (defs) {
obj_free (defs);
defs = nil;
free_defs (self);
}
if (data) {
obj_free (data);
@ -46,20 +59,28 @@
current_fnum =fnum;
if (defs) {
obj_free (defs);
defs = nil;
free_defs (self);
}
if (data) {
obj_free (data);
data = nil;
}
func = qdb_get_function (target, fnum);
if (func && func.local_size) {
data = obj_malloc (func.local_size);
}
aux_func = qdb_get_auxfunction (target, fnum);
if (aux_func) {
defs = qdb_get_local_defs (target, fnum);
}
if (func && func.local_size) {
data = obj_malloc (func.local_size);
def_views = obj_malloc (aux_func.num_locals);
def_rows = obj_malloc (aux_func.num_locals + 1);
def_rows[0] = 0;
for (int i = 0; i < aux_func.num_locals; i++) {
def_views[i] = [[DefView withDef:defs[i] in:data target:target]
retain];
def_rows[i + 1] = [def_views[i] rows];
}
prefixsum (def_rows, aux_func.num_locals + 1);
}
return self;
}
@ -75,7 +96,10 @@
-(int)numberOfRows:(TableView *)tableview
{
if (aux_func) {
return aux_func.num_locals;
if (!aux_func.num_locals) {
return 0;
}
return def_rows[aux_func.num_locals];
} else if (func) {
return (func.local_size + 3) / 4;
}
@ -86,15 +110,15 @@
forColumn:(TableViewColumn *)column
row:(int)row
{
View *view;
View *view = nil;
int *index = bsearch (&row, def_rows, aux_func.num_locals, 1, nil);
if ([column name] == "name") {
view = [NameView withName:qdb_get_string (target, defs[row].name)];
} else {
qfot_type_t *type = [TypeEncodings getType:defs[row].type_encoding
fromTarget:target];
unsigned offset = defs[row].offset;
view = [DefView withType:type at:offset in:data target:target];
if (index) {
if ([column name] == "name") {
view = [def_views[*index] nameViewAtRow: row - *index];
} else {
view = [def_views[*index] dataViewAtRow: row - *index];
}
}
[view resizeTo:{[column width], 1}];
return view;

View file

@ -4,8 +4,7 @@
#include "ruamoko/qwaq/debugger/views/defview.h"
@interface BasicView : DefView
// might return a NameView (which is also a DefView)
+(DefView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(DefView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_basicview_h

View file

@ -28,7 +28,7 @@ static string type_views[] = {
return self;
}
+(DefView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(DefView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
string typename = nil;
if (type.type == ty_alias) {
@ -40,7 +40,7 @@ static string type_views[] = {
}
id class = obj_lookup_class (typename);
if (class) {
return [class withType:type at:offset in:data];
return [class withDef:def in:data type:type];
}
return [NameView withName:"Invalid Type"];
}

View file

@ -7,14 +7,16 @@
@interface DefView : View
{
qdb_def_t def;
qfot_type_t *type;
qdb_target_t target;
}
+(DefView *)withType:(qfot_type_t *)type
at:(unsigned)offset
in:(void *)data
target:(qdb_target_t)target;
-initWithType:(qfot_type_t *)type;
+(DefView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
+(DefView *)withDef:(qdb_def_t)def in:(void *)data target:(qdb_target_t)target;
-initWithDef:(qdb_def_t)def;
-(int) rows;
-(View *) nameViewAtRow:(int) row;
-(View *) dataViewAtRow:(int) row;
@end
#endif//__qwaq_debugger_defview_h

View file

@ -1,4 +1,5 @@
#include <string.h>
#include "ruamoko/qwaq/debugger/typeencodings.h"
#include "ruamoko/qwaq/debugger/views/defview.h"
#include "ruamoko/qwaq/debugger/views/nameview.h"
@ -22,12 +23,12 @@ static string meta_views[] = {
return self;
}
-initWithType:(qfot_type_t *)type
-initWithDef:(qdb_def_t)def
{
if (!(self = [super init])) {
return nil;
}
self.type = type;
self.def = def;
return self;
}
@ -37,16 +38,17 @@ static string meta_views[] = {
return self;
}
+(DefView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(DefView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [self withType:type at:offset in:data target:nil];
return [self withDef:def in:data target:nil];
}
+(DefView *)withType:(qfot_type_t *)type
at:(unsigned)offset
in:(void *)data
target:(qdb_target_t)target
+(DefView *)withDef:(qdb_def_t)def
in:(void *)data
target:(qdb_target_t)target
{
qfot_type_t *type = [TypeEncodings getType:def.type_encoding
fromTarget:target];
string metaname = nil;
if (type.meta == ty_alias) {
type = type.alias.aux_type;
@ -57,9 +59,24 @@ static string meta_views[] = {
}
id class = obj_lookup_class (metaname);
if (class) {
return [[class withType:type at:offset in:data] setTarget:target];
return [[class withDef:def in:data type:type] setTarget:target];
}
return [NameView withName:"Invalid Meta"];
}
-(int) rows
{
return 1;
}
-(View *) nameViewAtRow:(int) row
{
return [NameView withName:qdb_get_string (target, def.name)];
}
-(View *) dataViewAtRow:(int) row
{
return self;
}
@end

View file

@ -7,7 +7,7 @@
{
double *data;
}
+(DoubleView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(DoubleView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_doubleview_h

View file

@ -3,18 +3,18 @@
@implementation DoubleView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (double *)(data + offset);
self.data = (double *)(data + def.offset);
return self;
}
+(DoubleView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(DoubleView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
entity *data;
}
+(EntityView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(EntityView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_entityview_h

View file

@ -3,18 +3,18 @@
@implementation EntityView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (entity *)(data + offset);
self.data = (entity *)(data + def.offset);
return self;
}
+(EntityView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(EntityView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
unsigned *data;
}
+(FieldView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(FieldView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_fieldview_h

View file

@ -3,18 +3,18 @@
@implementation FieldView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (unsigned *)(data + offset);
self.data = (unsigned *)(data + def.offset);
return self;
}
+(FieldView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(FieldView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
float *data;
}
+(FloatView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(FloatView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_floatview_h

View file

@ -3,18 +3,18 @@
@implementation FloatView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (float *)(data + offset);
self.data = (float *)(data + def.offset);
return self;
}
+(FloatView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(FloatView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
unsigned *data;
}
+(FuncView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(FuncView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_funcview_h

View file

@ -3,18 +3,18 @@
@implementation FuncView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (unsigned *)(data + offset);
self.data = (unsigned *)(data + def.offset);
return self;
}
+(FuncView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(FuncView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
int *data;
}
+(IntView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(IntView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_intview_h

View file

@ -3,18 +3,18 @@
@implementation IntView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (int *)(data + offset);
self.data = (int *)(data + def.offset);
return self;
}
+(IntView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(IntView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -5,7 +5,7 @@
-initWithName:(string)name
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.name = name;

View file

@ -7,7 +7,7 @@
{
unsigned *data;
}
+(PointerView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(PointerView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_pointerview_h

View file

@ -3,18 +3,18 @@
@implementation PointerView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (unsigned *)(data + offset);
self.data = (unsigned *)(data + def.offset);
return self;
}
+(PointerView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(PointerView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
quaternion *data;
}
+(QuatView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(QuatView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_quatview_h

View file

@ -3,18 +3,18 @@
@implementation QuatView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (quaternion *)(data + offset);
self.data = (quaternion *)(data + def.offset);
return self;
}
+(QuatView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(QuatView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
int *data;
}
+(StringView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(StringView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_stringview_h

View file

@ -3,18 +3,18 @@
@implementation StringView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (int *)(data + offset);
self.data = (int *)(data + def.offset);
return self;
}
+(StringView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(StringView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
unsigned *data;
}
+(UIntView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(UIntView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_uintview_h

View file

@ -3,18 +3,18 @@
@implementation UIntView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (unsigned *)(data + offset);
self.data = (unsigned *)(data + def.offset);
return self;
}
+(UIntView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(UIntView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
vector *data;
}
+(VectorView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(VectorView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_vectorview_h

View file

@ -3,18 +3,18 @@
@implementation VectorView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (vector *)(data + offset);
self.data = (vector *)(data + def.offset);
return self;
}
+(VectorView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(VectorView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw

View file

@ -7,7 +7,7 @@
{
unsigned *data;
}
+(VoidView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data;
+(VoidView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type;
@end
#endif//__qwaq_debugger_voidview_h

View file

@ -3,18 +3,18 @@
@implementation VoidView
-initWithType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
-initWithDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
if (!(self = [super initWithType:type])) {
if (!(self = [super initWithDef:def])) {
return nil;
}
self.data = (unsigned *) (data + offset);
self.data = (unsigned *) (data + def.offset);
return self;
}
+(VoidView *)withType:(qfot_type_t *)type at:(unsigned)offset in:(void *)data
+(VoidView *)withDef:(qdb_def_t)def in:(void *)data type:(qfot_type_t *)type
{
return [[[self alloc] initWithType:type at:offset in:data] autorelease];
return [[[self alloc] initWithDef:def in:data type:type] autorelease];
}
-draw