set_record.py: Fixed input stream for Windows, omit null characters in string receive

This commit fixes two bugs, the first when recording
on Windows where the user is unable to stop the capture cleanly
and one regarding the VCD output being malformed due to null characters in strings.

Reading from the stdin buffer is generally better behaved on both platforms,
while not as performant. The user can now cancel the capture by terminating the source
program or issuing a keyboard interrupt.

The issue with string capture having trailing null characters is fixed,
which in the best case confuses GTKwave, or in the worst case segfaults it.
This commit is contained in:
Dominic Höglinger 2025-05-14 20:36:49 +02:00
parent e40e97200d
commit 4bec2c3c42

View File

@ -261,7 +261,6 @@ class Filter:
if tagcode not in self.TAGCODE_LUT:
self.packets_dropped += 1
print("LUT ERR", tagcode)
return
tag = self.TAGCODE_LUT[tagcode]
@ -413,11 +412,13 @@ class VcdSink:
timestamp = self.timestamp
# unpack
for i in range(0,4):
char = chr(value >> (i*8) & 0xFF)
self.strings[tag][1] += char
char = value >> (i*8) & 0xFF
if char != 0:
self.strings[tag][1] += chr(char)
# sub of 1 indicates end of string
if sub == 1:
try:
string = self.strings[tag][1]
#print(f"### {timestamp:012X} : {self.varnames[tag]} <= \"{self.strings[tag][1]}\"", flush=True)
self.writer.change(self.strings[tag][0], timestamp, self.strings[tag][1])
except ValueError:
@ -515,9 +516,9 @@ def main():
print(" === BEGIN NOISE ===")
try:
while True:
for b in sys.stdin.buffer.read(1):
packet_filter.process(b)
for bstr in sys.stdin.buffer:
for b in bstr:
petf.process(b)
except KeyboardInterrupt:
pass