Remove serial0-output-line, fix stack overflow in serial debug output (fix #741)

This commit is contained in:
Fabian 2022-10-14 19:57:26 -05:00
parent f13c238109
commit 0c17fea221
2 changed files with 20 additions and 21 deletions

View file

@ -26,9 +26,11 @@ window.onload = function()
}, },
autostart: true, autostart: true,
disable_keyboard: true, disable_keyboard: true,
disable_mouse: true,
}); });
var data = ""; var data = "";
var do_output = false;
emulator.add_listener("serial0-output-char", function(char) emulator.add_listener("serial0-output-char", function(char)
{ {
@ -37,24 +39,17 @@ window.onload = function()
data += char; data += char;
} }
if(do_output)
{
document.getElementById("result").textContent += char;
}
if(data.endsWith("~% ")) if(data.endsWith("~% "))
{ {
console.log("Now ready"); console.log("Now ready");
document.getElementById("status").textContent = "Ready.\n"; document.getElementById("status").textContent = "Ready.\n";
document.getElementById("run").disabled = false; document.getElementById("run").disabled = false;
} do_output = false;
});
emulator.add_listener("serial0-output-line", function(line)
{
// filter noise
if(!line.startsWith("/root% lua -e") &&
!line.startsWith("> ") &&
line.indexOf("Welcome to Buildroot") === -1 &&
line.indexOf("login:") === -1 &&
line.trim() !== "")
{
document.getElementById("result").textContent += line;
} }
}); });
@ -75,6 +70,8 @@ window.onload = function()
document.getElementById("result").textContent = ""; document.getElementById("result").textContent = "";
document.getElementById("status").textContent = "Running ...\n"; document.getElementById("status").textContent = "Running ...\n";
this.disabled = true; this.disabled = true;
do_output = true;
}; };
}; };

View file

@ -67,7 +67,7 @@ function UART(cpu, port, bus)
this.input = new ByteQueue(4096); this.input = new ByteQueue(4096);
this.current_line = []; this.current_line = "";
switch(port) switch(port)
{ {
@ -350,13 +350,15 @@ UART.prototype.write_data = function(out_byte)
this.bus.send("serial" + this.com + "-output-char", char); this.bus.send("serial" + this.com + "-output-char", char);
this.current_line.push(out_byte); if(DEBUG)
if(char === "\n")
{ {
const line = String.fromCharCode.apply("", this.current_line).trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g, ""); this.current_line += char;
dbg_log("SERIAL: " + line);
this.bus.send("serial" + this.com + "-output-line", String.fromCharCode.apply("", this.current_line)); if(char === "\n")
this.current_line = []; {
const line = this.current_line.trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g, "");
dbg_log("SERIAL: " + line);
this.current_line = "";
}
} }
}; };