Closed antoinealb closed 10 years ago
The problem with printf this is, that panic now needs a working newlib context which might not be trivial in an interrupt. Also printf uses malloc to print float values. I suggest that we implement a simple printf variant that works from any context but only knows how to print integers (floats&pointers could be printed as hex) without any format options. I wanted to do this anyway to debug in interrupts.
For now PANIC
uses vsprintf
, but we can use our own function instead. You are probably right, it would be better.
I wonder if we should create a centralized "logging" module which would also provide function to log non critical informations (debug, warning levels). What do you think ?
I think a centralized logging would be useful. I suggest we redirect the stdout of each task by default to this logging service.
I don't really know how you would redirect stdout per task ? fdevopen
would be application-wide.
When you port newlib you have to provide system calls read, write, open and close. Those functions have the filedescriptor as an arugment and stdin, stdout & stderr are preset to 0, 1 & 2. So you just map the filedescriptor 1 to the log of the current task for write system calls.
I think it would be better to use a centralized but explicit logging service, providing macros such as INFO
, WARNING
and ERROR
, each taking a printf style string and additional arguments. Patching system calls feels a bit weird to me. Abstraction rulez :D
OK explicit logging has it's advantage too. For the system calls it's not really patching since we have to write them ourselves anyway.
I think we can merge this and change the printf later.
Ok, perfect. Should the logging go in it's own module ?
I would say yes, it's quite independent.
Okay, I started writing an implementation tonight at the club. Will push it once the API is a bit frozen.
Now PANIC can be used with printf-like variable arguments, which is useful to provide more detailed informations about a crash.
Sorry, this is a big commit, but it was hard splitting it into smaller meaningful patches.