|
From: kosmirror <kos...@us...> - 2025-08-04 19:31:14
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "A pseudo Operating System for the Dreamcast.".
The branch, master has been updated
via 1126528da063d0b81254d9a71f9fda683c1815b4 (commit)
via b049605c316ce5cd7fe8c2c7ad7d3b5cb6dafda0 (commit)
via d8022a6cef850f16e43d4734f1fa7cd4b889b99d (commit)
via 45ea2ae4d55a8e000f868b8519a3f9ad81717920 (commit)
from 6d7a039b48130587c9063defc9454cc2b0946e51 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1126528da063d0b81254d9a71f9fda683c1815b4
Author: QuzarDC <qu...@co...>
Date: Fri Aug 1 15:24:11 2025 -0400
fs_vmu: Use new dbglog source functionality for verbose debug.
Additionally add the include for <kos/opts.h> which was missing.
This was getting chained in pretty much accidentally from kos/fs.h.
commit b049605c316ce5cd7fe8c2c7ad7d3b5cb6dafda0
Author: QuzarDC <qu...@co...>
Date: Fri Aug 1 15:08:09 2025 -0400
dbglog: Provide functionality for source-specific verbose debugging.
We provide many of these throughout the codebase where a single
driver, subsystem, or file will have its own define to set if
extra verbose or detailed debug info is outputted for it. These
have been cumbersome to use as they rarely had a unified style
or mechanisms, and presumed the defined would be set in the
individual source file.
Even once these options were made available in opts.h, it was
quite inconsistent as each implementation might use different
mechanisms (printf vs dbglog, for instance).
Now, instead, dbglog allows a 'level' to be passed which takes
a define that if defined means output regardless of the set level,
and if not defined will only output in the new 'DBG_MAX' setting
which explicitly has all dbglogs output.
commit d8022a6cef850f16e43d4734f1fa7cd4b889b99d
Author: QuzarDC <qu...@co...>
Date: Fri Aug 1 06:16:18 2025 -0400
dbglog: Add option to compile-time disable/limit debug logging.
This should help allow debug messages to be garbage collected,
and provide simpler steps for a release build when paired with
NDEBUG. `DBGLOG_LEVEL_SUPPORT` can be set to a dbglog level in
order to cap the level available at runtime to that amount.
`DBGLOG_DISABLED` overrides this down to disallow any output.
As the actual function backing `dbglog` is now named differently
this had to be updated in the exports. I've additionally moved it
out of the stdio section to reflect that it's kos-internal and
no longer is being shared with stdio after #1000 .
commit 45ea2ae4d55a8e000f868b8519a3f9ad81717920
Author: QuzarDC <qu...@co...>
Date: Fri Aug 1 05:30:10 2025 -0400
dbglog: Lower the default debug level.
`DBG_INFO` is noted as being a good level, so lets use that.
It never made much sense to have this default to the highest
setting, and it's a frequent user complaint.
-----------------------------------------------------------------------
Summary of changes:
doc/environ.sh.sample | 11 ++++++-----
include/kos/dbglog.h | 24 +++++++++++++++++++++---
include/kos/opts.h | 15 ++++++++++++++-
kernel/arch/dreamcast/fs/fs_vmu.c | 24 +++++++++---------------
kernel/exports.txt | 2 +-
kernel/libc/koslib/dbglog.c | 9 +++++----
6 files changed, 56 insertions(+), 29 deletions(-)
diff --git a/doc/environ.sh.sample b/doc/environ.sh.sample
index bdee2cb7..e23238c7 100644
--- a/doc/environ.sh.sample
+++ b/doc/environ.sh.sample
@@ -124,13 +124,14 @@ export KOS_LDFLAGS=""
export KOS_AFLAGS=""
export DC_ARM_LDFLAGS=""
-# Debug Builds
+# Debug Options
#
-# Controls whether to disable additional debugging checks and assertions,
-# such as for parameter validation or internal errors. Uncomment this if
-# you do not wish to compile with this additional logic enabled.
+# NDEBUG controls whether to disable `assert` per C standard, and
+# DBGLOG_DISABLED controls whether other debug output will be provided
+# (see ./kos/dbglog.h). Enable these if you want to remove assert checks
+# and disable logging output, as is desirable for release builds.
#
-#export KOS_CFLAGS="${KOS_CFLAGS} -DNDEBUG"
+#export KOS_CFLAGS="${KOS_CFLAGS} -DNDEBUG -DDBGLOG_DISABLED"
# Optimization Level
#
diff --git a/include/kos/dbglog.h b/include/kos/dbglog.h
index f9c87fc6..4b8bd1ca 100644
--- a/include/kos/dbglog.h
+++ b/include/kos/dbglog.h
@@ -22,13 +22,15 @@
#include <kos/cdefs.h>
__BEGIN_DECLS
+#include <kos/opts.h>
+
/** \defgroup logging Logging
\brief KOS's Logging API
\ingroup debugging
*/
/** \brief Kernel debugging printf.
- \ingroup logging
+ \ingroup logging
This function is similar to printf(), but filters its output through a log
level check before being printed. This way, you can set the level of debug
@@ -39,7 +41,14 @@ __BEGIN_DECLS
\param ... Format arguments
\see dbglog_levels
*/
-void dbglog(int level, const char *fmt, ...) __printflike(2, 3);
+void __real_dbglog(int level, const char *fmt, ...) __printflike(2, 3);
+
+/* This wrapper allows for the garbage collection of unneeded debug data */
+#define dbglog(lvl, ...) \
+do { \
+ if ((lvl) <= DBGLOG_LEVEL_SUPPORT) \
+ __real_dbglog(lvl, __VA_ARGS__); \
+} while(0)
/** \defgroup dbglog_levels Log Levels
\brief dbglog severity levels
@@ -48,8 +57,13 @@ void dbglog(int level, const char *fmt, ...) __printflike(2, 3);
This is the list of levels that are allowed to be passed into the dbglog()
function, representing different levels of importance.
+ For `DBG_SOURCE()` pass to it a define that controls specific debugging
+ and if the define is defined, the logging will be outputted. If not defined
+ the messages will only be outputted if the level is set to `DBG_MAX`.
+
@{
*/
+#define DBG_DISABLED -1 /**< \brief No output allowed */
#define DBG_DEAD 0 /**< \brief The system is dead */
#define DBG_CRITICAL 1 /**< \brief A critical error message */
#define DBG_ERROR 2 /**< \brief A normal error message */
@@ -58,13 +72,17 @@ void dbglog(int level, const char *fmt, ...) __printflike(2, 3);
#define DBG_INFO 5 /**< \brief Informational messages */
#define DBG_DEBUG 6 /**< \brief User debug messages */
#define DBG_KDEBUG 7 /**< \brief Kernel debug messages */
+#define DBG_MAX 8 /**< \brief All debug outputted */
+
+#define DBG_SOURCE(x) (__is_defined(x) ? DBG_DEAD : DBG_MAX) /**< \brief Verbose debugging of specific systems */
/** @} */
/** \brief Set the debugging log level.
\ingroup logging
This function sets the level for which dbglog() will ignore messages for if
- the message has a higher level.
+ the message has a higher level. This runtime setting does not override the
+ `DBGLOG_LEVEL_SUPPORT` define.
\param level The level to stop paying attention after.
\see dbglog_levels
diff --git a/include/kos/opts.h b/include/kos/opts.h
index 8000da10..069d9c65 100644
--- a/include/kos/opts.h
+++ b/include/kos/opts.h
@@ -42,10 +42,23 @@ __BEGIN_DECLS
@{
*/
+/* Completely disable debug logging at compile time if defined. */
+/* #define DBGLOG_DISABLED */
+
+/* Set the maximum allowed dbglog level. Normally the level is adjustable at
+ runtime, but that means keeping all debug information even in release builds. */
+#ifdef DBGLOG_DISABLED
+#define DBGLOG_LEVEL_SUPPORT -1
+#endif
+
+/* This retains the old behavior of all debugging being retained for runtime */
+#ifndef DBGLOG_LEVEL_SUPPORT
+#define DBGLOG_LEVEL_SUPPORT 127
+#endif
+
/* Enable debugging in fs_vmu. */
/* #define VMUFS_DEBUG 1 */
-
/* Enable to allow extra debugging checks in the malloc code itself. This
sometimes catches corrupted blocks. Recommended during debugging phases. */
/* #define MALLOC_DEBUG 1 */
diff --git a/kernel/arch/dreamcast/fs/fs_vmu.c b/kernel/arch/dreamcast/fs/fs_vmu.c
index 59ffc09c..54b97c1f 100644
--- a/kernel/arch/dreamcast/fs/fs_vmu.c
+++ b/kernel/arch/dreamcast/fs/fs_vmu.c
@@ -15,6 +15,7 @@
#include <arch/types.h>
#include <kos/mutex.h>
+#include <kos/opts.h>
#include <kos/dbglog.h>
#include <dc/fs_vmu.h>
#include <dc/vmufs.h>
@@ -42,11 +43,10 @@ Note: this new version now talks directly to the vmufs module and doesn't do
any block-level I/O anymore. This layer and that one are interchangeable
and may be used pretty much simultaneously in the same program.
+Define VMUFS_DEBUG in kos/opts.h, in your CFLAGS, or here if you want copious
+debug output.
*/
-/* Enable this if you want copious debug output */
-/* #define VMUFS_DEBUG */
-
#define VMU_DIR 0
#define VMU_FILE 1
#define VMU_ANY -1 /* Used for checking validity */
@@ -167,16 +167,13 @@ static vmu_fh_t *vmu_open_vmu_dir(void) {
names[num][1] = u + '0';
num++;
- if(__is_defined(VMUFS_DEBUG)) {
- dbglog(DBG_KDEBUG, "vmu_open_vmu_dir: found memcard (%c%d)\n",
- 'a' + p, u);
- }
+ dbglog(DBG_SOURCE(VMUFS_DEBUG), "vmu_open_vmu_dir: found memcard (%c%d)\n",
+ 'a' + p, u);
}
}
}
- if(__is_defined(VMUFS_DEBUG))
- dbglog(DBG_KDEBUG, "# of memcards found: %d\n", num);
+ dbglog(DBG_SOURCE(VMUFS_DEBUG), "# of memcards found: %d\n", num);
if(!(dh = malloc(sizeof(vmu_dh_t))))
return NULL;
@@ -501,8 +498,7 @@ static ssize_t vmu_write(void * hnd, const void *buffer, size_t cnt) {
n = n / 512;
- if(__is_defined(VMUFS_DEBUG))
- dbglog(DBG_KDEBUG, "VMUFS: extending file's filesize by %d\n", n);
+ dbglog(DBG_SOURCE(VMUFS_DEBUG), "VMUFS: extending file's filesize by %d\n", n);
/* We alloc another 512*n bytes for the file */
tmp = realloc(fh->data, (fh->filesize + n) * 512);
@@ -519,10 +515,8 @@ static ssize_t vmu_write(void * hnd, const void *buffer, size_t cnt) {
}
/* insert the data in buffer into fh->data at fh->loc */
- if(__is_defined(VMUFS_DEBUG)) {
- dbglog(DBG_KDEBUG, "VMUFS: adding %d bytes of data at loc %ld (%ld avail)\n",
- cnt, fh->loc, fh->filesize * 512);
- }
+ dbglog(DBG_SOURCE(VMUFS_DEBUG), "VMUFS: adding %d bytes of data at loc %ld (%ld avail)\n",
+ cnt, fh->loc, fh->filesize * 512);
memcpy(fh->data + fh->loc + fh->start, buffer, cnt);
fh->loc += cnt;
diff --git a/kernel/exports.txt b/kernel/exports.txt
index ef26e64e..676a5173 100644
--- a/kernel/exports.txt
+++ b/kernel/exports.txt
@@ -36,7 +36,6 @@ ftell
fflush
rewind
fputc
-dbglog
sprintf
vsprintf
@@ -188,6 +187,7 @@ dcache_purge_range
dcache_purge_all
# Low-level debug I/O
+__real_dbglog
dbgio_set_irq_usage
dbgio_enable
dbgio_disable
diff --git a/kernel/libc/koslib/dbglog.c b/kernel/libc/koslib/dbglog.c
index d37f529a..47a5b18e 100644
--- a/kernel/libc/koslib/dbglog.c
+++ b/kernel/libc/koslib/dbglog.c
@@ -13,6 +13,7 @@
#include <kos/thread.h>
#include <kos/dbgio.h>
#include <kos/fs.h>
+
#include <arch/spinlock.h>
/* Not re-entrant */
@@ -22,7 +23,7 @@ static spinlock_t mutex = SPINLOCK_INITIALIZER;
/* Default kernel debug log level: if a message has a level higher than this,
it won't be shown. Set to DBG_DEAD to see basically nothing, and set to
DBG_KDEBUG to see everything. DBG_INFO is generally a decent level. */
-int dbglog_level = DBG_KDEBUG;
+int dbglog_level = (DBGLOG_LEVEL_SUPPORT < DBG_INFO) ? DBGLOG_LEVEL_SUPPORT : DBG_INFO;
/* Set debug level */
void dbglog_set_level(int level) {
@@ -30,12 +31,12 @@ void dbglog_set_level(int level) {
}
/* Kernel debug logging facility */
-void dbglog(int level, const char *fmt, ...) {
+void __real_dbglog(int level, const char *fmt, ...) {
va_list args;
int i;
/* If this log level is blocked out, don't even bother */
- if(level > dbglog_level)
+ if((DBGLOG_LEVEL_SUPPORT < level) || (level > dbglog_level))
return;
/* We only try to lock if the message isn't urgent */
@@ -49,7 +50,7 @@ void dbglog(int level, const char *fmt, ...) {
if(i > 0) {
if(irq_inside_int() ||
(fs_write(STDOUT_FILENO, printf_buf, strlen(printf_buf)) < 0))
- dbgio_write_str(printf_buf);
+ dbgio_write_str(printf_buf);
}
if(level >= DBG_ERROR && !irq_inside_int())
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|