Added support for sending debugging output to a file.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4410 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2003-08-30 04:47:19 +00:00
parent 497bc759e4
commit 49cab54852
2 changed files with 87 additions and 4 deletions

View File

@ -272,6 +272,70 @@ get_tls_handle()
}
#endif
/*! \brief Helper class for initializing the debugging output
file.
Note that this hummer isn't threadsafe, but it doesn't really
matter for our concerns, since the worst it'll result in is
a dangling file descriptor, and that would be in the case of
two or more volumes being mounted almost simultaneously...
not too big of a worry.
*/
class DebugOutputFile {
public:
DebugOutputFile(const char *filename = NULL)
: fFile(-1)
{
Init(filename);
}
~DebugOutputFile() {
if (fFile >= 0)
close(fFile);
}
void Init(const char *filename) {
if (fFile < 0 && filename)
fFile = open(filename, O_RDWR | O_CREAT | O_TRUNC);
}
int File() const { return fFile; }
private:
int fFile;
};
DebugOutputFile out;
/*! \brief It doesn't appear that the constructor for the global
\c out variable is called when built as an R5 filesystem add-on,
so this function needs to be called in udf_mount to let the
magic happen.
*/
void initialize_debugger(const char *filename)
{
out.Init(filename);
}
// dbg_printf, stolen from Ingo's ReiserFS::Debug.cpp.
void
dbg_printf(const char *format,...)
{
#if DEBUG_TO_FILE
char buffer[1024];
va_list args;
va_start(args, format);
// no vsnprintf() on PPC and in kernel
#if defined(__INTEL__) && USER
vsnprintf(buffer, sizeof(buffer) - 1, format, args);
#else
vsprintf(buffer, format, args);
#endif
va_end(args);
buffer[sizeof(buffer) - 1] = '\0';
write(out.File(), buffer, strlen(buffer));
#endif
}
//----------------------------------------------------------------------
// DebugHelper
//----------------------------------------------------------------------

View File

@ -4,6 +4,7 @@
//
// UDF version copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
// Initial version copyright (c) 2002 Axel Dörfler, axeld@pinc-software.de
// dbg_printf() function copyright (c) 2003 Ingo Weinhold, bonefish@cs.tu-berlin.edu
//----------------------------------------------------------------------
#ifndef UDF_DEBUG_H
#define UDF_DEBUG_H
@ -19,13 +20,24 @@
#ifdef DEBUG
# include <string.h>
#endif
#include <unistd.h>
#ifdef USER
#define DEBUG_TO_FILE 0
#if DEBUG_TO_FILE
# include <stdio.h>
# define __out printf
# include <fcntl.h>
# define __out dbg_printf
void dbg_printf(const char *format,...);
void initialize_debugger(const char *filename);
#else
# include <null.h>
# define __out dprintf
# ifdef USER
# include <stdio.h>
# define __out printf
# else
# include <null.h>
# define __out dprintf
# endif
#endif
#include "cpp.h"
@ -119,6 +131,12 @@ private:
// DEBUG-dependent macros
//----------------------------------------------------------------------
#ifdef DEBUG
#if DEBUG_TO_FILE
#define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) initialize_debugger(filename);
#else
#define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) ;
#endif
#define DEBUG_INIT_SILENT(categoryFlags, className) \
DebugHelper _debugHelper((categoryFlags), className, 2);
@ -243,6 +261,7 @@ private:
#define DBG(x) x ;
#else // ifdef DEBUG
#define INITIALIZE_DEBUGGING_OUTPUT_FILE(filename) ;
#define DEBUG_INIT_SILENT(categoryFlags, className) ;
#define DEBUG_INIT(categoryFlags, className) ;
#define DEBUG_INIT_ETC(categoryFlags, className, arguments) ;