Communication to the simulator is performed by the sendSim() and waitForSim() functions. waitForSim() waits for a specified timeout period then assumes that all data has been received from the simulator.
sendSim("command for simulator");
waitForSim(timeout, NULL);
This timeout period is too short on some systems with ucSim 0.6.x versions. These versions of uCsim are present in the versions of SDCC from 3.8.0 to 4.2.0.
In addition uCsim 0.6.x sends extra data to SDCDB at startup which makes the issue worse.
The affected system is Windows 10 Pro, Version 21H2, OS build 19044.2130 with SDCC 3.6.0, 3.8.0, 4.0.0 and 4.2.0 installed.
The attached patch doubles the timeout period for all waitForSim() calls and swallows the startup data sent from the simulator if it is sent.
The source used is shown below. It doesn't do anything useful and is just to illustrate the problem.
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
volatile char buff[20];
void load_function()
{
int x, y, z;
for(x = 0; x < 10; x++)
for(y = 0; y < 10; y++)
for(z = 0; z < 10; z++)
buff[x] = y * z;
}
void load_buff()
{
load_function();
}
int main(void)
{
int n;
for(n = 0; n < 10; n++)
load_buff();
return 0;
}
Log of SDCDB 3.6.0 running with -d=2 -v flags to show simulator IO.
simi: openSimulator
simi: openSimulator: arg0: s51 arg1: -P arg2: -r arg3: 9756 arg4: -t arg5: 8051 arg6: -b
simi: waitForSim start(200)
waitForSim(200) got[uCsim 0.5.4, Copyright (C) 1997 Daniel Drotos, Talker Bt.
uCsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
]
uCsim 0.5.4, Copyright (C) 1997 Daniel Drotos, Talker Bt.
uCsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
file "hello36.ihx"
simi: sendSim-->file "hello36.ihx"
simi: waitForSim start(1000)
waitForSim(1000) got[241 words read from hello36.ihx
]
simi: sendSim-->break 0x62
simi: waitForSim start(200)
waitForSim(200) got[Breakpoint 1 at 0x000062: MOV R6,#00
]
simi: sendSim-->break 0xcc
simi: waitForSim start(200)
waitForSim(200) got[Breakpoint 2 at 0x0000cc: RET
]
simi: sendSim-->break 0xcd
simi: waitForSim start(200)
waitForSim(200) got[Breakpoint 3 at 0x0000cd: LCALL 0062
]
simi: sendSim-->break 0xd0
simi: waitForSim start(200)
waitForSim(200) got[Breakpoint 4 at 0x0000d0: RET
]
simi: sendSim-->break 0xd1
simi: waitForSim start(200)
waitForSim(200) got[Breakpoint 5 at 0x0000d1: MOV R6,#0a
]
simi: sendSim-->break 0xec
simi: waitForSim start(200)
waitForSim(200) got[Breakpoint 6 at 0x0000ec: RET
]
+ s51 -P -r 9756 -t 8051 -b
SDCDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for SDCDB; type "show warranty" for details.
SDCDB 0.9. Copyright (C) 1999 Sandeep Dutta (sandeep.dutta@usa.net)
Type ? for help
WARNING: SDCDB is EXPERIMENTAL.
...
log of SDCDB 4.2.0 running with -d=2 -v flags to show simulator IO.
simi: openSimulator
simi: openSimulator: arg0: s51 arg1: -P arg2: -r arg3: 9756 arg4: -t arg5: 8051 arg6: -b
simi: waitForSim start(200)
waitForSim(200) got[????
]
????
file "hello36.ihx"
simi: sendSim-->file "hello36.ihx"
simi: waitForSim start(500)
waitForSim(500) got[uCsim 0.6.4, Copyright (C) 1997 Daniel Drotos.
uCsim comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
]
simi: sendSim-->break 0x62
simi: waitForSim start(100)
waitForSim(100) got[file "hello36.ihx"
break 0x62
]
simi: sendSim-->break 0xcc
simi: waitForSim start(100)
waitForSim(100) got[break 0xcc
Breakpoint 1 at 0x000062: 0x0062 F? 7e 00 MOV R6,#0x00 (cond="")
]
simi: sendSim-->break 0xcd
simi: waitForSim start(100)
waitForSim(100) got[Breakpoint 2 at 0x0000cc: 0x00cc F? 22 RET (cond="")
]
simi: sendSim-->break 0xd0
simi: waitForSim start(100)
waitForSim(100) got[break 0xcd
break 0xd0
Breakpoint 3 at 0x0000cd: 0x00cd F? 12 00 62 LCALL 0x0062 (cond="")
]
simi: sendSim-->break 0xd1
simi: waitForSim start(100)
waitForSim(100) got[Breakpoint 4 at 0x0000d0: 0x00d0 F? 22 RET (cond="")
]
simi: sendSim-->break 0xec
simi: waitForSim start(100)
waitForSim(100) got[break 0xd1
Breakpoint 5 at 0x0000d1: 0x00d1 F? 7e 0a MOV R6,#0x0a (cond="")
]
+ s51 -P -r 9756 -t 8051 -b
SDCDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for SDCDB; type "show warranty" for details.
SDCDB 0.9. Copyright (C) 1999 Sandeep Dutta (sandeep.dutta@usa.net)
Type ? for help
WARNING: SDCDB is EXPERIMENTAL.
...
A small clarification: the attached source was built with SDCC 3.6.0 so that all versions of SDCDB could debug it.
Superficially, this patch looks safe.
@drdani, do you think this also applies to SDCDB communication with more recent ucsim or does this patch solve a purely ucsim 0.6.x related problem?