add xevlog_analyze function
authorBoram Park <boram1288.park@samsung.com>
Mon, 8 Apr 2013 10:41:13 +0000 (19:41 +0900)
committerBoram Park <boram1288.park@samsung.com>
Mon, 17 Jun 2013 08:44:33 +0000 (17:44 +0900)
Change-Id: I2ed7fffd161ccb38b628b01bf2ee0d667b000cd7

57 files changed:
Makefile.am
bin/Makefile.am
bin/xdbg/Makefile.am
bin/xdbg/xdbg.c
bin/xevlog_analyze/Makefile.am [moved from dbus/Makefile.am with 80% similarity]
bin/xevlog_analyze/xevlog_analyze.c [new file with mode: 0644]
common/Makefile.am [new file with mode: 0644]
common/ds/bintree.c [moved from module/ds/bintree.c with 99% similarity]
common/ds/bintree.h [moved from module/ds/bintree.h with 99% similarity]
common/ds/bool_exp_parser.c [moved from module/ds/bool_exp_parser.c with 99% similarity]
common/ds/bool_exp_parser.h [moved from module/ds/bool_exp_parser.h with 99% similarity]
common/ds/bool_exp_rule_checker.c [moved from module/ds/bool_exp_rule_checker.c with 99% similarity]
common/ds/bool_exp_rule_checker.h [moved from module/ds/bool_exp_rule_checker.h with 99% similarity]
common/ds/bool_exp_token.h [moved from module/ds/bool_exp_token.h with 99% similarity]
common/ds/bool_exp_tokenizer.c [moved from module/ds/bool_exp_tokenizer.c with 100% similarity]
common/ds/bool_exp_tokenizer.h [moved from module/ds/bool_exp_tokenizer.h with 99% similarity]
common/xdbg_dbus.h [moved from dbus/xdbg_dbus.h with 100% similarity]
common/xdbg_dbus_client.c [moved from dbus/xdbg_dbus_client.c with 89% similarity]
common/xdbg_dbus_client.h [moved from dbus/xdbg_dbus_client.h with 100% similarity]
common/xdbg_dbus_server.c [moved from dbus/xdbg_dbus_server.c with 99% similarity, mode: 0644]
common/xdbg_dbus_server.h [moved from dbus/xdbg_dbus_server.h with 100% similarity]
common/xdbg_evlog.c [new file with mode: 0644]
common/xdbg_evlog.h [new file with mode: 0644]
common/xdbg_evlog_event.c [moved from module/xdbg_module_evlog_event.c with 62% similarity]
common/xdbg_evlog_event.h [moved from module/xdbg_module_evlog_event.h with 86% similarity]
common/xdbg_evlog_request.c [moved from module/xdbg_module_evlog_request.c with 60% similarity]
common/xdbg_evlog_request.h [moved from module/xdbg_module_evlog_request.h with 84% similarity]
common/xdbg_types.h [new file with mode: 0644]
configure.ac
lib/Makefile.am
lib/xdbg.h [changed mode: 0755->0644]
lib/xdbg_log.h [changed mode: 0755->0644]
lib/xdbg_log_drmevent.c [changed mode: 0755->0644]
lib/xdbg_log_drmevent.h [changed mode: 0755->0644]
lib/xdbg_log_fpsdebug.c [changed mode: 0755->0644]
lib/xdbg_log_fpsdebug.h [changed mode: 0755->0644]
lib/xdbg_log_plist.c [changed mode: 0755->0644]
lib/xdbg_log_plist.h [changed mode: 0755->0644]
module/Makefile.am
module/xdbg_module.h [moved from module/xdbg_module_types.h with 78% similarity]
module/xdbg_module_clist.c [changed mode: 0755->0644]
module/xdbg_module_clist.h [changed mode: 0755->0644]
module/xdbg_module_command.c [changed mode: 0755->0644]
module/xdbg_module_command.h
module/xdbg_module_drmevent.c [changed mode: 0755->0644]
module/xdbg_module_drmevent.h [changed mode: 0755->0644]
module/xdbg_module_evlog.c
module/xdbg_module_evlog.h
module/xdbg_module_fpsdebug.c [changed mode: 0755->0644]
module/xdbg_module_fpsdebug.h [changed mode: 0755->0644]
module/xdbg_module_main.c
module/xdbg_module_main.h
module/xdbg_module_options.c
module/xdbg_module_options.h
module/xdbg_module_plist.c [changed mode: 0755->0644]
module/xdbg_module_plist.h [changed mode: 0755->0644]
packaging/xorg-x11-module-xdbg.spec

index a88c0fa..13ed352 100644 (file)
@@ -22,4 +22,4 @@
 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-SUBDIRS = dbus lib module bin
+SUBDIRS = common lib module bin
index 016cafe..9a2b4bf 100644 (file)
@@ -22,4 +22,4 @@
 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-SUBDIRS = xdbg
+SUBDIRS = xdbg xevlog_analyze
index 32b2bb2..6271f85 100644 (file)
 
 bin_PROGRAMS = xdbg
 
-xdbg_LDADD = $(XDBG_LIBS) ../../dbus/libdbus.la ../../lib/libxdbg-log.la
+xdbg_LDADD = $(XDBG_CLIENT_LIBS) ../../common/libcommon-client.la
 xdbg_LDFLAGS = ${LDFLAGS}
 xdbg_CFLAGS = \
        ${CFLAGS} \
-       @XDBG_CFLAGS@ \
-       -I$(top_srcdir)/dbus \
-       -I$(top_srcdir)/lib
+       @XDBG_CLIENT_CFLAGS@ \
+       -I$(top_srcdir)/common
 
 xdbg_sc_SOURCES =      \
         xdbg.c
index 322f41b..0e371c2 100644 (file)
@@ -45,7 +45,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <sys/mman.h>
 
 #include <X11/Xlib.h>
-#include <xdbg.h>
 #include "xdbg_dbus_client.h"
 
 int main(int argc, char ** argv)
similarity index 80%
rename from dbus/Makefile.am
rename to bin/xevlog_analyze/Makefile.am
index bbe3b9f..37f7448 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
-# 
+#
 # Contact: Boram Park <boram1288.park@samsung.com>
-# 
+#
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the
 # "Software"), to deal in the Software without restriction, including
@@ -9,11 +9,11 @@
 # distribute, sub license, and/or sell copies of the Software, and to
 # permit persons to whom the Software is furnished to do so, subject to
 # the following conditions:
-# 
+#
 # The above copyright notice and this permission notice (including the
 # next paragraph) shall be included in all copies or substantial portions
 # of the Software.
-# 
+#
 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-noinst_LTLIBRARIES = libdbus.la
+bin_PROGRAMS = xevlog_analyze
 
-libdbus_la_LIBADD = @XDBG_LIBS@
-libdbus_la_LDFLAGS = ${LDFLAGS}
-libdbus_la_CFLAGS = \
-    ${CFLAGS} \
-    @XDBG_CFLAGS@ \
-    -I$(top_srcdir)/lib
+xevlog_analyze_LDADD = $(XDBG_CLIENT_LIBS) ../../common/libcommon-client.la
+xevlog_analyze_LDFLAGS = ${LDFLAGS}
+xevlog_analyze_CFLAGS = \
+       ${CFLAGS} \
+       @XDBG_CLIENT_CFLAGS@ \
+       -I$(top_srcdir)/common
 
-libdbus_la_SOURCES = \
-    xdbg_dbus_server.c \
-    xdbg_dbus_client.c
+xevlog_analyze_sc_SOURCES = \
+        xevlog_analyze.c
diff --git a/bin/xevlog_analyze/xevlog_analyze.c b/bin/xevlog_analyze/xevlog_analyze.c
new file mode 100644 (file)
index 0000000..3b70e92
--- /dev/null
@@ -0,0 +1,283 @@
+/**************************************************************************
+
+xevlog-analyze
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xw32defs.h>
+#include <xdbg_types.h>
+#include <xdbg_evlog.h>
+
+typedef struct _EvlogOption
+{
+    int pid;
+    Bool help_opt;
+    char command_name[PATH_MAX+1];
+    char path_name[PATH_MAX+1];
+} EvlogOption;
+
+#define BUF_SIZE 256
+
+
+static void
+_printUsage(char* name)
+{
+    fprintf(stderr, "Usage: %s [OPTION]...\n", name);
+    fprintf(stderr, "\n");
+    fprintf(stderr, " Options:\n");
+    fprintf(stderr, "       -f [File_Name]  File to save information\n");
+    fprintf(stderr, "\n");
+    fprintf(stderr, "       -h              Command Usage information\n");
+    fprintf(stderr, "\n");
+}
+
+static void _xEvlogAnalyzePrint (EvlogOption *eo)
+{
+    int fd = -1, cfd = -1;
+    int total, read_len;
+    int evlog_len;
+    char fd_name[256];
+    EvlogInfo evinfo={0,};
+
+    if (eo->help_opt)
+    {
+        _printUsage(eo->command_name);
+        return;
+    }
+
+    if (!eo->path_name)
+    {
+        printf ("failed: no evlog path\n");
+        return;
+    }
+
+    fd = open (eo->path_name, O_RDONLY);
+    if (fd < 0)
+    {
+        printf ("failed: open '%s'. (%s)\n", eo->path_name, strerror(errno));
+        return;
+    }
+
+    snprintf (fd_name, sizeof (fd_name), "/proc/%d/fd/1", eo->pid);
+    cfd = open (fd_name, O_RDWR);
+
+    if (cfd < 0)
+    {
+        printf ("failed: open consol '%s'. (%s)\n", fd_name, strerror(errno));
+        goto print_done;
+    }
+
+    while ((read_len = read (fd, &evlog_len, sizeof (int))) == sizeof (int))
+    {
+        char log[1024];
+        int size = sizeof (log);
+
+        total = read_len;
+
+        read_len = read (fd, &evinfo.time, sizeof (CARD32));
+        GOTO_IF_FAIL (read_len == sizeof (CARD32), print_done);
+        total += read_len;
+
+        read_len = read (fd, &evinfo.type, sizeof (EvlogType));
+        GOTO_IF_FAIL (read_len == sizeof (EvlogType), print_done);
+        GOTO_IF_FAIL (evinfo.type >= EVENT && evinfo.type <= FLUSH, print_done);
+        total += read_len;
+
+        read_len = read (fd, &evinfo.mask, sizeof (int));
+        GOTO_IF_FAIL (read_len == sizeof (int), print_done);
+        total += read_len;
+
+        if (evinfo.mask & EVLOG_MASK_CLIENT)
+        {
+            read_len = read (fd, &evinfo.client, sizeof (EvlogClient));
+            GOTO_IF_FAIL (read_len == sizeof (EvlogClient), print_done);
+            total += read_len;
+        }
+
+        if (evinfo.mask & EVLOG_MASK_REQUEST)
+        {
+            read_len = read (fd, &evinfo.req, sizeof(EvlogRequest));
+            GOTO_IF_FAIL (read_len == sizeof(EvlogRequest), print_done);
+            total += read_len;
+
+            evinfo.req.ptr = malloc (sizeof(xReq));
+            GOTO_IF_FAIL (evinfo.req.ptr != NULL, print_done);
+
+            read_len = read (fd, evinfo.req.ptr, sizeof (xReq));
+            GOTO_IF_FAIL (read_len == sizeof(xReq), print_done);
+            total += read_len;
+        }
+
+        else if (evinfo.mask & EVLOG_MASK_EVENT)
+        {
+            read_len = read (fd, &evinfo.evt, sizeof(EvlogEvent));
+            GOTO_IF_FAIL (read_len == sizeof(EvlogEvent), print_done);
+            total += read_len;
+
+            evinfo.evt.ptr = malloc (sizeof(xEvent));
+            GOTO_IF_FAIL (evinfo.evt.ptr != NULL, print_done);
+
+            read_len = read (fd, evinfo.evt.ptr, sizeof (xEvent));
+            GOTO_IF_FAIL (read_len == sizeof(xEvent), print_done);
+            total += read_len;
+        }
+        GOTO_IF_FAIL (evlog_len == total, print_done);
+
+        xDbgEvlogFillLog(&evinfo, log, &size);
+        printf ("%s", log);
+
+        if (evinfo.req.ptr)
+        {
+            free (evinfo.req.ptr);
+            evinfo.req.ptr = NULL;
+        }
+
+        else if (evinfo.evt.ptr)
+        {
+            free (evinfo.evt.ptr);
+            evinfo.evt.ptr = NULL;
+        }
+    }
+
+
+print_done:
+    if (evinfo.req.ptr)
+        free (evinfo.req.ptr);
+
+    else if (evinfo.evt.ptr)
+        free (evinfo.evt.ptr);
+
+    if (cfd >= 0)
+        close (cfd);
+
+    if (fd >= 0)
+        close (fd);
+}
+
+static void
+_checkOption(int argc, char** argv)
+{
+    int c;
+    int opt_str_len = 0;
+    char* opt_str = NULL;
+    EvlogOption eo = {0,};
+
+    eo.pid = atoi (argv[0]);
+    eo.help_opt = TRUE;
+    strncpy(eo.command_name, argv[1], PATH_MAX);
+
+    if (argc <= 2)
+    {
+        _printUsage( eo.command_name );
+        return;
+    }
+
+    while ((c = getopt(argc, argv, "f:h")) != EOF)
+    {
+        switch (c)
+        {
+
+            case 'f':
+                opt_str = optarg;
+                opt_str_len = strlen(opt_str);
+
+                if(opt_str_len > 0)
+                {
+                    eo.help_opt = FALSE;
+                    strncpy (eo.path_name, opt_str, opt_str_len);
+                }
+                break;
+
+            case 'h':
+                _printUsage( eo.command_name );
+                return;
+                break;
+
+            default:
+                break;
+        }
+    }
+
+    _xEvlogAnalyzePrint(&eo);
+}
+
+
+int main(int argc, char** argv)
+{
+
+    Display *dpy;
+    char **new_argv;
+    int new_argc, i;
+    char temp[128];
+
+    dpy = XOpenDisplay (NULL);
+    if (!dpy)
+    {
+        fprintf (stderr, "failed: open display\n");
+        exit (-1);
+    }
+
+    new_argc = argc + 1;
+    new_argv = (char**)malloc (new_argc * sizeof (char*));
+    if (!new_argv)
+    {
+        fprintf (stderr, "failed: malloc new argv\n");
+        exit (-1);
+    }
+
+    snprintf (temp, sizeof(temp), "%d", (int)getpid());
+    new_argv[0] = temp;
+
+    for (i = 0; i < argc; i++)
+        new_argv[i+1] = argv[i];
+
+    _checkOption(new_argc, new_argv);
+
+    free (new_argv);
+
+    XCloseDisplay (dpy);
+
+    return 0;
+}
diff --git a/common/Makefile.am b/common/Makefile.am
new file mode 100644 (file)
index 0000000..92e0701
--- /dev/null
@@ -0,0 +1,61 @@
+# Copyright 2013 Samsung Electronics co., Ltd. All Rights Reserved.
+#
+# Contact: Boram Park <boram1288.park@samsung.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sub license, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice (including the
+# next paragraph) shall be included in all copies or substantial portions
+# of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+# IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+COMMON_SOURCE =  \
+    xdbg_dbus_client.c \
+    xdbg_evlog.c \
+    xdbg_evlog_request.c \
+    xdbg_evlog_event.c \
+    ds/bintree.c \
+    ds/bool_exp_parser.c \
+    ds/bool_exp_rule_checker.c \
+    ds/bool_exp_tokenizer.c
+
+COMMON_CFLAGS = \
+    ${CFLAGS} \
+    @XDBG_CFLAGS@ \
+    -I$(top_srcdir)/lib \
+    -I$(top_srcdir)/common \
+    -I$(top_srcdir)/common/ds
+
+COMMON_CLIENT_CFLAGS = \
+    ${CFLAGS} \
+    @XDBG_CLIENT_CFLAGS@ \
+    -I$(top_srcdir)/common \
+    -I$(top_srcdir)/common/ds
+
+
+noinst_LTLIBRARIES = libcommon-client.la  \
+                     libcommon-server.la
+
+libcommon_client_la_LIBADD = ${LDFLAGS} @XDBG_LIBS@
+libcommon_client_la_LDFLAGS = ${LDFLAGS} @XDBG_LIBS@
+libcommon_client_la_CFLAGS = ${COMMON_CLIENT_CFLAGS}
+libcommon_client_la_SOURCES = $(COMMON_SOURCE)
+
+libcommon_server_la_LIBADD = ${LDFLAGS} @XDBG_LIBS@
+libcommon_server_la_LDFLAGS = ${LDFLAGS} @XDBG_LIBS@
+libcommon_server_la_CFLAGS = ${COMMON_CFLAGS}
+libcommon_server_la_SOURCES = $(COMMON_SOURCE) \
+                                xdbg_dbus_server.c
similarity index 99%
rename from module/ds/bintree.c
rename to common/ds/bintree.c
index a38cf2e..0625d78 100644 (file)
@@ -162,4 +162,3 @@ void bintree_postorder_traverse (BINARY_TREE tree, BINTREE_TRAVERSE_FUNC func, v
     if (tree->head)
         bintree_postorder_traverse_recursive (tree, tree->head, tree->head, func, arg);
 }
-
similarity index 99%
rename from module/ds/bintree.h
rename to common/ds/bintree.h
index be4040c..24befed 100644 (file)
@@ -64,4 +64,3 @@ void bintree_inorder_traverse (BINARY_TREE tree, BINTREE_TRAVERSE_FUNC func, voi
 void bintree_postorder_traverse (BINARY_TREE tree, BINTREE_TRAVERSE_FUNC func, void * arg);
 
 #endif /* _BOOL_EXP_BINTREE_H_ */
-
similarity index 99%
rename from module/ds/bool_exp_parser.c
rename to common/ds/bool_exp_parser.c
index 7c37a2d..be40b16 100644 (file)
@@ -258,4 +258,3 @@ BINARY_TREE bool_exp_parse (const char * string)
 
     return tree;
 }
-
similarity index 99%
rename from module/ds/bool_exp_parser.h
rename to common/ds/bool_exp_parser.h
index 2b0bcb5..ba89be5 100644 (file)
@@ -60,4 +60,3 @@ struct _PARSE_DATA
 BINARY_TREE bool_exp_parse (const char * string);
 
 #endif /* _BOOL_EXP_PARSER_H_ */
-
similarity index 99%
rename from module/ds/bool_exp_rule_checker.c
rename to common/ds/bool_exp_rule_checker.c
index 5c3204a..563e9a2 100644 (file)
@@ -397,4 +397,3 @@ int rulechecker_validate_rule (RULE_CHECKER rc, int type, int reqID, const char
 
     return default_policy == ALLOW;
 }
-
similarity index 99%
rename from module/ds/bool_exp_rule_checker.h
rename to common/ds/bool_exp_rule_checker.h
index 76c0b25..44689d2 100644 (file)
@@ -52,4 +52,3 @@ const char * rulechecker_print_usage (void);
 int rulechecker_validate_rule (RULE_CHECKER rc, int direct, int reqID, const char * name, int pid, char * cmd);
 
 #endif /* _BOOL_EXP_RULE_CHECKER_H_ */
-
similarity index 99%
rename from module/ds/bool_exp_token.h
rename to common/ds/bool_exp_token.h
index 542ef0f..03b56f2 100644 (file)
@@ -51,4 +51,3 @@ typedef enum
 } TOKEN;
 
 #endif /* _BOOL_EXP_TOKEN_H_ */
-
similarity index 99%
rename from module/ds/bool_exp_tokenizer.h
rename to common/ds/bool_exp_tokenizer.h
index 6d3c4df..42f9433 100644 (file)
@@ -35,4 +35,3 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 TOKEN get_next_token (const char ** string);
 
 #endif /* _BOOL_EXP_TOKENIZER_ */
-
similarity index 100%
rename from dbus/xdbg_dbus.h
rename to common/xdbg_dbus.h
similarity index 89%
rename from dbus/xdbg_dbus_client.c
rename to common/xdbg_dbus_client.c
index 5402be3..5321a6d 100644 (file)
@@ -36,19 +36,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "xdbg.h"
+#include "xdbg_types.h"
 #include "xdbg_dbus_client.h"
 
 #define REPLY_TIME 1000
 #define STR_LEN  128
 
-#define WARNING_IF_FAIL(cond)         {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
-#define RETURN_IF_FAIL(cond)          {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
-#define RETURN_VAL_IF_FAIL(cond, val) {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return val; }}
-#define RETURN_VAL_IF_ERRNO(cond, val, errno)       {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); return val; }}
-#define GOTO_IF_FAIL(cond, dst)       {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
-#define GOTO_IF_ERRNO(cond, dst, errno)       {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
-
 struct _XDbgDBusClientInfo
 {
     DBusConnection *conn;
old mode 100755 (executable)
new mode 100644 (file)
similarity index 99%
rename from dbus/xdbg_dbus_server.c
rename to common/xdbg_dbus_server.c
index b8c1961..e8ac325
@@ -41,6 +41,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <dix.h>
 
 #include "xdbg.h"
+#include "xdbg_types.h"
 #include "xdbg_dbus_server.h"
 
 #define ARGV_NUM        128
diff --git a/common/xdbg_evlog.c b/common/xdbg_evlog.c
new file mode 100644 (file)
index 0000000..b80dec5
--- /dev/null
@@ -0,0 +1,270 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <time.h>
+
+#include "xdbg_types.h"
+#include "xdbg_evlog.h"
+#include "bool_exp_rule_checker.h"
+
+static char *evt_type[] = { "Event", "Request", "Reply", "Flush" };
+static char *evt_dir[]  = { "<====", "---->",   "<----", "*****" };
+
+static RULE_CHECKER rc = NULL;
+
+static void
+_mergeArgs (char * target, int argc, const char ** argv)
+{
+    int i;
+    int len;
+
+    for (i=0; i<argc; i++)
+    {
+        len = sprintf (target, "%s", argv[i]);
+        target += len;
+
+        if (i != argc - 1)
+            *(target++) = ' ';
+    }
+}
+
+static int
+_strcasecmp(const char *str1, const char *str2)
+{
+    const u_char *us1 = (const u_char *) str1, *us2 = (const u_char *) str2;
+
+    while (tolower(*us1) == tolower(*us2)) {
+        if (*us1++ == '\0')
+            return 0;
+        us2++;
+    }
+
+    return (tolower(*us1) - tolower(*us2));
+}
+
+char*
+xDbgEvlogGetCmd (char *path)
+{
+    char *p;
+    if (!path)
+        return NULL;
+    p = strrchr (path, '/');
+    return (p)?p+1:path;
+}
+
+Bool
+xDbgEvlogRuleSet (const int argc, const char **argv, char *reply, int *len)
+{
+    const char * command;
+
+    if (rc == NULL)
+        rc = rulechecker_init();
+
+    if (argc == 0)
+    {
+        rulechecker_print_rule (rc, reply);
+        return TRUE;
+    }
+
+    command = argv[0];
+
+    if (!_strcasecmp (command, "add"))
+    {
+        POLICY_TYPE policy_type;
+        RC_RESULT_TYPE result;
+        const char * policy = argv[1];
+        char rule[8192];
+
+        if (argc < 3)
+        {
+            XDBG_REPLY ("Error : Too few arguments.\n");
+            return FALSE;
+        }
+
+        if (!_strcasecmp (policy, "ALLOW"))
+            policy_type = ALLOW;
+        else if (!_strcasecmp (policy, "DENY"))
+            policy_type = DENY;
+        else
+        {
+            XDBG_REPLY ("Error : Unknown policy : [%s].\n          Policy should be ALLOW or DENY.\n", policy);
+            return FALSE;
+        }
+
+        _mergeArgs (rule, argc - 2, &(argv[2]));
+
+        result = rulechecker_add_rule (rc, policy_type, rule);
+        if (result == RC_ERR_TOO_MANY_RULES)
+        {
+            XDBG_REPLY ("Error : Too many rules were added.\n");
+            return FALSE;
+        }
+        else if (result == RC_ERR_PARSE_ERROR)
+        {
+            XDBG_REPLY ("Error : An error occured during parsing the rule [%s]\n", rule);
+            return FALSE;
+        }
+
+        XDBG_REPLY ("The rule was successfully added.\n\n");
+        rulechecker_print_rule (rc, reply);
+        return TRUE;
+    }
+    else if (!_strcasecmp (command, "remove"))
+    {
+        const char * remove_idx;
+        int i;
+
+        if (argc < 2)
+        {
+            XDBG_REPLY ("Error : Too few arguments.\n");
+            return FALSE;
+        }
+
+        for (i=0; i<argc - 1; i++)
+        {
+            remove_idx = argv[i+1];
+
+            if (!_strcasecmp (remove_idx, "all"))
+            {
+                rulechecker_destroy (rc);
+                rc = rulechecker_init();
+                XDBG_REPLY ("Every rules were successfully removed.\n");
+            }
+            else
+            {
+                int index = atoi (remove_idx);
+                if (isdigit (*remove_idx) && rulechecker_remove_rule (rc, index) == 0)
+                    XDBG_REPLY ("The rule [%d] was successfully removed.\n", index);
+                else
+                    XDBG_REPLY ("Rule remove fail : No such rule [%s].\n", remove_idx);
+            }
+        }
+        rulechecker_print_rule (rc, reply);
+        return TRUE;
+    }
+    else if (!_strcasecmp (command, "print"))
+    {
+        rulechecker_print_rule (rc, reply);
+        return TRUE;
+    }
+    else if (!_strcasecmp (command, "help"))
+    {
+        XDBG_REPLY ("%s", rulechecker_print_usage());
+        return TRUE;
+    }
+
+    XDBG_REPLY ("%s\nUnknown command : [%s].\n\n", rulechecker_print_usage(), command);
+
+    return TRUE;
+}
+
+Bool
+xDbgEvlogRuleValidate (EvlogInfo *evinfo)
+{
+    const char *evlog_name = "";
+    char *cmd = "";
+
+    if (rc == NULL)
+        rc = rulechecker_init ();
+
+    if (!rc)
+    {
+        fprintf (stderr, "failed: create rulechecker\n");
+        return FALSE;
+    }
+
+    cmd = xDbgEvlogGetCmd (evinfo->client.command);
+
+    if (evinfo->type == REQUEST)
+        evlog_name = evinfo->req.name;
+    else if (evinfo->type == EVENT)
+        evlog_name = evinfo->evt.name;
+
+    return rulechecker_validate_rule (rc,
+                                      evinfo->type,
+                                      evinfo->req.id,
+                                      evlog_name,
+                                      evinfo->client.pid,
+                                      cmd);
+}
+
+void
+xDbgEvlogFillLog (EvlogInfo *evinfo, char *reply, int *len)
+{
+    static CARD32 prev;
+
+    RETURN_IF_FAIL (evinfo->type >= 0 && (sizeof (evt_dir) / sizeof (char*)));
+    RETURN_IF_FAIL (evinfo->type >= 0 && (sizeof (evt_type) / sizeof (char*)));
+
+    XDBG_REPLY ("[%10.3f][%5ld] %22s(%2d:%5d) %s %s",
+                evinfo->time / 1000.0,
+                evinfo->time - prev,
+                xDbgEvlogGetCmd (evinfo->client.command),
+                evinfo->client.index,
+                evinfo->client.pid,
+                evt_dir[evinfo->type],
+                evt_type[evinfo->type]);
+
+    if (evinfo->type == REQUEST)
+    {
+        XDBG_REPLY ("(");
+        reply = xDbgEvlogReqeust (evinfo, reply, len);
+        XDBG_REPLY (")");
+    }
+    else if (evinfo->type == EVENT)
+    {
+        XDBG_REPLY ("(");
+        reply = xDbgEvlogEvent (evinfo, reply, len);
+        XDBG_REPLY (")");
+    }
+    else
+    {
+        const char *evlog_name = "";
+        if (evinfo->type == REQUEST)
+            evlog_name = evinfo->req.name;
+        else if (evinfo->type == EVENT)
+            evlog_name = evinfo->evt.name;
+        XDBG_REPLY ("(%s)", evlog_name);
+    }
+
+    XDBG_REPLY ("\n");
+
+    prev = evinfo->time;
+}
diff --git a/common/xdbg_evlog.h b/common/xdbg_evlog.h
new file mode 100644 (file)
index 0000000..9dd4388
--- /dev/null
@@ -0,0 +1,44 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_EVLOG_H__
+#define __XDBG_EVLOG_H__
+
+#include "xdbg_types.h"
+#include "xdbg_evlog_request.h"
+#include "xdbg_evlog_event.h"
+
+char*   xDbgEvlogGetCmd         (char *path);
+Bool    xDbgEvlogRuleSet        (const int argc, const char **argv, char *reply, int *len);
+Bool    xDbgEvlogRuleValidate   (EvlogInfo *evinfo);
+void    xDbgEvlogFillLog        (EvlogInfo *evinfo, char *reply, int *len);
+
+#endif
similarity index 62%
rename from module/xdbg_module_evlog_event.c
rename to common/xdbg_evlog_event.c
index a608546..899c351 100644 (file)
@@ -52,54 +52,98 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <X11/extensions/damageproto.h>
 #include <X11/extensions/damagewire.h>
 #include <X11/extensions/XI2proto.h>
+#include <X11/Xlib.h>
 #include <windowstr.h>
+#include <X11/extensions/Xdamage.h>
 
-#include <xdbg.h>
+#include "xdbg_types.h"
+#include "xdbg_evlog_event.h"
 
-#include "xdbg_module_types.h"
-#include "xdbg_module_evlog_request.h"
 
 #define UNKNOWN_EVENT "<unknown>"
 
+#ifdef XDBG_CLIENT
+static int damage_base;
+static int damage_err_base;
+#else
 static ExtensionEntry *damage;
+#endif
 
 static Bool
-_EvlogEventGetExtentionEntry (void)
+_EvlogEventGetExtentionEntry ()
 {
+#ifdef XDBG_CLIENT
+
     static int init = 0;
     static Bool success = FALSE;
+    Display *dpy;
 
     if (init)
         return success;
 
     init = 1;
 
-    damage = CheckExtension (DAMAGE_NAME); 
-    XDBG_RETURN_VAL_IF_FAIL (damage != NULL, FALSE);
+    dpy = XOpenDisplay (NULL);
+    if (!dpy)
+    {
+        fprintf (stderr, "failed: open display\n");
+        exit (-1);
+    }
+
+    if (!XDamageQueryExtension(dpy, &damage_base, &damage_err_base))
+    {
+        fprintf (stderr, "[UTILX] no X Damage extension. \n");
+        return False;
+    }
+    success = TRUE;
+    XCloseDisplay (dpy);
+    return success;
+
+#else
+
+    static int init = 0;
+    static Bool success = FALSE;
+
+    if (init)
+        return success;
+
+    init = 1;
+    damage = CheckExtension (DAMAGE_NAME);
+    RETURN_VAL_IF_FAIL (damage != NULL, FALSE);
 
     success = TRUE;
 
     return success;
+
+#endif
 }
 
-Bool
-xDbgModuleEvlogEvent (xEvent *ev, char *buf, int remain)
+
+char *
+xDbgEvlogEvent (EvlogInfo *evinfo, char *reply, int *len)
 {
-    const char *evt_name;
-    int len;
+    EvlogEvent   ev;
+    xEvent *xEvt = NULL;
+
+    RETURN_VAL_IF_FAIL (evinfo != NULL, reply);
+    RETURN_VAL_IF_FAIL (evinfo->type == EVENT, reply);
+
+    ev = evinfo->evt;
+    xEvt = ev.ptr;
 
     if (!_EvlogEventGetExtentionEntry ())
-        return FALSE;
+        return reply;
 
-    evt_name = LookupEventName ((int)(ev->u.u.type));
-    len = snprintf (buf, remain, "%s", evt_name);
-    buf += len;
-    remain -= len;
+    XDBG_REPLY ("%s", ev.name);
 
-    if (ev->u.u.type == damage->eventBase + XDamageNotify)
+#ifdef XDBG_CLIENT
+    if (xEvt->u.u.type == damage_base + XDamageNotify)
+#else
+    if (xEvt->u.u.type == damage->eventBase + XDamageNotify)
+#endif
     {
-        xDamageNotifyEvent *damage_e = (xDamageNotifyEvent*)ev;
-        snprintf (buf, remain, ": XID(%lx) area(%d,%d %dx%d) geo(%d,%d %dx%d)",
+        xDamageNotifyEvent *damage_e = (xDamageNotifyEvent*)xEvt;
+        XDBG_REPLY (": XID(%lx) area(%d,%d %dx%d) geo(%d,%d %dx%d)",
             damage_e->drawable,
             damage_e->area.x,
             damage_e->area.y,
@@ -109,9 +153,7 @@ xDbgModuleEvlogEvent (xEvent *ev, char *buf, int remain)
             damage_e->geometry.y,
             damage_e->geometry.width,
             damage_e->geometry.height);
-        return TRUE;
+        return reply;
     }
-
-    return FALSE;
+    return reply;
 }
-
similarity index 86%
rename from module/xdbg_module_evlog_event.h
rename to common/xdbg_evlog_event.h
index 6bb2096..67dbccb 100644 (file)
@@ -29,11 +29,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
-#ifndef __XDBG_MODULE_EVLOG_EVENT_H__
-#define __XDBG_MODULE_EVLOG_EVENT_H__
+#ifndef __XDBG_EVLOG_EVENT_H__
+#define __XDBG_EVLOG_EVENT_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_types.h"
 
-Bool  xDbgModuleEvlogEvent (xEvent *ev, char *buf, int remain);
+char *  xDbgEvlogEvent (EvlogInfo *evinfo, char *reply, int *len);
 
-#endif /* __XDBG_MODULE_EVLOG_EVENT_H__ */
+#endif
similarity index 60%
rename from module/xdbg_module_evlog_request.c
rename to common/xdbg_evlog_request.c
index 3328325..d6c14cc 100644 (file)
@@ -50,38 +50,75 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <xacestr.h>
 #include <X11/Xatom.h>
 #include <X11/extensions/XI2proto.h>
+#include <X11/Xlib.h>
 #include <windowstr.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
 
-#include <xdbg.h>
-
-#include "xdbg_module_types.h"
-#include "xdbg_module_evlog_request.h"
+#include "xdbg_types.h"
+#include "xdbg_evlog_request.h"
 
 #define UNKNOWN_EVENT "<unknown>"
 
+#ifdef XDBG_CLIENT
+static int base;
+#else
 static ExtensionEntry *xext;
+#endif
 
 static Bool
-_EvlogRequestGetExtentionEntry (void)
+_EvlogRequestGetExtentionEntry ()
 {
+#ifdef XDBG_CLIENT
+
     static int init = 0;
     static Bool success = FALSE;
+    Display *dpy;
 
     if (init)
         return success;
 
     init = 1;
 
-    xext = CheckExtension (SHMNAME); 
-    XDBG_RETURN_VAL_IF_FAIL (xext != NULL, FALSE);
+    dpy = XOpenDisplay (NULL);
+    if (!dpy)
+    {
+        fprintf (stderr, "failed: open display\n");
+        exit (-1);
+    }
+
+    if (!XShmQueryExtension (dpy))
+    {
+        fprintf (stderr, "[UTILX] no XShm extension. !!\n");
+        return False;
+    }
+    printf("debug request\n");
+    base = XShmGetEventBase(dpy);
+    success = TRUE;
+    XCloseDisplay (dpy);
+    return success;
+
+#else
+
+    static int init = 0;
+    static Bool success = FALSE;
+
+    if (init)
+        return success;
+
+    init = 1;
+    xext = CheckExtension (SHMNAME);
+    RETURN_VAL_IF_FAIL (xext != NULL, FALSE);
 
     success = TRUE;
 
     return success;
+
+#endif
 }
 
-static Bool
-_EvlogRequestCore (xReq *req, char *buf, int remain)
+static char *
+_EvlogRequestCore (xReq *req, char *reply, int *len)
 {
     xReq *stuff = req;
 
@@ -90,23 +127,23 @@ _EvlogRequestCore (xReq *req, char *buf, int remain)
     case X_PutImage:
         {
             xPutImageReq *stuff = (xPutImageReq *)req;
-            snprintf (buf, remain, ": XID(%lx) size(%dx%d) dst(%d,%d)",
+            XDBG_REPLY (": XID(%lx) size(%dx%d) dst(%d,%d)",
                 stuff->drawable,
                 stuff->width,
                 stuff->height,
                 stuff->dstX,
                 stuff->dstY);
-            return TRUE;
+            return reply;
         }
     default:
             break;
     }
 
-    return FALSE;
+    return reply;
 }
 
-static Bool
-_EvlogRequestShm (xReq *req, char *buf, int remain)
+static char *
+_EvlogRequestShm (xReq *req, char *reply, int *len)
 {
     xReq *stuff = req;
 
@@ -115,7 +152,7 @@ _EvlogRequestShm (xReq *req, char *buf, int remain)
     case X_ShmPutImage:
         {
             xShmPutImageReq *stuff = (xShmPutImageReq *)req;
-            snprintf (buf, remain, ": XID(%lx) size(%dx%d) src(%d,%d %dx%d) dst(%d,%d)",
+            XDBG_REPLY (": XID(%lx) size(%dx%d) src(%d,%d %dx%d) dst(%d,%d)",
                 stuff->drawable,
                 stuff->totalWidth,
                 stuff->totalHeight,
@@ -125,43 +162,49 @@ _EvlogRequestShm (xReq *req, char *buf, int remain)
                 stuff->srcHeight,
                 stuff->dstX,
                 stuff->dstY);
-            return TRUE;
+            return reply;
         }
     default:
             break;
     }
 
-    return FALSE;
+    return reply;
 }
 
-Bool
-xDbgModuleEvlogReqeust (EvlogClientInfo *evinfo, xReq *req, char *buf, int remain)
+char *
+xDbgEvlogReqeust (EvlogInfo *evinfo, char *reply, int *len)
 {
-    const char *req_name;
-    int len;
+    EvlogRequest req;
+    xReq *xReq = NULL;
 
-    if (!_EvlogRequestGetExtentionEntry () || !req)
-        return FALSE;
+    RETURN_VAL_IF_FAIL (evinfo != NULL, reply);
+    RETURN_VAL_IF_FAIL (evinfo->type == REQUEST, reply);
 
-    if (req->reqType < EXTENSION_BASE)
-    {
-        req_name = LookupRequestName (req->reqType, 0);
-        len = snprintf (buf, remain, "%s", req_name);
-        buf += len;
-        remain -= len;
+    req = evinfo->req;
+    xReq = req.ptr;
 
-        return _EvlogRequestCore (req, buf, remain);
+    if (!_EvlogRequestGetExtentionEntry ())
+        return reply;
+
+    XDBG_REPLY ("%s", req.name);
+
+    if (xReq->reqType < EXTENSION_BASE)
+    {
+        return _EvlogRequestCore (xReq, reply, len);
     }
     else
     {
-        req_name = LookupRequestName (req->reqType, req->data);
-        len = snprintf (buf, remain, "%s", req_name);
-        buf += len;
-        remain -= len;
 
-        if (req->reqType == xext->base)
-           return _EvlogRequestShm (req, buf, remain);
+#ifdef XDBG_CLIENT
+        if (xReq->reqType == base)
+#else
+        if (xReq->reqType == xext->base)
+#endif
+
+        {
+            return _EvlogRequestShm (xReq, reply, len);
+        }
     }
 
-    return FALSE;
+    return reply;
 }
similarity index 84%
rename from module/xdbg_module_evlog_request.h
rename to common/xdbg_evlog_request.h
index cad513d..ef75ca6 100644 (file)
@@ -29,11 +29,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
-#ifndef __XDBG_MODULE_EVLOG_REQUEST_H__
-#define __XDBG_MODULE_EVLOG_REQUEST_H__
+#ifndef __XDBG_EVLOG_REQUEST_H__
+#define __XDBG_EVLOG_REQUEST_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_types.h"
 
-Bool  xDbgModuleEvlogReqeust (EvlogClientInfo *evinfo, xReq *req , char *buf, int remain);
+char * xDbgEvlogReqeust (EvlogInfo *evinfo, char *reply, int *len);
 
-#endif /* __XDBG_MODULE_EVLOG_REQUEST_H__ */
+#endif
diff --git a/common/xdbg_types.h b/common/xdbg_types.h
new file mode 100644 (file)
index 0000000..8a19c77
--- /dev/null
@@ -0,0 +1,116 @@
+/**************************************************************************
+
+xdbg
+
+Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+
+Contact: Boram Park <boram1288.park@samsung.com>
+         Sangjin LEE <lsj119@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __XDBG_TYPES_H__
+#define __XDBG_TYPES_H__
+
+#include <xf86.h>
+#include <X11/Xdefs.h> /* for Bool */
+
+#define XDBG_PATH_MAX        1024
+
+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#define SWAP(a, b)  ({int t; t = a; a = b; b = t;})
+
+#define WARNING_IF_FAIL(cond) \
+    {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
+#define RETURN_IF_FAIL(cond) \
+    {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
+#define RETURN_VAL_IF_FAIL(cond, val) \
+    {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); return val; }}
+#define RETURN_VAL_IF_ERRNO(cond, val, errno) \
+    {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); return val; }}
+#define GOTO_IF_FAIL(cond, dst) \
+    {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
+#define GOTO_IF_ERRNO(cond, dst, errno) \
+    {if (!(cond)) { fprintf (stderr, "[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
+
+#define XDBG_REPLY(fmt, ARG...)  \
+    do { \
+        if (reply && len && *len > 0) \
+        { \
+            int s = snprintf (reply, *len, fmt, ##ARG); \
+            reply += s; \
+            *len -= s; \
+        } \
+    } while (0)
+
+#define UNKNOWN_EVENT "<unknown>"
+
+typedef enum
+{
+    EVENT,
+    REQUEST,
+    REPLY,
+    FLUSH
+} EvlogType;
+
+#define EVLOG_MASK_CLIENT    (1<<0)
+#define EVLOG_MASK_REQUEST   (1<<1)
+#define EVLOG_MASK_EVENT     (1<<2)
+
+typedef struct _EvlogClient
+{
+    int     index;
+    int     pid;
+    int     gid;
+    int     uid;
+    char    command[PATH_MAX+1];
+} EvlogClient;
+
+typedef struct _EvlogRequest
+{
+    int     id;
+    CARD32  length;
+    xReq   *ptr;
+    char    name[PATH_MAX+1];
+} EvlogRequest;
+
+typedef struct _EvlogEvent
+{
+    xEvent *ptr;
+    char    name[PATH_MAX+1];
+} EvlogEvent;
+
+typedef struct _EvlogInfo
+{
+    EvlogType    type;
+
+    int          mask;
+    EvlogClient  client;
+    EvlogRequest req;
+    EvlogEvent   evt;
+
+    CARD32       time;
+} EvlogInfo;
+
+#endif
index 7f86074..086585a 100644 (file)
@@ -49,10 +49,15 @@ AC_ARG_WITH(xorg-module-dir,
                            [moduledir="$libdir/xorg/modules"])
 
 # Checks for pkg-config packages
-PKG_CHECK_MODULES(XDBG, xorg-server x11 dbus-1 bigreqsproto compositeproto damageproto dmxproto dri2proto fixesproto fontsproto gestureproto inputproto kbproto randrproto recordproto renderproto resourceproto scrnsaverproto videoproto xcmiscproto xextproto xf86bigfontproto xf86dgaproto xf86driproto xf86vidmodeproto xineramaproto xproto libdrm)
+PKG_CHECK_MODULES(XDBG, xorg-server x11 xdamage xext dbus-1 bigreqsproto compositeproto damageproto dmxproto dri2proto fixesproto fontsproto gestureproto inputproto kbproto randrproto recordproto renderproto resourceproto scrnsaverproto videoproto xcmiscproto xextproto xf86bigfontproto xf86dgaproto xf86driproto xf86vidmodeproto xineramaproto xproto libdrm)
 AC_SUBST([XDBG_CFLAGS])
 AC_SUBST([XDBG_LIBS])
 
+XDBG_CLIENT_CFLAGS="${XDBG_CFLAGS} -DXDBG_CLIENT"
+XDBG_CLIENT_LIBS="${XDBG_LIBS}"
+AC_SUBST([XDBG_CLIENT_CFLAGS])
+AC_SUBST([XDBG_CLIENT_LIBS])
+
 # Checks for header files.
 AC_HEADER_STDC
 
@@ -63,9 +68,10 @@ AC_SUBST([moduledir])
 AC_DEFINE_UNQUOTED(MODULE_NAME, "$MODULE_NAME", [module name])
 
 AC_OUTPUT([Makefile
-           dbus/Makefile
+           common/Makefile
            bin/Makefile
            bin/xdbg/Makefile
+           bin/xevlog_analyze/Makefile
            lib/Makefile
            lib/xdbg.pc
            module/Makefile])
@@ -74,3 +80,5 @@ echo "CFLAGS     : $CFLAGS"
 echo "LDFLAGS    : $LDFLAGS"
 echo "XDBG_CFLAGS: $XDBG_CFLAGS"
 echo "XDBG_LIBS  : $XDBG_LIBS"
+echo "XDBG_CLIENT_CFLAGS: $XDBG_CLIENT_CFLAGS"
+echo "XDBG_CLIENT_LIBS  : $XDBG_CLIENT_LIBS"
index 0891b29..d2f640e 100644 (file)
@@ -29,7 +29,8 @@ libxdbg_log_la_LDFLAGS = ${LDFLAGS}
 libxdbg_log_la_CFLAGS = \
     ${CFLAGS} \
     @XDBG_CFLAGS@ \
-    -I$(top_srcdir)/lib
+    -I$(top_srcdir)/lib \
+    -I$(top_srcdir)/common
 
 libxdbg_log_la_SOURCES = \
        xdbg_log.c \
old mode 100755 (executable)
new mode 100644 (file)
index a18723a..05dde89
@@ -29,6 +29,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
+#if defined(XDBG_CLIENT)
+#error "This header is not for client."
+#endif
+
 #ifndef __XDBG_H__
 #define __XDBG_H__
 
old mode 100755 (executable)
new mode 100644 (file)
index ba1aa21..78e8a38
@@ -29,6 +29,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
+#if defined(XDBG_CLIENT)
+#error "This header is not for client."
+#endif
+
 #ifndef __XDBG_LOG_H__
 #define __XDBG_LOG_H__
 
@@ -90,7 +94,7 @@ void* xDbgLog            (unsigned int module, int logoption, const char *file,
 #define XDBG_KLOG(mod, fmt, ARG...)       XLOG_KLOG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
 #define XDBG_SLOG(mod, fmt, ARG...)       XLOG_SLOG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
 
-#define XDBG_NEVER_GET_HERE(mod)          XLOG_ERROR(mod, "[%s] ** NEVER GET HERE **\n", __FUNCTION__)
+#define XDBG_NEVER_GET_HERE(mod)          XLOG_ERROR(mod, "[%s:%d] ** NEVER GET HERE **\n", __FUNCTION__,__LINE__)
 
 #define XDBG_WARNING_IF_FAIL(cond)         {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
 #define XDBG_RETURN_IF_FAIL(cond)          {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
@@ -99,16 +103,6 @@ void* xDbgLog            (unsigned int module, int logoption, const char *file,
 #define XDBG_GOTO_IF_FAIL(cond, dst)       {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
 #define XDBG_GOTO_IF_ERRNO(cond, dst, errno)       {if (!(cond)) { ErrorF ("[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
 
-#define XDBG_REPLY(fmt, ARG...)  \
-    do { \
-        if (reply && len && *len > 0) \
-        { \
-            int s = snprintf (reply, *len, fmt, ##ARG); \
-            reply += s; \
-            *len -= s; \
-        } \
-    } while (0)
-
 unsigned int xDbgLogGetModule (char *name);
 
 #define _C(b,s)             (((b) >> (s)) & 0xFF)
old mode 100755 (executable)
new mode 100644 (file)
index 5219a87..d955300
@@ -45,7 +45,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "xdbg.h"
 #include "xdbg_log_int.h"
-
+#include "xdbg_types.h"
 #include <list.h>
 
 #ifndef API
old mode 100755 (executable)
new mode 100644 (file)
index 83d777f..1de12bf
@@ -29,6 +29,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
+#if defined(XDBG_CLIENT)
+#error "This header is not for client."
+#endif
+
 #ifndef __XDBG_LOG_DRMEVENT_H__
 #define __XDBG_LOG_DRMEVENT_H__
 
old mode 100755 (executable)
new mode 100644 (file)
index 2d06795..03738c6
@@ -40,6 +40,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xorg-server.h"
 #include "xdbg.h"
 #include "xdbg_log_int.h"
+#include "xdbg_types.h"
+#include "xdbg_log_fpsdebug.h"
 
 #ifndef API
 #define API __attribute__ ((visibility("default")))
old mode 100755 (executable)
new mode 100644 (file)
index a7bcdba..50caccb
@@ -29,6 +29,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
+#if defined(XDBG_CLIENT)
+#error "This header is not for client."
+#endif
+
 #ifndef __XDBG_LOG_FPSDEBUG_H__
 #define __XDBG_LOG_FPSDEBUG_H__
 
old mode 100755 (executable)
new mode 100644 (file)
index 08d90ce..6f4b730
@@ -43,6 +43,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <list.h>
 #include "xdbg.h"
 #include "xdbg_log_int.h"
+#include "xdbg_types.h"
+#include "xdbg_log_plist.h"
 
 /* for debug message */
 #define MMEM    XDBG_M('M','E','M',0)
old mode 100755 (executable)
new mode 100644 (file)
index 16c6174..26ba48d
@@ -29,6 +29,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
+#if defined(XDBG_CLIENT)
+#error "This header is not for client."
+#endif
+
 #ifndef __XDBG_LOG_PLIST_H__
 #define __XDBG_LOG_PLIST_H__
 
index 107709f..d732f6e 100644 (file)
 
 libxdbg_la_LTLIBRARIES = libxdbg.la
 libxdbg_ladir = @moduledir@
-libxdbg_la_LIBADD = @XDBG_LIBS@ ../dbus/libdbus.la ../lib/libxdbg-log.la
+libxdbg_la_LIBADD = @XDBG_LIBS@ ../common/libcommon-server.la ../lib/libxdbg-log.la
 libxdbg_la_LDFLAGS = -module -avoid-version ${LDFLAGS}
 libxdbg_la_CFLAGS = \
        ${CFLAGS} \
        @XDBG_CFLAGS@ \
-       -I$(top_srcdir)/dbus \
+       -I$(top_srcdir)/common \
        -I$(top_srcdir)/lib \
-       -I$(top_srcdir)/module \
-       -I$(top_srcdir)/module/ds
+       -I$(top_srcdir)/module
 
 libxdbg_la_SOURCES = \
        xdbg_module.c \
@@ -43,10 +42,4 @@ libxdbg_la_SOURCES = \
        xdbg_module_plist.c \
        xdbg_module_fpsdebug.c \
        xdbg_module_evlog.c \
-       xdbg_module_evlog_request.c \
-       xdbg_module_evlog_event.c \
-       xdbg_module_drmevent.c \
-       ds/bintree.c \
-       ds/bool_exp_parser.c \
-       ds/bool_exp_rule_checker.c \
-       ds/bool_exp_tokenizer.c
+       xdbg_module_drmevent.c
similarity index 78%
rename from module/xdbg_module_types.h
rename to module/xdbg_module.h
index 706b4d9..9d63e66 100644 (file)
@@ -29,24 +29,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 **************************************************************************/
 
-#ifndef __XDBG_MODULE_TYPES_H__
-#define __XDBG_MODULE_TYPES_H__
+#ifndef __XDBG_MODULE_H__
+#define __XDBG_MODULE_H__
 
 #include <xf86.h>
 #include <X11/Xdefs.h> /* for Bool */
-
-#define XDBG_PATH_MAX        1024
-
-#ifndef MAX
-#define MAX(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-#ifndef MIN
-#define MIN(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
-#ifndef SWAP
-#define SWAP(a, b)  ({int t; t = a; a = b; b = t;})
-#endif
+#include "xdbg_types.h"
 
 typedef struct _ModuleClientInfo
 {
@@ -66,19 +54,8 @@ typedef struct _XDbgModule
     char *evlog_path;
 } XDbgModule;
 
-typedef struct _EvlogClientInfo
-{
-    int    index;
-    int    pid;
-    int    gid;
-    int    uid;
-    char   command[PATH_MAX+1];
-    pointer requestBuffer;
-    CARD32 req_len;
-} EvlogClientInfo;
-
 extern DevPrivateKeyRec debug_client_key;
 #define DebugClientKey (&debug_client_key)
 #define GetClientInfo(pClient) ((ModuleClientInfo*)dixLookupPrivate(&(pClient)->devPrivates, DebugClientKey))
 
-#endif  /* __XDBG_MODULE_TYPES_H__ */
+#endif  /* __XDBG_MODULE_H__ */
old mode 100755 (executable)
new mode 100644 (file)
index 48c9aad..4a2bd2a
@@ -36,7 +36,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <stdio.h>
 
 #include "xdbg.h"
-#include "xdbg_module_types.h"
+#include "xdbg_types.h"
+#include "xdbg_module.h"
 
 
 void
old mode 100755 (executable)
new mode 100644 (file)
index eaed740..c49f71c
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_CLIST_H__
 #define __XDBG_MODULE_CLIST_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 void xDbgModuleCList (XDbgModule *pMod, char *reply, int *len);
 
old mode 100755 (executable)
new mode 100644 (file)
index 1f209bc..93f7bc1
@@ -42,8 +42,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <windowstr.h>
 #include <xacestr.h>
 #include <xdbg.h>
+#include "xdbg_types.h"
 #include <xf86Priv.h>
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 #include "xdbg_module_clist.h"
 #include "xdbg_module_plist.h"
 #include "xdbg_module_evlog.h"
@@ -253,19 +254,6 @@ _CommandSetEvlogPath (int pid, int argc, char **argv, char *reply, int *len, XDb
 }
 
 static void
-_CommandSetEvlogPrint (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
-{
-    char *evlog_path;
-
-    if (argc < 3 || !argv[2] || strlen(argv[2]) <= 0)
-        evlog_path = pMod->evlog_path;
-    else
-        evlog_path = argv[2];
-
-    xDbgModuleEvlogPrintEvlog (pMod, pid, evlog_path, reply, len);
-}
-
-static void
 _CommandDrmEventPending (int pid, int argc, char **argv, char *reply, int *len, XDbgModule *pMod)
 {
     if (argc != 2)
@@ -350,12 +338,6 @@ static struct
     },
 
     {
-        "evlog_print", "to print evlog file", "[filepath]",
-        NULL, "[filepath]",
-        _CommandSetEvlogPrint
-    },
-
-    {
         "drmevent_pending", "to print pending drmvents", "",
         NULL, "",
         _CommandDrmEventPending
index 5192bf1..9c4300d 100644 (file)
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_COMMAND_H__
 #define __XDBG_MODULE_COMMAND_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 void xDbgModuleCommand (void *data, int argc, char **argv, char *reply, int *len);
 Bool xDbgModuleCommandInitLogPath (XDbgModule *pMod);
old mode 100755 (executable)
new mode 100644 (file)
index 3a55b45..bfc6a04
@@ -35,7 +35,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "xdbg.h"
 #include "xdbg_log_int.h"
-#include "xdbg_module_types.h"
+#include "xdbg_types.h"
+#include "xdbg_module.h"
 
 
 void
old mode 100755 (executable)
new mode 100644 (file)
index ff5e924..c7a0ae4
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_DRMEVENT_H__
 #define __XDBG_MODULE_DRMEVENT_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 void xDbgModuleDrmEventPending (XDbgModule *pMod, char *reply, int *remain);
 
index e2f9c8f..ae47b28 100644 (file)
@@ -59,12 +59,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <windowstr.h>
 
 #include <xdbg.h>
-
-#include "xdbg_module_types.h"
+#include "xdbg_types.h"
+#include "xdbg_module.h"
 #include "xdbg_module_evlog.h"
-#include "xdbg_module_evlog_request.h"
-#include "xdbg_module_evlog_event.h"
-#include "bool_exp_rule_checker.h"
+#include "xdbg_evlog.h"
 
 #define XREGISTRY
 #include "registry.h"
@@ -77,92 +75,34 @@ static int  xev_trace_record_fd = -1;
 static Atom atom_rotate = None;
 static Atom atom_client_pid = None;
 
-RULE_CHECKER rc = NULL;
-
-#define UNKNOWN_EVENT "<unknown>"
-
-typedef enum
-{
-    EVENT,
-    REQUEST,
-    REPLY,
-    FLUSH
-} evtType;
-
-#define EVTDATA_MASK_CLIENT_INFO    0x1
-#define EVTDATA_MASK_CLIENT_REQ     0x2
-#define EVTDATA_MASK_EVENT          0x4
-
-static char *evt_type[] = { "Event", "Request", "Reply", "Flush" };
-static char *evt_dir[]  = { "<====", "---->",   "<----", "*****" };
-
-static void _evtPrintF (int fd, const char * format, ...)
+static void evtRecord (int fd, EvlogInfo *evinfo)
 {
-    va_list args;
+    int write_len = 0;
 
-    va_start (args, format);
-    if (fd < 0)
-        VErrorF (format, args);
-    else
-        vdprintf (fd, format, args);
-    va_end (args);
-}
+    XDBG_RETURN_IF_FAIL (fd >= 0)
 
-static void evtGetReqInfo (evtType type, EvlogClientInfo *evinfo, xReq *req, xEvent *ev,
-                           int *req_id, const char **req_string,
-                           char **c_cmd, int *c_index, int *c_pid)
-{
-    if (type == REQUEST && req)
-    {
-        *req_id = req->reqType;
-        if (req->reqType < EXTENSION_BASE)
-            *req_string = LookupRequestName (req->reqType, 0);
-        else
-            *req_string = LookupRequestName (req->reqType, req->data);
-    }
-    else if (type == EVENT && ev)
-        *req_string = LookupEventName ((int)(ev->u.u.type));
-
-    if(evinfo)
+    if (evinfo)
     {
-        *c_index = evinfo->index;
-        *c_pid = evinfo->pid;
+        evinfo->mask = 0;
 
-        *c_cmd = rindex (evinfo->command, '/');
-        if (*c_cmd == NULL)
-            *c_cmd = evinfo->command;
-        else
-            *c_cmd = *c_cmd + 1;
-    }
-}
-
-static void evtRecord (CARD32 msec, evtType type, EvlogClientInfo *evinfo, xEvent *ev)
-{
-    int mask = 0;
-    int write_len = sizeof (int) +
-                    sizeof (CARD32) +
-                    sizeof (evtType) +
-                    sizeof (int);
+        write_len = sizeof (int) +
+                    sizeof (EvlogType) +
+                    sizeof (int) +
+                    sizeof (CARD32);
 
-    if (xev_trace_record_fd < 0)
-        return;
+        evinfo->mask |= EVLOG_MASK_CLIENT;
+        write_len += sizeof (EvlogClient);
 
-    if (evinfo)
-    {
-        mask |= EVTDATA_MASK_CLIENT_INFO;
-        write_len += sizeof (EvlogClientInfo);
-
-        if (evinfo->requestBuffer)
+        if (evinfo->type == REQUEST)
         {
-            mask |= EVTDATA_MASK_CLIENT_REQ;
-            write_len += evinfo->req_len;
+            evinfo->mask |= EVLOG_MASK_REQUEST;
+            write_len += sizeof (EvlogRequest) + sizeof (xReq);
+        }
+        else if (evinfo->type == EVENT)
+        {
+            evinfo->mask |= EVLOG_MASK_EVENT;
+            write_len += sizeof (EvlogEvent) + sizeof (xEvent);
         }
-    }
-
-    if (ev)
-    {
-        mask |= EVTDATA_MASK_EVENT;
-        write_len += sizeof (xEvent);
     }
 
     if (write (xev_trace_record_fd, &write_len, sizeof(int)) == -1)
@@ -170,155 +110,135 @@ static void evtRecord (CARD32 msec, evtType type, EvlogClientInfo *evinfo, xEven
         XDBG_ERROR (MXDBG, "failed: write write_len\n");
         return;
     }
-    if (write (xev_trace_record_fd, &msec, sizeof(CARD32)) == -1)
-    {
-        XDBG_ERROR (MXDBG, "failed: write msec\n");
-        return;
-    }
-    if (write (xev_trace_record_fd, &type, sizeof(evtType)) == -1)
-    {
-        XDBG_ERROR (MXDBG, "failed: write type\n");
-        return;
-    }
-    if (write (xev_trace_record_fd, &mask, sizeof(int)) == -1)
-    {
-        XDBG_ERROR (MXDBG, "failed: write mask\n");
-        return;
-    }
 
     if (evinfo)
     {
-        if (write (xev_trace_record_fd, evinfo, sizeof (EvlogClientInfo)) == -1)
+        if (write (xev_trace_record_fd, &evinfo->time, sizeof(CARD32)) == -1)
+        {
+            XDBG_ERROR (MXDBG, "failed: write msec\n");
+            return;
+        }
+        if (write (xev_trace_record_fd, &evinfo->type, sizeof(EvlogType)) == -1)
+        {
+            XDBG_ERROR (MXDBG, "failed: write type\n");
+            return;
+        }
+        if (write (xev_trace_record_fd, &evinfo->mask, sizeof(int)) == -1)
+        {
+            XDBG_ERROR (MXDBG, "failed: write mask\n");
+            return;
+        }
+        if (write (xev_trace_record_fd, &evinfo->client, sizeof (EvlogClient)) == -1)
         {
             XDBG_ERROR (MXDBG, "failed: write client\n");
             return;
         }
-        if (evinfo->requestBuffer)
-            if (write (xev_trace_record_fd, evinfo->requestBuffer, evinfo->req_len) == -1)
+
+        if (evinfo->type == REQUEST)
+        {
+            if (write (xev_trace_record_fd, &evinfo->req, sizeof (EvlogRequest)) == -1)
             {
-                XDBG_ERROR (MXDBG, "failed: write requestBuffer\n");
+                XDBG_ERROR (MXDBG, "failed: write request\n");
                 return;
             }
-    }
-
-    if (ev)
-        if (write (xev_trace_record_fd, ev, sizeof (xEvent)) == -1)
+            if (write (xev_trace_record_fd, evinfo->req.ptr, sizeof (xReq)) == -1)
+            {
+                XDBG_ERROR (MXDBG, "failed: write request\n");
+                return;
+            }
+        }
+        else if (evinfo->type == EVENT)
         {
-            XDBG_ERROR (MXDBG, "failed: write ev\n");
-            return;
+            if (write (xev_trace_record_fd, &evinfo->evt, sizeof (EvlogEvent)) == -1)
+            {
+                XDBG_ERROR (MXDBG, "failed: write event\n");
+                return;
+            }
+            if (write (xev_trace_record_fd, evinfo->evt.ptr, sizeof (xEvent)) == -1)
+            {
+                XDBG_ERROR (MXDBG, "failed: write event\n");
+                return;
+            }
         }
+    }
 }
 
-static void evtPrintF (int fd, CARD32 msec, evtType type, EvlogClientInfo *evinfo, xEvent *ev)
+static void evtPrintF (int fd, EvlogInfo *evinfo)
 {
-    int   req_id = 0;
-    const char *req_string = "";
-    const char *req_detail = "";
-    char  tempbuf[256] = {0,};
-    char *c_cmd = "";
-    int   c_index = 0;
-    int   c_pid = 0;
-    static CARD32 prev;
-    xReq *req = NULL;
-
-    XDBG_RETURN_IF_FAIL (type >= 0 && (sizeof (evt_dir) / sizeof (char*)));
-    XDBG_RETURN_IF_FAIL (type >= 0 && (sizeof (evt_type) / sizeof (char*)));
-
-    if(evinfo)
-    {
-        req = (xReq *)evinfo->requestBuffer;
-    }
+    char log[1024];
+    int size = sizeof (log);
 
-    evtGetReqInfo (type, evinfo, req, ev, &req_id, &req_string, &c_cmd, &c_index, &c_pid);
+    xDbgEvlogFillLog (evinfo, log, &size);
 
-    if (type == REQUEST)
-    {
-        XDBG_RETURN_IF_FAIL (evinfo != NULL);
-        XDBG_RETURN_IF_FAIL (req != NULL);
-        xDbgModuleEvlogReqeust (evinfo, req, tempbuf, sizeof (tempbuf));
-        req_detail = tempbuf;
-    }
-    else if (type == EVENT)
-    {
-        XDBG_RETURN_IF_FAIL (ev != NULL);
-        xDbgModuleEvlogEvent (ev, tempbuf, sizeof (tempbuf));
-        req_detail = tempbuf;
-    }
+    if (fd < 0)
+        ErrorF ("%s", log);
     else
-        req_detail = req_string;
-
-    _evtPrintF (fd, "[%10.3f][%4ld] %15s(%2d:%4d) %s %7s (%s)\n",
-                msec / 1000.0,
-                msec - prev,
-                c_cmd, c_index, c_pid,
-                evt_dir[type],
-                evt_type[type], req_detail);
-
-    prev = msec;
+        dprintf (fd, "%s", log);
 }
 
-static void evtPrint (evtType type, ClientPtr client, xEvent *ev)
+static void evtPrint (EvlogType type, ClientPtr client, xEvent *ev)
 {
-    int   req_id = 0;
-    const char *req_string = "";
-    char *c_cmd = "";
-    int   c_index = 0;
-    int   c_pid = 0;
-    CARD32 curr;
-    ModuleClientInfo *info = NULL;
-    EvlogClientInfo evinfo;
-    xReq *req = NULL;
+    EvlogInfo evinfo = {0,};
 
     if (xev_trace_on == FALSE)
         return;
 
+    /* evinfo.type */
+    evinfo.type = type;
+
+    /* evinfo.client */
     if (client)
     {
-        info = GetClientInfo (client);
+        ModuleClientInfo *info = GetClientInfo (client);
         XDBG_RETURN_IF_FAIL (info != NULL);
 
-        memset (&evinfo, 0, sizeof (EvlogClientInfo));
+        evinfo.mask |= EVLOG_MASK_CLIENT;
+        evinfo.client.index = info->index;
+        evinfo.client.pid = info->pid;
+        evinfo.client.gid = info->gid;
+        evinfo.client.uid = info->uid;
+        strncpy (evinfo.client.command, info->command, strlen (info->command));
+
+        /* evinfo.req */
+        if (type == REQUEST)
+        {
+            REQUEST (xReq);
 
-        evinfo.index = info->index;
-        evinfo.pid = info->pid;
-        evinfo.gid = info->gid;
-        evinfo.uid = info->uid;
-        strncpy (evinfo.command, info->command, strlen (info->command));
-        evinfo.requestBuffer = client->requestBuffer;
-        evinfo.req_len = client->req_len;
+            evinfo.mask |= EVLOG_MASK_REQUEST;
+            evinfo.req.id = stuff->reqType;
+            evinfo.req.length = client->req_len;
+            evinfo.req.ptr = client->requestBuffer;
 
-        req = (xReq *)evinfo.requestBuffer;
+            if (stuff->reqType < EXTENSION_BASE)
+                snprintf (evinfo.req.name, sizeof (evinfo.req.name), "%s",
+                          LookupRequestName (stuff->reqType, 0));
+            else
+                snprintf (evinfo.req.name, sizeof (evinfo.req.name), "%s",
+                          LookupRequestName (stuff->reqType, stuff->data));
+        }
     }
 
-    evtGetReqInfo (type, (client)?&evinfo:NULL, req, ev, &req_id, &req_string, &c_cmd, &c_index, &c_pid);
+    /* evinfo.evt */
+    if (ev)
+    {
+        XDBG_RETURN_IF_FAIL (type == EVENT);
 
-    if (rc == NULL)
-        rc = rulechecker_init();
+        evinfo.mask |= EVLOG_MASK_EVENT;
+        evinfo.evt.ptr = ev;
+        snprintf (evinfo.evt.name, sizeof (evinfo.evt.name), "%s",
+                  LookupEventName ((int)(ev->u.u.type)));
+    }
 
-    if (!rulechecker_validate_rule (rc, type, req_id, req_string, c_pid, c_cmd))
-        return;
+    /* evinfo.time */
+    evinfo.time = GetTimeInMillis ();
 
-    curr = GetTimeInMillis ();
+    if (!xDbgEvlogRuleValidate (&evinfo))
+        return;
 
     if (xev_trace_record_fd >= 0)
-        evtRecord (curr, type, (client)?&evinfo:NULL, ev);
+        evtRecord (xev_trace_record_fd, &evinfo);
     else
-        evtPrintF (xev_trace_fd, curr, type, (client)?&evinfo:NULL, ev);
-}
-
-static void _mergeArgs (char * target, int argc, const char ** argv)
-{
-    int i;
-    int len;
-
-    for (i=0; i<argc; i++)
-    {
-        len = sprintf (target, "%s", argv[i]);
-        target += len;
-
-        if (i != argc - 1)
-            *(target++) = ' ';
-    }
+        evtPrintF (xev_trace_fd, &evinfo);
 }
 
 static const char*
@@ -631,107 +551,7 @@ xDbgModuleEvlogPrintEvents (XDbgModule *pMod, Bool on, const char * client_name,
 int
 xDbgModuleEvlogInfoSetRule (XDbgModule *pMod, const int argc, const char ** argv, char *reply, int *len)
 {
-    const char * command;
-
-    if (rc == NULL)
-        rc = rulechecker_init();
-
-    if (argc == 0)
-    {
-        rulechecker_print_rule (rc, reply);
-        return 0;
-    }
-
-    command = argv[0];
-
-    if (!strcasecmp (command, "add"))
-    {
-        POLICY_TYPE policy_type;
-        RC_RESULT_TYPE result;
-        const char * policy = argv[1];
-        char rule[8192];
-
-        if (argc < 3)
-        {
-            XDBG_REPLY ("Error : Too few arguments.\n");
-            return -1;
-        }
-
-        if (!strcasecmp (policy, "ALLOW"))
-            policy_type = ALLOW;
-        else if (!strcasecmp (policy, "DENY"))
-            policy_type = DENY;
-        else
-        {
-            XDBG_REPLY ("Error : Unknown policy : [%s].\n          Policy should be ALLOW or DENY.\n", policy);
-            return -1;
-        }
-
-        _mergeArgs (rule, argc - 2, &(argv[2]));
-
-        result = rulechecker_add_rule (rc, policy_type, rule);
-        if (result == RC_ERR_TOO_MANY_RULES)
-        {
-            XDBG_REPLY ("Error : Too many rules were added.\n");
-            return -1;
-        }
-        else if (result == RC_ERR_PARSE_ERROR)
-        {
-            XDBG_REPLY ("Error : An error occured during parsing the rule [%s]\n", rule);
-            return -1;
-        }
-
-        XDBG_REPLY ("The rule was successfully added.\n\n");
-        rulechecker_print_rule (rc, reply);
-        return 0;
-    }
-    else if (!strcasecmp (command, "remove"))
-    {
-        const char * remove_idx;
-        int i;
-
-        if (argc < 2)
-        {
-            XDBG_REPLY ("Error : Too few arguments.\n");
-            return -1;
-        }
-
-        for (i=0; i<argc - 1; i++)
-        {
-            remove_idx = argv[i+1];
-
-            if (!strcasecmp (remove_idx, "all"))
-            {
-                rulechecker_destroy (rc);
-                rc = rulechecker_init();
-                XDBG_REPLY ("Every rules were successfully removed.\n");
-            }
-            else
-            {
-                int index = atoi (remove_idx);
-                if (isdigit (*remove_idx) && rulechecker_remove_rule (rc, index) == 0)
-                    XDBG_REPLY ("The rule [%d] was successfully removed.\n", index);
-                else
-                    XDBG_REPLY ("Rule remove fail : No such rule [%s].\n", remove_idx);
-            }
-        }
-        rulechecker_print_rule (rc, reply);
-        return 0;
-    }
-    else if (!strcasecmp (command, "print"))
-    {
-        rulechecker_print_rule (rc, reply);
-        return 0;
-    }
-    else if (!strcasecmp (command, "help"))
-    {
-        XDBG_REPLY ("%s", rulechecker_print_usage());
-        return 0;
-    }
-
-    XDBG_REPLY ("%s\nUnknown command : [%s].\n\n", rulechecker_print_usage(), command);
-
-    return 0;
+    return xDbgEvlogRuleSet (argc, argv, reply, len);
 }
 
 Bool
@@ -806,104 +626,3 @@ xDbgModuleEvlogSetEvlogPath (XDbgModule *pMod, int pid, char *path, char *reply,
 
     return TRUE;
 }
-
-void
-xDbgModuleEvlogPrintEvlog (XDbgModule *pMod, int pid, char *evlog_path, char *reply, int *len)
-{
-    int fd = -1, cfd = -1;
-    int total, read_len;
-    int evlog_len;
-    pointer requestBuffer = NULL;
-    char fd_name[256];
-
-    if (!evlog_path)
-    {
-        XDBG_REPLY ("failed: no evlog path\n");
-        return;
-    }
-
-    fd = open (evlog_path, O_RDONLY);
-    if (fd < 0)
-    {
-        XDBG_REPLY ("failed: open '%s'. (%s)\n", evlog_path, strerror(errno));
-        return;
-    }
-
-    snprintf (fd_name, sizeof (fd_name), "/proc/%d/fd/1", pid);
-    cfd = open (fd_name, O_RDWR);
-    if (cfd < 0)
-    {
-        XDBG_REPLY ("failed: open consol '%s'. (%s)\n", fd_name, strerror(errno));
-        goto print_done;
-    }
-
-    while ((read_len = read (fd, &evlog_len, sizeof (int))) == sizeof (int))
-    {
-        CARD32 msec;
-        evtType type;
-        int mask;
-        EvlogClientInfo evinfo;
-        xEvent ev;
-
-        total = read_len;
-
-        read_len = read (fd, &msec, sizeof (CARD32));
-        XDBG_GOTO_IF_FAIL (read_len == sizeof (CARD32), print_done);
-        total += read_len;
-
-        read_len = read (fd, &type, sizeof (evtType));
-        XDBG_GOTO_IF_FAIL (read_len == sizeof (evtType), print_done);
-        XDBG_GOTO_IF_FAIL (type >= EVENT && type <= FLUSH, print_done);
-        total += read_len;
-
-        read_len = read (fd, &mask, sizeof (int));
-        XDBG_GOTO_IF_FAIL (read_len == sizeof (int), print_done);
-        total += read_len;
-
-        if (mask & EVTDATA_MASK_CLIENT_INFO)
-        {
-            read_len = read (fd, &evinfo, sizeof (EvlogClientInfo));
-            XDBG_GOTO_IF_FAIL (read_len == sizeof (EvlogClientInfo), print_done);
-            total += read_len;
-
-            if (mask & EVTDATA_MASK_CLIENT_REQ && evinfo.req_len > 0)
-            {
-                requestBuffer = malloc (evinfo.req_len);
-                XDBG_GOTO_IF_FAIL (requestBuffer != NULL, print_done);
-
-                read_len = read (fd, requestBuffer, evinfo.req_len);
-                XDBG_GOTO_IF_FAIL (read_len == evinfo.req_len, print_done);
-                total += read_len;
-
-                evinfo.requestBuffer = requestBuffer;
-            }
-        }
-
-        if (mask & EVTDATA_MASK_EVENT)
-        {
-            read_len = read (fd, &ev, sizeof (xEvent));
-            XDBG_GOTO_IF_FAIL (read_len == sizeof (xEvent), print_done);
-            total += read_len;
-        }
-
-        XDBG_GOTO_IF_FAIL (evlog_len == total, print_done);
-
-        evtPrintF (cfd, msec, type, &evinfo, &ev);
-
-        if (requestBuffer)
-        {
-            free (requestBuffer);
-            requestBuffer = NULL;
-        }
-    }
-
-print_done:
-    if (requestBuffer)
-        free (requestBuffer);
-
-    if (cfd >= 0)
-        close (cfd);
-
-    if (fd >= 0)
-        close (fd);
-}
index e98b251..7e19f60 100644 (file)
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_EVLOG_H__
 #define __XDBG_MODULE_EVLOG_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 Bool    xDbgModuleEvlogInstallHooks   (XDbgModule *pMod);
 void    xDbgModuleEvlogUninstallHooks (XDbgModule *pMod);
@@ -41,6 +41,5 @@ void    xDbgModuleEvlogPrintEvents (XDbgModule *pMod, Bool on, const char * clie
 int     xDbgModuleEvlogInfoSetRule (XDbgModule *pMod, const int argc, const char ** argv, char *reply, int *len);
 
 Bool    xDbgModuleEvlogSetEvlogPath  (XDbgModule *pMod, int pid, char *path, char *reply, int *len);
-void    xDbgModuleEvlogPrintEvlog    (XDbgModule *pMod, int pid, char *evlog_path, char *reply, int *len);
 
 #endif /* __XDBG_MODULE_EVLOG_H__ */
old mode 100755 (executable)
new mode 100644 (file)
index af83741..25c8e09
@@ -35,7 +35,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "xdbg.h"
 #include "xdbg_log_int.h"
-#include "xdbg_module_types.h"
+#include "xdbg_types.h"
+#include "xdbg_module.h"
 
 void
 xDbgModuleFpsDebug (XDbgModule *pMod, int on, char *reply, int *len)
old mode 100755 (executable)
new mode 100644 (file)
index 596c223..487ad0b
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_FPSDEBUG_H__
 #define __XDBG_MODULE_FPSDEBUG_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 void xDbgModuleFpsDebug (XDbgModule *pMod, int on, char *reply, int *len);
 
index f23b491..50e81f6 100644 (file)
@@ -40,7 +40,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <xdbg.h>
 
 #include "xdbg_dbus_server.h"
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 #include "xdbg_module_command.h"
 #include "xdbg_module_evlog.h"
 
index 32001d4..47130f2 100644 (file)
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_MAIN_H__
 #define __XDBG_MODULE_MAIN_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 Bool    xDbgModuleMain     (XDbgModule *pMod);
 void    xDbgModuleMainExit (XDbgModule *pMod);
index f6a5bea..ce7e172 100644 (file)
@@ -35,7 +35,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <xdbg.h>
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 /* Supported options */
 typedef enum
index 1e28c8c..42a5a1b 100644 (file)
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_OPTIONS_H__
 #define __XDBG_MODULE_OPTIONS_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 void    xDbgModuleParseOptions (XDbgModule *pMod, XF86OptionPtr pOpt);
 
old mode 100755 (executable)
new mode 100644 (file)
index 27e5e85..3f40330
@@ -35,7 +35,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "xdbg.h"
 #include "xdbg_log_int.h"
-#include "xdbg_module_types.h"
+#include "xdbg_types.h"
+#include "xdbg_module.h"
+
 
 void
 xDbgModulePList (XDbgModule *pMod, char *reply, int *len)
old mode 100755 (executable)
new mode 100644 (file)
index b15aa58..1d9299e
@@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef __XDBG_MODULE_PLIST_H__
 #define __XDBG_MODULE_PLIST_H__
 
-#include "xdbg_module_types.h"
+#include "xdbg_module.h"
 
 void xDbgModulePList (XDbgModule *pMod, char *reply, int *remain);
 
index 789738a..b0a72f2 100644 (file)
@@ -8,6 +8,7 @@ Source0:    %{name}-%{version}.tar.gz
 BuildRequires:  pkgconfig(xorg-server)
 BuildRequires:  pkgconfig(x11)
 BuildRequires:  pkgconfig(xext)
+BuildRequires:  pkgconfig(xdamage)
 BuildRequires:  pkgconfig(xorg-macros)
 BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(bigreqsproto)
@@ -71,6 +72,7 @@ cp -af COPYING %{buildroot}/usr/share/license/%{name}
 %defattr(-,root,root,-)
 /usr/share/license/%{name}
 %{_bindir}/xdbg
+%{_bindir}/xevlog_analyze
 %{_libdir}/libxdbg-log.so.*
 %{_libdir}/xorg/modules/libxdbg.so