debugger_mod.c

00001 
00025 #include <stdio.h>
00026 #include <unistd.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 
00030 #include "../../sr_module.h"
00031 #include "../../dprint.h"
00032 #include "../../ut.h"
00033 #include "../../mod_fix.h"
00034 #include "../../parser/parse_param.h"
00035 #include "../../shm_init.h"
00036 
00037 #include "debugger_api.h"
00038 
00039 MODULE_VERSION
00040 
00041 static int  mod_init(void);
00042 static int child_init(int rank);
00043 static void mod_destroy(void);
00044 
00045 static int w_dbg_breakpoint(struct sip_msg* msg, char* point, char* str2);
00046 static int fixup_dbg_breakpoint(void** param, int param_no);
00047 
00048 /* parameters */
00049 extern int _dbg_cfgtrace;
00050 extern int _dbg_breakpoint;
00051 extern int _dbg_cfgtrace_level;
00052 extern int _dbg_cfgtrace_facility;
00053 extern char *_dbg_cfgtrace_prefix;
00054 extern int _dbg_step_usleep;
00055 extern int _dbg_step_loops;
00056 
00057 static char * _dbg_cfgtrace_facility_str = 0;
00058 
00059 static cmd_export_t cmds[]={
00060         {"dbg_breakpoint", (cmd_function)w_dbg_breakpoint, 1,
00061                 fixup_dbg_breakpoint, 0, ANY_ROUTE},
00062         {0, 0, 0, 0, 0, 0}
00063 };
00064 
00065 static param_export_t params[]={
00066         {"cfgtrace",          INT_PARAM, &_dbg_cfgtrace},
00067         {"breakpoint",        INT_PARAM, &_dbg_breakpoint},
00068         {"log_level",         INT_PARAM, &_dbg_cfgtrace_level},
00069         {"log_facility",      STR_PARAM, &_dbg_cfgtrace_facility_str},
00070         {"log_prefix",        STR_PARAM, &_dbg_cfgtrace_prefix},
00071         {"step_usleep",       INT_PARAM, &_dbg_step_usleep},
00072         {"step_loops",        INT_PARAM, &_dbg_step_loops},
00073         {0, 0, 0}
00074 };
00075 
00076 struct module_exports exports = {
00077         "debugger",
00078         DEFAULT_DLFLAGS, /* dlopen flags */
00079         cmds,
00080         params,
00081         0,
00082         0,              /* exported MI functions */
00083         0,              /* exported pseudo-variables */
00084         0,              /* extra processes */
00085         mod_init,       /* module initialization function */
00086         0,              /* response function */
00087         mod_destroy,    /* destroy function */
00088         child_init      /* per child init function */
00089 };
00090 
00091 
00095 static int mod_init(void)
00096 {
00097         int fl;
00098         if (_dbg_cfgtrace_facility_str!=NULL)
00099         {
00100                 fl = str2facility(_dbg_cfgtrace_facility_str);
00101                 if (fl != -1)
00102                 {
00103                         _dbg_cfgtrace_facility = fl;
00104                 } else {
00105                         LM_ERR("invalid log facility configured");
00106                         return -1;
00107                 }
00108         }
00109 
00110         if(dbg_init_rpc()!=0)
00111         {
00112                 LM_ERR("failed to register RPC commands\n");
00113                 return -1;
00114         }
00115 
00116         return dbg_init_bp_list();
00117 }
00118 
00122 static int child_init(int rank)
00123 {
00124         LM_DBG("rank is (%d)\n", rank);
00125         if (rank==PROC_INIT)
00126                 return dbg_init_pid_list();
00127         return dbg_init_mypid();
00128 }
00129 
00133 static void mod_destroy(void)
00134 {
00135 }
00136 
00140 static int w_dbg_breakpoint(struct sip_msg* msg, char* point, char* str2)
00141 {
00142         return 1;
00143 }
00144 
00148 static struct action *dbg_fixup_get_action(void **param, int param_no)
00149 {
00150         struct action *ac, ac2;
00151         action_u_t *au, au2;
00152         /* param points to au->u.string, get pointer to au */
00153         au = (void*) ((char *)param - ((char *)&au2.u.string-(char *)&au2));
00154         au = au - 1 - param_no;
00155         ac = (void*) ((char *)au - ((char *)&ac2.val-(char *)&ac2));
00156         return ac;
00157 }
00158 
00159 
00163 static int fixup_dbg_breakpoint(void** param, int param_no)
00164 {
00165         struct action *a;
00166         char *p;
00167 
00168         if(param_no!=1)
00169                 return -1;
00170         a = dbg_fixup_get_action(param, param_no);
00171         p = (char*)(*param);
00172 
00173     return dbg_add_breakpoint(a, (*p=='0')?0:1);
00174 }
00175 
00176