Skip to content

Commit 50cf7fd

Browse files
committed
Sync debugger from PNut v49
1 parent c9c4aad commit 50cf7fd

File tree

4 files changed

+3648
-3503
lines changed

4 files changed

+3648
-3503
lines changed

backends/brkdebug.c

Lines changed: 76 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum DebugBytecode {
2424
DBC_DELAY = 7,
2525
DBC_PC_KEY = 8,
2626
DBC_PC_MOUSE = 9,
27+
DBC_CZ = 10, // this one is special because DBC_FLAG_NOCOMMA applies to it
2728

2829
// Flags
2930
DBC_FLAG_NOCOMMA = 0x01,
@@ -37,6 +38,7 @@ enum DebugBytecode {
3738
// Output type
3839
DBC_TYPE_STR = 0x20 | DBC_SIZE_BYTE,
3940
DBC_TYPE_FLP = 0x20, // Note the overlap with the signed flag and the string type
41+
DBC_TYPE_BOL = 0x20, // etc, etc
4042
DBC_TYPE_DEC = 0x40,
4143
DBC_TYPE_HEX = 0x80,
4244
DBC_TYPE_BIN = 0xC0,
@@ -55,6 +57,9 @@ static struct DebugFunc debug_func_table[] = {
5557
{"dly" ,DBC_DELAY},
5658
{"pc_key" ,DBC_PC_KEY},
5759
{"pc_mouse" ,DBC_PC_MOUSE},
60+
{"c_z" ,DBC_CZ},
61+
62+
{"bool" ,DBC_TYPE_BOL},
5863

5964
{"zstr" ,DBC_TYPE_STR},
6065
{"lstr" ,DBC_TYPE_STR|DBC_FLAG_ARRAY},
@@ -256,80 +261,87 @@ int AsmDebug_CodeGen(AST *ast, BackendDebugEval evalFunc, void *evalArg) {
256261
if (simple && noExpr) {
257262
ERROR(item,"Cannot use underscore on simple functions");
258263
}
259-
if (!simple && !needcomma) opcode |= DBC_FLAG_NOCOMMA;
264+
if ((!simple || opcode == DBC_CZ) && !needcomma) opcode |= DBC_FLAG_NOCOMMA;
260265
if (!simple && noExpr) opcode |= DBC_FLAG_NOEXPR;
261266

262-
int expectedArgs = (func->opcode & DBC_FLAG_ARRAY) ? 2 : 1;
263-
int gotArgs = 0;
264-
ASSERT_AST_KIND(item->right,AST_EXPRLIST,break;);
265-
for (AST *arglist=item->right;arglist;arglist=arglist->right) {
266-
if (gotArgs == 0) {
267-
flexbuf_putc(opcode,f);
268-
DEBUG(item,"Emitting DEBUG opcode %02X",opcode);
269-
}
270-
gotArgs++;
271-
AST *arg = arglist->left;
272-
int addrKind, addr;
273-
274-
if (gotArgs==1 && !simple && !noExpr) {
275-
// TOOD: Yoink expression string from source buffer
276-
AST *exprAst = arg;
277-
if (exprAst->kind==AST_IMMHOLDER) {
278-
flexbuf_putc('#',f);
279-
exprAst = exprAst->left;
280-
}
281-
if (IsIdentifier(exprAst)) {
282-
const char *expr = GetUserIdentifierName(exprAst);
283-
flexbuf_addstr(f,expr);
284-
} else {
285-
PrintExpr(f, exprAst, PRINTEXPR_DEBUG);
267+
if ((opcode & ~DBC_FLAG_NOCOMMA) == DBC_CZ) {
268+
// Special no-argument function C_Z (I hate what I have brought upon myself)
269+
if (item->right && item->right->left) ERROR(item,"C_Z takes no arguments");
270+
flexbuf_putc(opcode,f);
271+
DEBUG(item,"Emitting DEBUG opcode %02X",opcode);
272+
} else {
273+
int expectedArgs = (func->opcode & DBC_FLAG_ARRAY) ? 2 : 1;
274+
int gotArgs = 0;
275+
ASSERT_AST_KIND(item->right,AST_EXPRLIST,break;);
276+
for (AST *arglist=item->right;arglist;arglist=arglist->right) {
277+
if (gotArgs == 0) {
278+
flexbuf_putc(opcode,f);
279+
DEBUG(item,"Emitting DEBUG opcode %02X",opcode);
286280
}
287-
flexbuf_putc(0,f);
288-
}
289-
290-
addrKind = (*evalFunc)(arg, regNum, &addr, evalArg);
291-
switch (addrKind) {
292-
case PASM_EVAL_ISCONST:
293-
emitAsmConstant(f, addr);
294-
break;
295-
case PASM_EVAL_ISREG:
296-
emitAsmRegref(f, addr);
297-
regNum++;
298-
break;
299-
case PASM_EVAL_ISREG_2:
300-
case PASM_EVAL_ISREG_3:
301-
case PASM_EVAL_ISREG_4:
302-
emitAsmRegref(f, addr);
303-
regNum++;
304-
addr++;
305-
for (int n = PASM_EVAL_ISREG; n < addrKind; n++) {
306-
if (gotArgs == expectedArgs) {
307-
opcode &= ~DBC_FLAG_NOCOMMA;
308-
flexbuf_putc(opcode|DBC_FLAG_NOEXPR, f);
309-
DEBUG(item,"Emitting DEBUG opcode %02X",opcode|DBC_FLAG_NOEXPR);
310-
gotArgs = 1;
281+
gotArgs++;
282+
AST *arg = arglist->left;
283+
int addrKind, addr;
284+
285+
if (gotArgs==1 && !simple && !noExpr) {
286+
// TOOD: Yoink expression string from source buffer
287+
AST *exprAst = arg;
288+
if (exprAst->kind==AST_IMMHOLDER) {
289+
flexbuf_putc('#',f);
290+
exprAst = exprAst->left;
291+
}
292+
if (IsIdentifier(exprAst)) {
293+
const char *expr = GetUserIdentifierName(exprAst);
294+
flexbuf_addstr(f,expr);
311295
} else {
312-
gotArgs++;
296+
PrintExpr(f, exprAst, PRINTEXPR_DEBUG);
313297
}
298+
flexbuf_putc(0,f);
299+
}
300+
301+
addrKind = (*evalFunc)(arg, regNum, &addr, evalArg);
302+
switch (addrKind) {
303+
case PASM_EVAL_ISCONST:
304+
emitAsmConstant(f, addr);
305+
break;
306+
case PASM_EVAL_ISREG:
307+
emitAsmRegref(f, addr);
308+
regNum++;
309+
break;
310+
case PASM_EVAL_ISREG_2:
311+
case PASM_EVAL_ISREG_3:
312+
case PASM_EVAL_ISREG_4:
314313
emitAsmRegref(f, addr);
315-
addr++; regNum++;
314+
regNum++;
315+
addr++;
316+
for (int n = PASM_EVAL_ISREG; n < addrKind; n++) {
317+
if (gotArgs == expectedArgs) {
318+
opcode &= ~DBC_FLAG_NOCOMMA;
319+
flexbuf_putc(opcode|DBC_FLAG_NOEXPR, f);
320+
DEBUG(item,"Emitting DEBUG opcode %02X",opcode|DBC_FLAG_NOEXPR);
321+
gotArgs = 1;
322+
} else {
323+
gotArgs++;
324+
}
325+
emitAsmRegref(f, addr);
326+
addr++; regNum++;
327+
}
328+
needcomma = true;
329+
break;
330+
default:
331+
ERROR(arg, "Unknown address kind returned by back end");
332+
break;
333+
}
334+
if (gotArgs == expectedArgs) {
335+
// consumed them all
336+
gotArgs = 0;
337+
needcomma = true;
338+
opcode &= ~DBC_FLAG_NOCOMMA;
316339
}
317-
needcomma = true;
318-
break;
319-
default:
320-
ERROR(arg, "Unknown address kind returned by back end");
321-
break;
322340
}
323-
if (gotArgs == expectedArgs) {
324-
// consumed them all
325-
gotArgs = 0;
326-
needcomma = true;
327-
opcode &= ~DBC_FLAG_NOCOMMA;
341+
if (gotArgs) {
342+
ERROR(item,"%s expects %d args, got %d",name,expectedArgs,gotArgs);
328343
}
329344
}
330-
if (gotArgs) {
331-
ERROR(item,"%s expects %d args, got %d",name,expectedArgs,gotArgs);
332-
}
333345
needcomma = true;
334346
} break;
335347
case AST_IDENTIFIER:

frontends/spin/spin.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,8 @@ debug_expritem:
805805
asmdebug_func:
806806
identifier '(' operandlist ')'
807807
{ $$ = MakeFunccall($1,$3,NULL);}
808+
| identifier '(' ')'
809+
{ $$ = MakeFunccall($1,NULL,NULL);}
808810
| SP_IF '(' operandlist ')'
809811
{ $$ = MakeFunccall(AstIdentifier("if"),$3,NULL);}
810812
| SP_IFNOT '(' operandlist ')'

sys/p2_brkdebug.spin

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
'**************************************
2-
'* Spin2/PASM Debugger - 2022.11.19 *
3-
'**************************************
1+
'********************************************
2+
'* Spin2/PASM Debugger - v49 - 2025.02.02 *
3+
'********************************************
44
'
55
' Sets up debugger and then launches appended applicaion
66
'
@@ -576,6 +576,8 @@ debug_byte callpa #z,#getdeb 'get DEBUG bytecode
576576
byte .dly '7 = DLY(ms)
577577
byte .pc '8 = PC_KEY(ptr)
578578
byte .pc '9 = PC_MOUSE(ptr)
579+
byte .c_z_pre 'A = C_Z_pre
580+
byte .c_z 'B = C_Z
579581

580582
.asm ijnz asm,#debug_byte 'set asm mode
581583

@@ -624,6 +626,14 @@ debug_byte callpa #z,#getdeb 'get DEBUG bytecode
624626
if_z add ptrb,#1
625627
if_z jmp #rwreg 'z=1 for write
626628
_ret_ wrlong y,ptrb++ 'write to hub
629+
630+
.c_z_pre callpb #_com,#rstrout 'output ", "
631+
.c_z testb iret,#31 wc 'set C value
632+
bitc _c_z+0,#16
633+
testb iret,#30 wc 'set Z value
634+
bitc _c_z+1,#16
635+
callpb #_c_z,#rstrout 'output "C=? Z=?"
636+
jmp #debug_byte
627637
'
628638
'
629639
' Output "CogN " with possible timestamp
@@ -669,22 +679,34 @@ arg_cmd testb z,#0 wz 'if %x0, output ", "
669679
call #getval 'get ptr/val argument
670680
mov ptrb,x
671681

672-
testb z,#4 wz 'get len argument?
673-
if_z call #getval
674-
if_z mov y,x
682+
testb z,#4 wc 'get dual-argument flag in c
683+
684+
if_c call #getval 'get len argument?
685+
if_c mov y,x
675686

676-
mov pa,z 'ZSTR/LSTR command?
677-
and pa,#$EC
678-
cmp pa,#$24 wz
679-
testb z,#4 wc 'value or array command?
680-
if_nz_and_nc jmp #value_cmd
687+
mov pa,z 'branch to handler
688+
and pa,#$FC
689+
cmp pa,#$24 wz 'ZSTR/LSTR command?
690+
if_nz cmp pa,#$34 wz
691+
if_z jmp #str_cmd
692+
cmp pa,#$20 wz 'BOOL command?
693+
if_nz_and_nc jmp #value_cmd 'value or array command?
681694
if_nz_and_c jmp #array_cmd
682695
'
683696
'
697+
' BOOL(val)
698+
'
699+
bool_cmd cmp x,#0 wz 'output "TRUE" or "FALSE"
700+
if_ne callpb #_tru,#rstrout
701+
if_e callpb #_fal,#rstrout
702+
703+
jmp #debug_byte
704+
'
705+
'
684706
' ZSTR(ptr)
685707
' LSTR(ptr,len)
686708
'
687-
testb z,#1 wc 'if %0x, output quote
709+
str_cmd testb z,#1 wc 'if %0x, output quote
688710
if_nc callpa #$22,#txbyte
689711

690712
testb z,#4 wc 'c=0 if ZSTR, c=1 if LSTR
@@ -700,7 +722,7 @@ arg_cmd testb z,#0 wz 'if %x0, output ", "
700722
jmp #debug_byte
701723
'
702724
'
703-
' Value command
725+
' Value command (val)
704726
'
705727
value_cmd testb z,#3 wc 'determine msb
706728
testb z,#2 wz
@@ -730,7 +752,7 @@ value_cmd testb z,#3 wc 'determine msb
730752
if_nz jmp #debug_byte '(followed by array_loop)
731753
'
732754
'
733-
' Array command
755+
' Array command (ptr, len)
734756
'
735757
array_loop djz y,#debug_byte 'done?
736758

@@ -786,7 +808,7 @@ getasm rdword x,ptr 'get initial word
786808
if_c sub ptr,#1
787809
if_c rdlong x,ptr
788810
if_c add ptr,#4
789-
ret wcz
811+
ret wcz 'restore flags
790812
'
791813
'
792814
' Debug string output
@@ -966,11 +988,14 @@ _lod byte " load",13,10,0
966988
_jmp byte " jump",13,10,0
967989
_com byte ", ",0,0
968990
_equ byte " = ",0
991+
_tru byte "TRUE",0,0,0,0
992+
_fal byte "FALSE",0,0,0
969993
_nil byte "nil",0
970994
_nan byte "NaN",0
971995
_key byte "PC_KEY",13,10,0,0,0,0
972-
_mou byte "PC_MOUSE"
996+
_mou byte "PC_MOUSE" '(must be followed by _lin)
973997
_lin byte 13,10,0,0
998+
_c_z byte "C=0 Z=0",0
974999

9751000
fit overlay_end+1
9761001
'
@@ -1164,20 +1189,22 @@ debugger_end
11641189
' 00000111 DLY(ms) delay for ms
11651190
' 00001000 PC_KEY(ptr) get PC keyboard
11661191
' 00001001 PC_MOUSE(ptr) get PC mouse
1192+
' 00001010 C_Z_pre ouput ", C=? Z=?"
1193+
' 00001011 C_Z ouput "C=? Z=?"
11671194
'
1168-
' ______00 ', ' + zstr + ' = ' + data specifiers for ZSTR..SBIN_LONG_ARRAY
1195+
' ______00 ', ' + zstr + ' = ' + data specifiers for BOOL..SBIN_LONG_ARRAY
11691196
' ______01 zstr + ' = ' + data
11701197
' ______10 ', ' + data
11711198
' ______11 data
11721199
'
1173-
' 001000__ <empty>
1200+
' 001000__ BOOL(val) boolean
11741201
' 001001__ ZSTR(ptr) z-string
11751202
' 001010__ <empty>
1176-
' 001011__ FDEC(val) floating point
1177-
' 001100__ FDEC_REG_ARRAY(ptr,len) floating point
1203+
' 001011__ FDEC(val) floating-point
1204+
' 001100__ FDEC_REG_ARRAY(ptr,len) floating-point
11781205
' 001101__ LSTR(ptr,len) length-string
11791206
' 001110__ <empty>
1180-
' 001111__ FDEC_ARRAY(ptr,len) floating point
1207+
' 001111__ FDEC_ARRAY(ptr,len) floating-point
11811208
'
11821209
' 010000__ UDEC(val) unsigned decimal
11831210
' 010001__ UDEC_BYTE(val)
@@ -1234,4 +1261,4 @@ debugger_end
12341261
' 111111__ SBIN_LONG_ARRAY(ptr,len)
12351262
'
12361263
'
1237-
' For PASM mode, each argument can be register or #immediate
1264+
' For PASM mode, each argument can be register or #immediate

0 commit comments

Comments
 (0)