Skip to content
Snippets Groups Projects
Commit 6ebb582e authored by Guy Zana's avatar Guy Zana
Browse files

debug: introduce debug_ll() and use it in abort()

the debug() console function is taking a lock before it access the console driver,
it does that by acquiring a mutex which may sleep.

since we want to be able to debug (and abort) in contexts where it's not possible sleep,
such as in page_fault, a lockless debug print method is introduced.

previousely to this patch, any abort on page_fault would cause an "endless" recursive
abort() loop which hanged the system in a peculiar state.
parent 9ef87755
No related branches found
No related tags found
No related merge requests found
......@@ -170,4 +170,10 @@ extern "C" {
console::write(msg, len, false);
}
// lockless version
void debug_ll(const char *msg)
{
console::write_ll(msg, strlen(msg));
}
}
......@@ -24,6 +24,11 @@ void write(const char *msg, size_t len, bool lf)
console.newline();
}
// lockless version
void write_ll(const char *msg, size_t len)
{
console.write_ll(msg, len);
}
mutex console_mutex;
// characters available to be returned on read() from the console
......
......@@ -15,6 +15,7 @@ public:
namespace console {
void write(const char *msg, size_t len, bool lf);
void write_ll(const char *msg, size_t len);
}
......
......@@ -10,6 +10,13 @@ void debug_console::write(const char* str, size_t len)
with_lock(_lock, [=] { if (_impl) { _impl->write(str, len); }});
}
void debug_console::write_ll(const char *str, size_t len)
{
if (_impl) {
_impl->write(str, len);
}
}
void debug_console::newline()
{
with_lock(_lock, [=] { if (_impl) { _impl->newline(); }});
......
......@@ -11,6 +11,8 @@ class debug_console : public Console {
public:
void set_impl(Console* impl);
virtual void write(const char *str, size_t len);
// write without taking any locks
void write_ll(const char *str, size_t len);
virtual void newline();
virtual bool input_ready() override;
virtual char readch();
......
......@@ -18,6 +18,10 @@ __BEGIN_DECLS
void debug(const char *msg);
void debug_write(const char *msg, size_t len);
/* a lockless version that doesn't take any locks before printing,
should be used only to debug faults */
void debug_ll(const char *msg);
int vkprintf(const char *__restrict fmt, va_list ap)
__attribute__((format(printf, 1, 0)));
int kprintf(const char *__restrict fmt, ...)
......
......@@ -86,7 +86,7 @@ void abort()
already_aborted = true;
// Since the debug() code is complex and might cause an additional
// abort, we need to prevent endless abort() nesting.
debug("Aborted\n");
debug_ll("Aborted\n");
}
osv::halt();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment