Kernel+LibC: Add a dbgputstr() syscall for sending strings to debug output.

This is very handy for the DebugLogStream implementation, among others. :^)
This commit is contained in:
Andreas Kling 2019-07-21 21:43:37 +02:00
parent 0ef13e60b0
commit af81645a2a
Notes: sideshowbarker 2024-07-19 13:05:46 +09:00
10 changed files with 33 additions and 4 deletions

View file

@ -79,8 +79,7 @@ public:
virtual void write(const char* characters, int length) const override virtual void write(const char* characters, int length) const override
{ {
for (int i = 0; i < length; ++i) dbgputstr(characters, length);
dbgprintf("%c", characters[i]);
} }
}; };

View file

@ -6,4 +6,5 @@
#include <stdio.h> #include <stdio.h>
#define kprintf printf #define kprintf printf
#define dbgprintf printf #define dbgprintf printf
#define dbgputstr(characters, length) fwrite(characters, 1, length, stdout)
#endif #endif

View file

@ -2722,3 +2722,12 @@ int Process::sys$dbgputch(u8 ch)
IO::out8(0xe9, ch); IO::out8(0xe9, ch);
return 0; return 0;
} }
int Process::sys$dbgputstr(const u8* characters, int length)
{
if (!validate_read(characters, length))
return -EFAULT;
for (int i = 0; i < length; ++i)
IO::out8(0xe9, characters[i]);
return 0;
}

View file

@ -105,6 +105,7 @@ public:
void finalize(); void finalize();
int sys$dbgputch(u8); int sys$dbgputch(u8);
int sys$dbgputstr(const u8*, int length);
int sys$dump_backtrace(); int sys$dump_backtrace();
int sys$gettid(); int sys$gettid();
int sys$donate(int tid); int sys$donate(int tid);

View file

@ -72,6 +72,8 @@ static u32 handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3
break; break;
case Syscall::SC_dbgputch: case Syscall::SC_dbgputch:
return current->process().sys$dbgputch((u8)arg1); return current->process().sys$dbgputch((u8)arg1);
case Syscall::SC_dbgputstr:
return current->process().sys$dbgputstr((const u8*)arg1, (int)arg2);
case Syscall::SC_sleep: case Syscall::SC_sleep:
return current->process().sys$sleep((unsigned)arg1); return current->process().sys$sleep((unsigned)arg1);
case Syscall::SC_usleep: case Syscall::SC_usleep:

View file

@ -117,7 +117,8 @@ struct timeval;
__ENUMERATE_SYSCALL(halt) \ __ENUMERATE_SYSCALL(halt) \
__ENUMERATE_SYSCALL(reboot) \ __ENUMERATE_SYSCALL(reboot) \
__ENUMERATE_SYSCALL(dump_backtrace) \ __ENUMERATE_SYSCALL(dump_backtrace) \
__ENUMERATE_SYSCALL(dbgputch) __ENUMERATE_SYSCALL(dbgputch) \
__ENUMERATE_SYSCALL(dbgputstr)
namespace Syscall { namespace Syscall {

View file

@ -57,12 +57,18 @@ int ksprintf(char* buffer, const char* fmt, ...)
return ret; return ret;
} }
extern "C" int dbgputstr(const char* characters, int length)
{
for (int i = 0; i < length; ++i)
IO::out8(0xe9, characters[i]);
return 0;
}
static void debugger_putch(char*&, char ch) static void debugger_putch(char*&, char ch)
{ {
IO::out8(0xe9, ch); IO::out8(0xe9, ch);
} }
extern "C" int dbgprintf(const char* fmt, ...) extern "C" int dbgprintf(const char* fmt, ...)
{ {
color_on(); color_on();

View file

@ -1,7 +1,10 @@
#pragma once #pragma once
#include <AK/Types.h>
extern "C" { extern "C" {
int dbgprintf(const char* fmt, ...); int dbgprintf(const char* fmt, ...);
int dbgputstr(const char*, int);
int kprintf(const char* fmt, ...); int kprintf(const char* fmt, ...);
int ksprintf(char* buf, const char* fmt, ...); int ksprintf(char* buf, const char* fmt, ...);
} }

View file

@ -488,6 +488,12 @@ void dbgputch(char ch)
syscall(SC_dbgputch, ch); syscall(SC_dbgputch, ch);
} }
int dbgputstr(const char* characters, int length)
{
int rc = syscall(SC_dbgputstr, characters, length);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
char* tmpnam(char*) char* tmpnam(char*)
{ {
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();

View file

@ -79,6 +79,7 @@ int fprintf(FILE*, const char* fmt, ...);
int printf(const char* fmt, ...); int printf(const char* fmt, ...);
int dbgprintf(const char* fmt, ...); int dbgprintf(const char* fmt, ...);
void dbgputch(char); void dbgputch(char);
int dbgputstr(const char*, ssize_t);
int sprintf(char* buffer, const char* fmt, ...); int sprintf(char* buffer, const char* fmt, ...);
int snprintf(char* buffer, size_t, const char* fmt, ...); int snprintf(char* buffer, size_t, const char* fmt, ...);
int putchar(int ch); int putchar(int ch);