[svn:mod_parrot] r595 - in mod_parrot/trunk: docs include src

[email protected] Fri, 23 Jan 2009 16:58:21 -0800 (PST)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Fri Jan 23 16:58:20 2009
New Revision: 595

Modified:
   mod_parrot/trunk/docs/apache-conf.txt
   mod_parrot/trunk/include/modparrot_config.h
   mod_parrot/trunk/include/modparrot_log.h
   mod_parrot/trunk/src/mod_parrot.c
   mod_parrot/trunk/src/modparrot_config.c
   mod_parrot/trunk/src/module.c

Log:
implement debugging subsystem
add apache module debugging output


Modified: mod_parrot/trunk/docs/apache-conf.txt
==============================================================================
--- mod_parrot/trunk/docs/apache-conf.txt	(original)
+++ mod_parrot/trunk/docs/apache-conf.txt	Fri Jan 23 16:58:20 2009
@@ -44,10 +44,23 @@
 Context:     server config
 Description: Start the interpreter, load and run PBC or PIR
 
+ParrotDebugLevel
+----------------
+Syntax:      ParrotDebug level
+Default:     0
+Context:     server config
+Description: Set mod_parrot's debug level (VERY verbose output).  Levels are:
+             0 = none (default)
+             1 = Apache module activity
+             2 = mod_parrot context activity
+             4 = runtime hook activity
+             8 = Parrot activity
+             16 = HLL activity
+
 ParrotTrace
 -----------
 Syntax:      ParrotTrace level
-Default:     off
+Default:     0
 Context:     server config
 Description: Enable Parrot trace output to the error log.  See Parrot docs
              for the appropriate trace levels.

Modified: mod_parrot/trunk/include/modparrot_config.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_config.h	(original)
+++ mod_parrot/trunk/include/modparrot_config.h	Fri Jan 23 16:58:20 2009
@@ -154,6 +154,7 @@
 /* config directives */
 const char *modparrot_cmd_init(cmd_parms *, void *, const char *);
 const char *modparrot_cmd_trace(cmd_parms *, void *, const char *);
+const char *modparrot_cmd_debug(cmd_parms *, void *, const char *);
 const char *modparrot_cmd_language(cmd_parms *, void *, const char *);
 const char *modparrot_cmd_load(cmd_parms *, void *, const char *);
 const char *modparrot_cmd_load_immediate(cmd_parms *, void *, const char *);

Modified: mod_parrot/trunk/include/modparrot_log.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_log.h	(original)
+++ mod_parrot/trunk/include/modparrot_log.h	Fri Jan 23 16:58:20 2009
@@ -18,6 +18,10 @@
 #ifndef _MODPARROT_LOG_H
 #define _MODPARROT_LOG_H
 
+#ifndef HAVE_LOCAL_DEBUG_LEVEL
+extern int modparrot_debug_level;
+#endif /* HAVE_LOCAL_DEBUG_LEVEL */
+
 #define MPLOG_WARN(s, msg) \
     ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "%s", msg)
 
@@ -42,4 +46,18 @@
 #define MPLOG_DEBUGF(s, fmt, msg) \
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, fmt, msg)
 
+#define MP_DEBUG_NONE 0
+#define MP_DEBUG_MODULE 1
+#define MP_DEBUG_CONTEXT 2
+#define MP_DEBUG_HOOK 4
+#define MP_DEBUG_PARROT 8
+#define MP_DEBUG_HLL 16
+
+#define MP_TRACE_h if (modparrot_debug_level & MP_DEBUG_HOOK) modparrot_trace
+#define MP_TRACE_c if (modparrot_debug_level & MP_DEBUG_CONTEXT) modparrot_trace
+#define MP_TRACE_p if (modparrot_debug_level & MP_DEBUG_PARROT) modparrot_trace
+#define MP_TRACE_m if (modparrot_debug_level & MP_DEBUG_MODULE) modparrot_trace
+
+void modparrot_trace(server_rec *, const char *, ...);
+
 #endif /* _MODPARROT_LOG_H */

Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c	(original)
+++ mod_parrot/trunk/src/mod_parrot.c	Fri Jan 23 16:58:20 2009
@@ -33,6 +33,7 @@
 #include "parrot/embed.h"
 #include "parrot/extend.h"
 
+#define HAVE_LOCAL_DEBUG_LEVEL 1
 #include "mod_parrot.h"
 #include "modparrot_config.h"
 #include "modparrot_log.h"
@@ -56,6 +57,20 @@
 /* thread info */
 int hard_thread_limit, max_threads;
 
+/* debug level */
+int modparrot_debug_level = 0;
+
+void modparrot_trace(server_rec *s, const char *fmt, ...)
+{
+    va_list ap;
+    char log[1000];
+
+    va_start(ap, fmt);
+    vsnprintf(log, sizeof(log), fmt, ap);
+    va_end(ap);
+    MPLOG_DEBUG(s, log);
+}
+
 void modparrot_load_file(Parrot_Interp interp, server_rec *s, const char *file)
 {
     int ret;
@@ -798,11 +813,18 @@
         "modparrot initialization file"
     ),
     AP_INIT_TAKE1(
+        "ParrotDebugLevel",
+        modparrot_cmd_debug,
+        NULL,
+        RSRC_CONF,
+        "set mod_parrot debugging level (default is 0)"
+    ),
+    AP_INIT_TAKE1(
         "ParrotTrace",
         modparrot_cmd_trace,
         NULL,
         RSRC_CONF,
-        "enable Parrot opcode tracing (default is off)"
+        "set Parrot opcode tracing level (default is 0)"
     ),
     AP_INIT_ITERATE(
         "ParrotLoad",

Modified: mod_parrot/trunk/src/modparrot_config.c
==============================================================================
--- mod_parrot/trunk/src/modparrot_config.c	(original)
+++ mod_parrot/trunk/src/modparrot_config.c	Fri Jan 23 16:58:20 2009
@@ -219,6 +219,18 @@
     return 1;
 }
 
+const char *modparrot_cmd_debug(cmd_parms *cmd, void *mconfig, const char *f)
+{
+    if (cmd->server->is_virtual) {
+        MPLOG_WARN(cmd->server, "WARNING: ignoring ParrotDebugLevel in VirtualHost");
+    }
+    else {
+        modparrot_debug_level = atoi(f);
+    }
+
+    return NULL;
+}
+
 const char *modparrot_cmd_trace(cmd_parms *cmd, void *mconfig, const char *f)
 {
     modparrot_srv_config *cfg;

Modified: mod_parrot/trunk/src/module.c
==============================================================================
--- mod_parrot/trunk/src/module.c	(original)
+++ mod_parrot/trunk/src/module.c	Fri Jan 23 16:58:20 2009
@@ -103,6 +103,7 @@
     }
 
     /* call merge routine */
+    MP_TRACE_m(our_server, "calling server_merge for module '%s'", modp->name);
     mergedcfg->cfg = Parrot_call_sub(ctxp->interp, minfo->server_merge_sub,
         "PPP", basecfg->cfg, newcfg->cfg);
 
@@ -152,6 +153,7 @@
     }
 
     /* call merge routine */
+    MP_TRACE_m(our_server, "calling dir_merge for module '%s'", modp->name);
     mergedcfg->cfg = Parrot_call_sub(ctxp->interp, minfo->dir_merge_sub,
         "PPP", basecfg->cfg, newcfg->cfg);
 
@@ -203,6 +205,10 @@
     modparrot_module_config *srvcfg, *dircfg;
     int ret;
 
+    MP_TRACE_m(cmd->server, \
+               "in modparrot_module_cmd_take123 for directive '%s'", \
+               cmd->directive->directive);
+
     /* mod_parrot specific stuff */
     ctxp = modparrot_startup(cmd->temp_pool, cmd->server, NULL);
     ctxp->pconf = cmd->pool;
@@ -218,6 +224,8 @@
         if (!srvcfg->cfg) {
             srvcfg->name = apr_pstrdup(cmd->pool, data->modp->name);
             if (minfo->server_create_sub) {
+                MP_TRACE_m(cmd->server, \
+                    "calling server_create for module '%s'", srvcfg->name);
                 srvcfg->cfg = Parrot_call_sub(ctxp->interp,
                     minfo->server_create_sub, "PP", parms_pmc);
                 if (!PMC_IS_NULL(srvcfg->cfg)) {
@@ -233,6 +241,8 @@
         if (!dircfg->cfg) {
             dircfg->name = apr_pstrdup(cmd->pool, data->modp->name);
             if (minfo->dir_create_sub) {
+                MP_TRACE_m(cmd->server, \
+                    "calling dir_create for module '%s'", srvcfg->name);
                 dircfg->cfg = Parrot_call_sub(ctxp->interp,
                     minfo->dir_create_sub, "PP", parms_pmc);
                 if (!PMC_IS_NULL(dircfg->cfg)) {
@@ -316,6 +326,8 @@
             pidx = (int *)apr_array_push(mpcfg->handler_modules[i]);
             *pidx = module_index;
 
+            MP_TRACE_m(our_server, "registering hook %d for module '%s'", i, modp->name);
+
             /* register this hook with apache */
             switch(i) {
                 case MP_HOOK_OPEN_LOGS:
@@ -413,6 +425,8 @@
     modparrot_context *ctxp = get_interp_ctx(interp);
     server_rec *s = ctxp->s;
 
+    MP_TRACE_m(s, "adding module '%s'", name);
+
     /* custom directives are optional */
     command_rec *cmds = NULL;
     if (PMC_IS_NULL(cmd_array)) {
@@ -504,6 +518,8 @@
         data->cmd_data = Parrot_PMC_get_pmc_keyed_str(interp, cmd,
                                         MAKE_PARROT_STRING("cmd_data"));
         cmds[i].cmd_data = data;
+
+    MP_TRACE_m(s, "registered directive '%s' for module '%s'", cmds[i].name, name);
     }
 
     modp->version       = MODULE_MAGIC_NUMBER_MAJOR;
@@ -540,18 +556,22 @@
     modp->dynamic_load_handle = minfo;
 
     if (sub = get_sub_pmc(interp, namespace, "server_create")) {
+        MP_TRACE_m(s, "registering server_create for module '%s'", name);
         modp->create_server_config = modparrot_module_srv_create;
         minfo->server_create_sub = sub;
     }
     if (sub = get_sub_pmc(interp, namespace, "server_merge")) {
+        MP_TRACE_m(s, "registering server_merge for module '%s'", name);
         modp->merge_server_config = modparrot_module_srv_merge;
         minfo->server_merge_sub = sub;
     }
     if (sub = get_sub_pmc(interp, namespace, "dir_create")) {
+        MP_TRACE_m(s, "registering dir_create for module '%s'", name);
         modp->create_dir_config = modparrot_module_dir_create;
         minfo->dir_create_sub = sub;
     }
     if (sub = get_sub_pmc(interp, namespace, "dir_merge")) {
+        MP_TRACE_m(s, "registering dir_merge for module '%s'", name);
         modp->merge_dir_config = modparrot_module_dir_merge;
         minfo->dir_merge_sub = sub;
     }
@@ -571,6 +591,8 @@
 
     ap_add_loaded_module(modp, p);
 
+    MP_TRACE_m(s, "registration complete for module '%s'", name);
+
     apr_pool_cleanup_register(p, modp, modparrot_remove_module,
                               apr_pool_cleanup_null);