Move userspace to a templated StrFormat.
This commit is contained in:
parent
d9df1212b7
commit
26b61db021
25 changed files with 263 additions and 217 deletions
|
|
@ -1,9 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/string/str_format.h>
|
||||
#include <glacier/string/string_view.h>
|
||||
#include <stdint.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
void dbgln(const char* fmt, ...);
|
||||
// TODO: Take StringView here instead.
|
||||
void dbgln(const glcr::StringBuilder& builder);
|
||||
|
||||
template <typename... Args>
|
||||
void dbgln(const glcr::StringView& fmt, Args... args) {
|
||||
dbgln(StrFormat(fmt, args...));
|
||||
}
|
||||
|
||||
// Checks that the code is ok.
|
||||
// if not exits the process.
|
||||
|
|
|
|||
|
|
@ -1,27 +1,11 @@
|
|||
#include "include/mammoth/debug.h"
|
||||
|
||||
#include <glacier/status/error.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <zcall.h>
|
||||
|
||||
void dbgln_internal(const char* str) { // Safe to ignore the result since right
|
||||
// now this doesn't throw.
|
||||
uint64_t _ = ZDebug(str);
|
||||
}
|
||||
|
||||
void dbgln(const char* fmt, ...) {
|
||||
char str[1024];
|
||||
va_list arg;
|
||||
va_start(arg, fmt);
|
||||
int ret = vsprintf(str, fmt, arg);
|
||||
va_end(arg);
|
||||
|
||||
if (ret == -1 || ret > 1024) {
|
||||
crash("Bad vsprintf", 1);
|
||||
}
|
||||
|
||||
dbgln_internal(str);
|
||||
void dbgln(const glcr::StringBuilder& builder) {
|
||||
glcr::String str = builder.ToString();
|
||||
(void)ZDebug(str.cstr());
|
||||
}
|
||||
|
||||
void check(uint64_t code) {
|
||||
|
|
@ -44,10 +28,10 @@ void check(uint64_t code) {
|
|||
dbgln("Unhandled code");
|
||||
break;
|
||||
}
|
||||
ZProcessExit(code);
|
||||
(void)ZProcessExit(code);
|
||||
}
|
||||
|
||||
void crash(const char* str, uint64_t code) {
|
||||
dbgln(str);
|
||||
ZProcessExit(code);
|
||||
(void)ZProcessExit(code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ void EndpointServer::ServerThread() {
|
|||
ZEndpointRecv(endpoint_cap_, &message_size, recieve_buffer_, &num_caps,
|
||||
nullptr, &reply_port_cap));
|
||||
if (err != glcr::OK) {
|
||||
dbgln("Error in receive: %x", err);
|
||||
dbgln("Error in receive: {x}", err);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ void EndpointServer::ServerThread() {
|
|||
// FIXME: Consider pumping these errors into the response as well.
|
||||
check(HandleRequest(request, response));
|
||||
if (!response.HasWritten()) {
|
||||
dbgln("Returning without having written a response. Req type %x",
|
||||
dbgln("Returning without having written a response. Req type {x}",
|
||||
request.request_id());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,30 +23,25 @@ z_err_t ParseInitPort(uint64_t init_port_cap) {
|
|||
RET_ERR(ret);
|
||||
switch (init_sig) {
|
||||
case Z_INIT_SELF_PROC:
|
||||
dbgln("received proc");
|
||||
gSelfProcCap = init_cap;
|
||||
break;
|
||||
case Z_INIT_SELF_VMAS:
|
||||
dbgln("received vmas");
|
||||
gSelfVmasCap = init_cap;
|
||||
break;
|
||||
case Z_INIT_ENDPOINT:
|
||||
gInitEndpointCap = init_cap;
|
||||
break;
|
||||
case Z_BOOT_DENALI_VMMO:
|
||||
dbgln("received denali");
|
||||
gBootDenaliVmmoCap = init_cap;
|
||||
break;
|
||||
case Z_BOOT_VICTORIA_FALLS_VMMO:
|
||||
dbgln("received victoria falls");
|
||||
gBootVictoriaFallsVmmoCap = init_cap;
|
||||
break;
|
||||
case Z_BOOT_PCI_VMMO:
|
||||
dbgln("received pci");
|
||||
gBootPciVmmoCap = init_cap;
|
||||
break;
|
||||
default:
|
||||
dbgln("Unexpected init type %x, continuing.", init_sig);
|
||||
dbgln("Unexpected init type {}, continuing.", init_sig);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue