mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
Separate debug console code from normal console code, see details:
- consoleDebugInit now lives in a separate source code file - The devoptab for debugDevice_CONSOLE is now loaded weakly, so that normal console code isn't linked in by explicit means - consoleInit no longer sets up stderr. If stderr to console is desired, explicitly use consoleDebugInit(debugDevice_CONSOLE) - This change makes it possible to use debugDevice_SVC without linking in the entire console runtime, which in turn also enabled default native window handling (and this can be undesirable)
This commit is contained in:
parent
763b1694ec
commit
4c9b2ac048
@ -2,7 +2,6 @@
|
||||
#include <string.h>
|
||||
#include <sys/iosupport.h>
|
||||
#include "runtime/devices/console.h"
|
||||
#include "kernel/svc.h"
|
||||
|
||||
#include "default_font_bin.h"
|
||||
|
||||
@ -450,62 +449,26 @@ static ssize_t con_write(struct _reent *r,void *fd,const char *ptr, size_t len)
|
||||
}
|
||||
|
||||
static const devoptab_t dotab_stdout = {
|
||||
"con",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
con_write,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
.name = "con",
|
||||
.write_r = con_write,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static ssize_t debug_write(struct _reent *r, void *fd, const char *ptr, size_t len) {
|
||||
//---------------------------------------------------------------------------------
|
||||
svcOutputDebugString(ptr,len);
|
||||
return len;
|
||||
const devoptab_t* __nx_get_console_dotab(void) {
|
||||
return &dotab_stdout;
|
||||
}
|
||||
|
||||
static const devoptab_t dotab_svc = {
|
||||
"svc",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
debug_write,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static const devoptab_t dotab_null = {
|
||||
"null",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
ConsoleRenderer* getDefaultConsoleRenderer(void);
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
PrintConsole* consoleInit(PrintConsole* console) {
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
static bool firstConsoleInit = true;
|
||||
static bool didFirstConsoleInit = false;
|
||||
|
||||
if(firstConsoleInit) {
|
||||
if(!didFirstConsoleInit) {
|
||||
devoptab_list[STD_OUT] = &dotab_stdout;
|
||||
devoptab_list[STD_ERR] = &dotab_stdout;
|
||||
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
setvbuf(stderr, NULL , _IONBF, 0);
|
||||
|
||||
firstConsoleInit = false;
|
||||
didFirstConsoleInit = true;
|
||||
}
|
||||
|
||||
if(console) {
|
||||
@ -551,29 +514,6 @@ void consoleUpdate(PrintConsole* console) {
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void consoleDebugInit(debugDevice device) {
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
int buffertype = _IONBF;
|
||||
|
||||
switch(device) {
|
||||
|
||||
case debugDevice_SVC:
|
||||
devoptab_list[STD_ERR] = &dotab_svc;
|
||||
buffertype = _IOLBF;
|
||||
break;
|
||||
case debugDevice_CONSOLE:
|
||||
devoptab_list[STD_ERR] = &dotab_stdout;
|
||||
break;
|
||||
case debugDevice_NULL:
|
||||
devoptab_list[STD_ERR] = &dotab_null;
|
||||
break;
|
||||
}
|
||||
setvbuf(stderr, NULL , buffertype, 0);
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
PrintConsole *consoleSelect(PrintConsole* console) {
|
||||
//---------------------------------------------------------------------------------
|
||||
|
48
nx/source/runtime/devices/console_debug.c
Normal file
48
nx/source/runtime/devices/console_debug.c
Normal file
@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/iosupport.h>
|
||||
#include "runtime/devices/console.h"
|
||||
#include "kernel/svc.h"
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
static ssize_t debug_write(struct _reent *r, void *fd, const char *ptr, size_t len) {
|
||||
//---------------------------------------------------------------------------------
|
||||
svcOutputDebugString(ptr,len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static const devoptab_t dotab_svc = {
|
||||
.name = "svc",
|
||||
.write_r = debug_write,
|
||||
};
|
||||
|
||||
static const devoptab_t dotab_null = {
|
||||
.name = "null",
|
||||
};
|
||||
|
||||
__attribute__((weak)) const devoptab_t* __nx_get_console_dotab(void) {
|
||||
return &dotab_null;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
void consoleDebugInit(debugDevice device) {
|
||||
//---------------------------------------------------------------------------------
|
||||
|
||||
int buffertype = _IONBF;
|
||||
|
||||
switch(device) {
|
||||
|
||||
case debugDevice_SVC:
|
||||
devoptab_list[STD_ERR] = &dotab_svc;
|
||||
buffertype = _IOLBF;
|
||||
break;
|
||||
case debugDevice_CONSOLE:
|
||||
devoptab_list[STD_ERR] = __nx_get_console_dotab();
|
||||
break;
|
||||
case debugDevice_NULL:
|
||||
devoptab_list[STD_ERR] = &dotab_null;
|
||||
break;
|
||||
}
|
||||
setvbuf(stderr, NULL, buffertype, 0);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user