mirror of
https://github.com/SCST-project/scst.git
synced 2026-09-26 01:44:54 +00:00
- Module scst_user and user space utility to test it added
- Support for per-target default security groups added - FILEIO made multithreaded - BLOCKIO made async - Other improvements, fixes and cleanups git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@121 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* debug.c
|
||||
*
|
||||
* Copyright (C) 2004-2007 Vladislav Bolkhovitin <vst@vlnb.net>
|
||||
* and Leonid Stoljar
|
||||
*
|
||||
* Contains helper functions for execution tracing and error reporting.
|
||||
* Intended to be included in main .c file.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, version 2
|
||||
* of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
_syscall0(pid_t,gettid);
|
||||
|
||||
#if defined(DEBUG) || defined(TRACING)
|
||||
|
||||
#define TRACE_BUF_SIZE 512
|
||||
|
||||
static char trace_buf[TRACE_BUF_SIZE];
|
||||
//static spinlock_t trace_buf_lock = SPIN_LOCK_UNLOCKED;
|
||||
|
||||
int debug_print_prefix(unsigned long trace_flag, const char *func,
|
||||
int line)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
// spin_lock_irqsave(&trace_buf_lock, flags);
|
||||
|
||||
if (trace_flag & TRACE_TIME) {
|
||||
struct tm t;
|
||||
time_t tt;
|
||||
time(&tt);
|
||||
localtime_r(&tt, &t);
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE, "%d:%d:%d ",
|
||||
t.tm_hour, t.tm_min, t.tm_sec);
|
||||
}
|
||||
if (trace_flag & TRACE_PID)
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE, "[%d]: ",
|
||||
gettid());
|
||||
if (trace_flag & TRACE_FUNCTION)
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%s:", func);
|
||||
if (trace_flag & TRACE_LINE)
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%i:", line);
|
||||
|
||||
if (i > 0)
|
||||
PRINTN("%s", trace_buf);
|
||||
|
||||
// spin_unlock_irqrestore(&trace_buf_lock, flags);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void debug_print_buffer(const void *data, int len)
|
||||
{
|
||||
int z, z1, i;
|
||||
const unsigned char *buf = (const unsigned char *) data;
|
||||
int f = 0;
|
||||
|
||||
if (buf == NULL)
|
||||
return;
|
||||
|
||||
// spin_lock_irqsave(&trace_buf_lock, flags);
|
||||
|
||||
PRINT(" (h)___0__1__2__3__4__5__6__7__8__9__A__B__C__D__E__F");
|
||||
for (z = 0, z1 = 0, i = 0; z < len; z++) {
|
||||
if (z % 16 == 0) {
|
||||
if (z != 0) {
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i,
|
||||
" ");
|
||||
for (; (z1 < z) && (i < TRACE_BUF_SIZE - 1);
|
||||
z1++) {
|
||||
if ((buf[z1] >= 0x20) &&
|
||||
(buf[z1] < 0x80))
|
||||
trace_buf[i++] = buf[z1];
|
||||
else
|
||||
trace_buf[i++] = '.';
|
||||
}
|
||||
trace_buf[i] = '\0';
|
||||
PRINT("%s", trace_buf);
|
||||
i = 0;
|
||||
f = 1;
|
||||
}
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i,
|
||||
"%4x: ", z);
|
||||
}
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%02x ",
|
||||
buf[z]);
|
||||
}
|
||||
i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, " ");
|
||||
for (; (z1 < z) && (i < TRACE_BUF_SIZE - 1); z1++) {
|
||||
if ((buf[z1] > 0x20) && (buf[z1] < 0x80))
|
||||
trace_buf[i++] = buf[z1];
|
||||
else
|
||||
trace_buf[i++] = '.';
|
||||
}
|
||||
trace_buf[i] = '\0';
|
||||
if (f) {
|
||||
PRINT("%s", trace_buf)
|
||||
} else {
|
||||
PRINT("%s", trace_buf);
|
||||
}
|
||||
|
||||
// spin_unlock_irqrestore(&trace_buf_lock, flags);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* DEBUG || TRACING */
|
||||
Reference in New Issue
Block a user