From ba694ad2f10d892a6faf03ba1b9d74e7d4e96987 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Wed, 12 Jun 2013 17:41:28 +0900 Subject: [PATCH] add 'dlog' option to xdbg Change-Id: I3cf5f6037a4714c71203a0307ca4075bfee00e1f --- lib/xdbg_log.c | 34 ++++++++++++++++++++++++++++++---- lib/xdbg_log.h | 7 +++++-- module/xdbg_module.h | 1 + module/xdbg_module_command.c | 24 ++++++++++++++++++++++++ module/xdbg_module_options.c | 7 +++++++ 5 files changed, 67 insertions(+), 6 deletions(-) diff --git a/lib/xdbg_log.c b/lib/xdbg_log.c index 0ae68af..355d7f3 100644 --- a/lib/xdbg_log.c +++ b/lib/xdbg_log.c @@ -59,6 +59,9 @@ typedef struct static ModuleInfo modules[MAX_MODULE_CNT]; static int module_cnt = 0; +static int default_level = XLOG_LEVEL_DEFAULT; + +static Bool dlog_enable; extern void dLogWrapper (int loglevel, int is_module, const char * file, int line, const char * f, va_list args); extern void kLogWrapper (int loglevel, int is_module, const char * file, int line, const char * f, va_list args); @@ -98,7 +101,6 @@ _LogModule (void * handle, int logoption, const char * file, int line, const cha kLogWrapper (loglevel, logoption, file, line, tmpBuf, args); } - /* write to file */ if (loglevel >= XLOG_LEVEL_INFO) { @@ -107,10 +109,16 @@ _LogModule (void * handle, int logoption, const char * file, int line, const cha else snprintf(tmpBuf, BUF_LEN, "(%s) [%s]%s", ostr[loglevel], (name)?name:"", f); - if (logoption & XLOG_OPTION_XORG) + if (!dlog_enable) LogVWrite (1, tmpBuf, args); + else + { + dLogWrapper (loglevel, logoption, file, line, tmpBuf, args); - dLogWrapper (loglevel, logoption, file, line, tmpBuf, args); + /* write to Xorg.0.log too */ + if (logoption & XLOG_OPTION_XORG) + LogVWrite (1, tmpBuf, args); + } } /* write to terminal */ @@ -139,6 +147,15 @@ xDbgLogSetLevel (unsigned int module, int level) if (level < XLOG_LEVEL_0 || level > XLOG_LEVEL_4) return FALSE; + if (module == XDBG_ALL_MODULE) + { + default_level = level; + for (i = 0; i < module_cnt; i++) + modules[i].loglevel = level; + + return TRUE; + } + for (i = 0; i < module_cnt; i++) { if (module == modules[i].module) @@ -155,6 +172,12 @@ xDbgLogSetLevel (unsigned int module, int level) return TRUE; } +API void +xDbgLogEnableDlog (Bool enable) +{ + dlog_enable = (enable > 0) ? TRUE:FALSE; +} + API void* xDbgLog (unsigned int module, int logoption, const char * file, int line, const char * f, ...) { @@ -176,7 +199,7 @@ xDbgLog (unsigned int module, int logoption, const char * file, int line, const goto check_level; } - h= (ModuleInfo *)_LogInitModule (module, XLOG_LEVEL_DEFAULT); + h= (ModuleInfo *)_LogInitModule (module, default_level); if(h == NULL) return NULL; @@ -268,6 +291,9 @@ xDbgLogGetModule (char *name) if (!name) return 0; + if (!strcasecmp (name, "all")) + return XDBG_ALL_MODULE; + len = strlen (name); for (i = 0; i < len; i++) { diff --git a/lib/xdbg_log.h b/lib/xdbg_log.h index 25ec4ec..869ba7a 100644 --- a/lib/xdbg_log.h +++ b/lib/xdbg_log.h @@ -63,9 +63,11 @@ enum XLOG_LEVEL_3, XLOG_LEVEL_4, XLOG_LEVEL_MAX, - XLOG_LEVEL_DEFAULT = XLOG_LEVEL_3 + XLOG_LEVEL_DEFAULT = XLOG_LEVEL_MAX }; +#define XDBG_ALL_MODULE 0xFFFFFFFF + #define XLOG_LEVEL_DEBUG XLOG_LEVEL_0 #define XLOG_LEVEL_TRACE XLOG_LEVEL_1 #define XLOG_LEVEL_INFO XLOG_LEVEL_2 @@ -86,6 +88,7 @@ typedef enum int xDbgLogEnumModules (LOG_ENUM_MODE mode, char *buf, int *remain); int xDbgLogSetLevel (unsigned int module, int level); +void xDbgLogEnableDlog (Bool enable); void* xDbgLog (unsigned int module, int logoption, const char *file, int line, const char *f, ...); // defines @@ -122,7 +125,7 @@ void* xDbgLog (unsigned int module, int logoption, const char *file, #define XDBG_RETURN_IF_FAIL(cond) {if (!(cond)) { XDBG_ERROR (MXDBG, "'%s' failed.\n", #cond); return; }} #define XDBG_RETURN_VAL_IF_FAIL(cond, val) {if (!(cond)) { XDBG_ERROR (MXDBG, "'%s' failed.\n", #cond); return val; }} #define XDBG_RETURN_VAL_IF_ERRNO(cond, val, errno) {if (!(cond)) { XDBG_ERRNO (MXDBG, "'%s' failed.\n", #cond); return val; }} -#define XDBG_GOTO_IF_FAIL(cond, dst) {if (!(cond)) { XDBG_ERROR ("'%s' failed.\n", #cond); goto dst; }} +#define XDBG_GOTO_IF_FAIL(cond, dst) {if (!(cond)) { XDBG_ERROR (MXDBG, "'%s' failed.\n", #cond); goto dst; }} #define XDBG_GOTO_IF_ERRNO(cond, dst, errno) {if (!(cond)) { XDBG_ERRNO (MXDBG, "'%s' failed.\n", #cond); goto dst; }} #define XDBG_REPLY(fmt, ARG...) \ diff --git a/module/xdbg_module.h b/module/xdbg_module.h index baf528d..e960cdd 100644 --- a/module/xdbg_module.h +++ b/module/xdbg_module.h @@ -48,6 +48,7 @@ typedef struct _ModuleClientInfo typedef struct _XDbgModule { + Bool dlog; char *log_path; char *real_log_path; char *evlog_path; diff --git a/module/xdbg_module_command.c b/module/xdbg_module_command.c index 7126d80..c915b36 100644 --- a/module/xdbg_module_command.c +++ b/module/xdbg_module_command.c @@ -52,6 +52,24 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "xdbg_module_fpsdebug.h" #include "xdbg_module_command.h" +static void +_CommandDLog (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod) +{ + int on; + + if (argc != 3) + { + XDBG_REPLY ("Error : too few arguments\n"); + return; + } + + on = atoi (argv[2]); + + xDbgLogEnableDlog (on); + + XDBG_REPLY ("Success\n"); +} + static Bool _CommandSetLogFile (int pid, char *path, char *reply, int *len, XDbgModule *pMod) { @@ -284,6 +302,12 @@ static struct } command_proc[] = { { + "dlog", "to enable dlog", "[0-1]", + NULL, "[OFF:0/ON:1]", + _CommandDLog + }, + + { "log_path", "to set log path", "[console/filepath]", NULL, "[console/filepath]", _CommandLogPath diff --git a/module/xdbg_module_options.c b/module/xdbg_module_options.c index ce7e172..8295f12 100644 --- a/module/xdbg_module_options.c +++ b/module/xdbg_module_options.c @@ -40,12 +40,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /* Supported options */ typedef enum { + OPTION_DLOG, OPTION_LOG_PATH, OPTION_EVLOG_PATH, } ModuleOption; static const OptionInfoRec module_options[] = { + { OPTION_DLOG, "dlog", OPTV_BOOLEAN, {0}, FALSE }, { OPTION_LOG_PATH, "log_path", OPTV_STRING, {0}, FALSE }, { OPTION_EVLOG_PATH, "evlog_path", OPTV_STRING, {0}, FALSE }, { -1, NULL, OPTV_NONE, {0}, FALSE } @@ -61,6 +63,11 @@ xDbgModuleParseOptions (XDbgModule *pMod, XF86OptionPtr pOpt) xf86ProcessOptions (-1, pOpt, options); + /* dlog */ + xf86GetOptValBool (options, OPTION_DLOG, &pMod->dlog); + XDBG_SLOG (MXDBG, "dlog: \"%s\"\n", (pMod->dlog)?"on":"off"); + xDbgLogEnableDlog (pMod->dlog); + /* log_path */ log_path = xf86GetOptValString (options, OPTION_LOG_PATH); if (log_path) -- 2.7.4