log-server: validate operation with libstd

This makes minor changes to the panic behavior when operating with a
libstd client.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-05-17 16:00:43 +08:00
parent e0f4e0c47f
commit b13b458b11
3 changed files with 41 additions and 8 deletions

View file

@ -2,7 +2,7 @@
use std::env;
extern crate vergen;
use vergen::{ConstantsFlags, generate_cargo_keys};
use vergen::{generate_cargo_keys, ConstantsFlags};
fn main() {
let target = env::var("TARGET").unwrap();
@ -16,7 +16,10 @@ fn main() {
println!("cargo:rustc-cfg=baremetal");
}
generate_cargo_keys(ConstantsFlags::SHA /*| ConstantsFlags::BUILD_TIMESTAMP*/).unwrap();
generate_cargo_keys(
ConstantsFlags::SHA, /*| ConstantsFlags::BUILD_TIMESTAMP*/
)
.unwrap();
// BUILD_TIMESTAMP doesn't work -- it doesn't update because of the below line
// removing the below line causes a lengthy full-rebuild just to capture a timestamp.
// so, we're removing the timestamp.

View file

@ -12,13 +12,13 @@ pub enum Opcode {
/// A `LogRecord` message, delivering structured log output
LogRecord = 0,
/// A `xous::String` destined for stdout
/// A `&[u8]` destined for stdout
StandardOutput = 1,
/// A `xous::String` destined for stderr
/// A `&[u8]` destined for stderr
StandardError = 2,
/// A `xous::String` containing this program's name
/// A `xous::StringBuffer` containing this program's name
ProgramName = 3,
/// A panic occurred, and a panic log is forthcoming

View file

@ -86,6 +86,20 @@ mod implementation {
pub fn putc(&self, c: u8) {
self.tx.send(ControlMessage::Byte(c)).unwrap();
}
/// Write a buffer to the output and return the number of
/// bytes written. This is mostly compatible with `std::io::Write`,
/// except it is infallible.
pub fn write(&mut self, buf: &[u8]) -> usize {
for c in buf {
self.putc(*c);
}
buf.len()
}
pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result<usize, ()> {
Ok(self.write(buf))
}
}
impl Write for OutputWriter {
@ -177,6 +191,20 @@ mod implementation {
uart_csr.wo(utra::uart::RXTX, c as u32);
}
}
/// Write a buffer to the output and return the number of
/// bytes written. This is mostly compatible with `std::io::Write`,
/// except it is infallible.
pub fn write(&mut self, buf: &[u8]) -> usize {
for c in buf {
self.putc(*c);
}
buf.len()
}
pub fn write_all(&mut self, buf: &[u8]) -> core::result::Result<usize, ()> {
Ok(self.write(buf))
}
}
impl Write for OutputWriter {
@ -199,7 +227,7 @@ fn handle_scalar(
sender_pid: xous::PID,
) {
match msg.id {
1000 => writeln!(output, "PANIC from PID {} | {}", sender_pid, sender).unwrap(),
1000 => writeln!(output, "PANIC in PID {}:", sender_pid).unwrap(),
1100 => (),
1101..=1132 => {
let mut output_bfr = [0u8; core::mem::size_of::<usize>() * 4];
@ -279,8 +307,10 @@ fn handle_opcode(
}
}
api::Opcode::StandardOutput | api::Opcode::StandardError => {
let string = unsafe { xous::stringbuffer::StringBuffer::from_memory_message(mem) };
write!(output, "{}", string).unwrap();
let buffer =
unsafe { core::slice::from_raw_parts(mem.buf.as_ptr(), mem.buf.len()) };
output.write_all(buffer).unwrap();
// TODO: If the buffer is mutable, set `length` to 0.
}
_ => {
writeln!(output, "Unhandled opcode").unwrap();