[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: debug prints
From: |
Hollis Blanchard |
Subject: |
Re: debug prints |
Date: |
Sun, 23 Jan 2005 13:29:18 -0600 |
On Jan 23, 2005, at 12:10 PM, Hollis Blanchard wrote:
Then grub_debug can be set at runtime to enable debugging messages,
which could be quite helpful. If we wanted to get fancy, we could turn
grub_debug into a set of flags (e.g. FILESYSTEM, PARTITION, DISK,
LINUX, MEMORY) to selectively debug specific systems.
Lots of good ideas. It sounds like the code should look like this:
enum grub_debug_area_t {
GRUB_DEBUG_FILESYSTEM = 0x1,
GRUB_DEBUG_PARTITION = 0x2,
GRUB_DEBUG_DISK = 0x4,
GRUB_DEBUG_LINUX = 0x8,
GRUB_DEBUG_MEMORY = 0x10,
...
};
#ifndef DEBUG
/* the compiler will optimize this function away */
grub_debug_printf (enum grub_debug_area_t area __unused__,
const char *location __unused__,
const char *fmt __unused__,
...)
{
}
#else
grub_debug_printf (enum grub_debug_area_t area, const char *location,
const char *fmt, ...)
{
char *envflags = grub_env_get("debug");
grub_uint32_t flags = strtoul(envflags);
va_list ap;
int ret;
if (! (flags & area))
return;
va_start (ap, fmt);
ret = grub_vprintf (fmt, ap);
va_end (ap);
return ret;
}
#endif
"area" it the bit specifying the type of debug message
"location" a string such as the module name (e.g. "ext2") or even file
name if desired
"fmt ..." the printf debug string
(To enable all debug messages, you can "set debug -1".)
-Hollis