Browse Source

debugger: work on nicer output

- output of dbg command to print action name along with type, making it
  more user friendly and easy to understand
Daniel-Constantin Mierla 15 years ago
parent
commit
9a65f7d218
3 changed files with 264 additions and 8 deletions
  1. 139 0
      modules/debugger/debugger_act.c
  2. 34 0
      modules/debugger/debugger_act.h
  3. 91 8
      modules/debugger/debugger_api.c

+ 139 - 0
modules/debugger/debugger_act.c

@@ -0,0 +1,139 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "../../dprint.h"
+#include "../../sr_module.h"
+
+#include "debugger_act.h"
+
+typedef struct _dbg_action {
+	int type;
+	str name;
+} dbg_action_t;
+
+static str _dbg_action_special[] = {
+	str_init("unknown"),   /* 0 */
+	str_init("exit"),      /* 1 */
+	str_init("drop"),      /* 2 */
+	str_init("return"),    /* 3 */
+	{0, 0}
+};
+
+static dbg_action_t _dbg_action_list[] = {
+	{ FORWARD_T, str_init("forward") },
+	{ SEND_T, str_init("send") },
+	{ LOG_T, str_init("log") },
+	{ ERROR_T, str_init("error") },
+	{ ROUTE_T, str_init("route") },
+	{ EXEC_T, str_init("exec") },
+	{ SET_HOST_T, str_init("sethost") },
+	{ SET_HOSTPORT_T, str_init("sethostport") },
+	{ SET_USER_T, str_init("setuser") },
+	{ SET_USERPASS_T, str_init("setuserpass") },
+	{ SET_PORT_T, str_init("setport") },
+	{ SET_URI_T, str_init("seturi") },
+	{ SET_HOSTPORTTRANS_T, str_init("sethostporttrans") },
+	{ SET_HOSTALL_T, str_init("sethostall") },
+	{ SET_USERPHONE_T, str_init("setuserphone") },
+	{ IF_T, str_init("if") },
+	{ SWITCH_T, str_init("switch") },
+	{ BLOCK_T, str_init("block") },
+	{ EVAL_T, str_init("eval") },
+	{ SWITCH_JT_T, str_init("switch") },
+	{ SWITCH_COND_T, str_init("switch") },
+	{ MATCH_COND_T, str_init("case") },
+	{ WHILE_T, str_init("while") },
+	{ SETFLAG_T, str_init("setflag") },
+	{ RESETFLAG_T, str_init("resetflag") },
+	{ ISFLAGSET_T, str_init("isflagset") },
+	{ AVPFLAG_OPER_T, str_init("avpflag") },
+	{ LEN_GT_T, str_init("lengt") },
+	{ PREFIX_T, str_init("prefix") },
+	{ STRIP_T, str_init("strip") },
+	{ STRIP_TAIL_T, str_init("striptail") },
+	{ APPEND_BRANCH_T, str_init("append_branch") },
+	{ REVERT_URI_T, str_init("reverturi") },
+	{ FORWARD_TCP_T, str_init("forward_tcp") },
+	{ FORWARD_UDP_T, str_init("forward_udp") },
+	{ FORWARD_TLS_T, str_init("forward_tls") },
+	{ FORWARD_SCTP_T, str_init("forward_sctp") },
+	{ SEND_TCP_T, str_init("send_tcp") },
+	{ FORCE_RPORT_T, str_init("force_rport") },
+	{ ADD_LOCAL_RPORT_T, str_init("add_local_rport") },
+	{ SET_ADV_ADDR_T, str_init("set_adv_addr") },
+	{ SET_ADV_PORT_T, str_init("set_adv_port") },
+	{ FORCE_TCP_ALIAS_T, str_init("force_tcp_alias") },
+	{ LOAD_AVP_T, str_init("load_avp") },
+	{ AVP_TO_URI_T, str_init("avp_to_uri") },
+	{ FORCE_SEND_SOCKET_T, str_init("force_send_socket") },
+	{ ASSIGN_T, str_init("assign") },
+	{ ADD_T, str_init("add") },
+	{ UDP_MTU_TRY_PROTO_T, str_init("udp_mtu_try_proto") },
+	{ SET_FWD_NO_CONNECT_T, str_init("set_fwd_no_connect") },
+	{ SET_RPL_NO_CONNECT_T, str_init("set_rpl_no_connect") },
+	{ SET_FWD_CLOSE_T, str_init("set_fwd_close") },
+	{ SET_RPL_CLOSE_T, str_init("set_rpl_close") },
+	{ 0, {0, 0} }
+};
+
+str* dbg_get_action_name(struct action *a)
+{
+	int i;
+	static str aname;
+	cmd_export_common_t *cmd;
+
+	if(a==NULL)
+		return &_dbg_action_special[0];
+
+	switch(a->type) {
+		case DROP_T:
+			if(a->val[1].u.number&DROP_R_F)
+				return &_dbg_action_special[2];
+			if(a->val[1].u.number&RETURN_R_F)
+				return &_dbg_action_special[3];
+			return &_dbg_action_special[1];
+		case MODULE_T:
+		case MODULE3_T:
+		case MODULE4_T:
+		case MODULE5_T:
+		case MODULE6_T:
+		case MODULEX_T:
+			cmd = (cmd_export_common_t*)(a->val[0].u.data);
+			aname.s = cmd->name;
+			aname.len = strlen(aname.s);
+			return &aname;
+		default:
+			for(i=0; _dbg_action_list[i].type!=0; i++)
+			{
+				if(_dbg_action_list[i].type==a->type)
+					return &_dbg_action_list[i].name;
+			}
+	}
+
+	return &_dbg_action_special[0];
+}

+ 34 - 0
modules/debugger/debugger_act.h

@@ -0,0 +1,34 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+		       
+#ifndef _DEBUGGER_ACT_H_
+#define _DEBUGGER_ACT_H_
+
+#include "../../str.h"
+#include "../../route_struct.h"     
+
+str* dbg_get_action_name(struct action *a);
+
+#endif
+

+ 91 - 8
modules/debugger/debugger_api.c

@@ -36,6 +36,7 @@
 #include "../../route_struct.h"
 #include "../../route_struct.h"
 #include "../../mem/shm_mem.h"
 #include "../../mem/shm_mem.h"
 		       
 		       
+#include "debugger_act.h"
 #include "debugger_api.h"
 #include "debugger_api.h"
 
 
 #define DBG_CMD_SIZE 256
 #define DBG_CMD_SIZE 256
@@ -44,10 +45,53 @@
 #define DBG_STATE_WAIT	1
 #define DBG_STATE_WAIT	1
 #define DBG_STATE_NEXT	2
 #define DBG_STATE_NEXT	2
 
 
+static str _dbg_state_list[] = {
+	str_init("unknown"),
+	str_init("init"),
+	str_init("wait"),
+	str_init("next"),
+	{0, 0}
+};
+
+str *dbg_get_state_name(int t)
+{
+	switch(t) {
+		case DBG_STATE_INIT:
+			return &_dbg_state_list[1];
+		case DBG_STATE_WAIT:
+			return &_dbg_state_list[2];
+		case DBG_STATE_NEXT:
+			return &_dbg_state_list[3];
+	}
+	return &_dbg_state_list[0];
+}
+
 #define DBG_CFGTRACE_ON	(1<<0)
 #define DBG_CFGTRACE_ON	(1<<0)
 #define DBG_ABKPOINT_ON	(1<<1)
 #define DBG_ABKPOINT_ON	(1<<1)
 #define DBG_LBKPOINT_ON	(1<<2)
 #define DBG_LBKPOINT_ON	(1<<2)
 
 
+static str _dbg_status_list[] = {
+	str_init("cfgtrace-on"),
+	str_init("cfgtrace-off"),
+	str_init("abkpoint-on"),
+	str_init("abkpoint-off"),
+	str_init("lbkpoint-on"),
+	str_init("lbkpoint-off"),
+	{0, 0}
+};
+
+str *dbg_get_status_name(int t)
+{
+	if(t&DBG_CFGTRACE_ON)
+		return &_dbg_status_list[0];
+	if(t&DBG_ABKPOINT_ON)
+		return &_dbg_status_list[2];
+	if(t&DBG_LBKPOINT_ON)
+		return &_dbg_status_list[4];
+
+	return &_dbg_state_list[0];
+}
+
 #define DBG_CMD_NOP		0
 #define DBG_CMD_NOP		0
 #define DBG_CMD_ERR		1
 #define DBG_CMD_ERR		1
 #define DBG_CMD_READ	2
 #define DBG_CMD_READ	2
@@ -57,6 +101,42 @@
 #define DBG_CMD_PVEVAL	6
 #define DBG_CMD_PVEVAL	6
 #define DBG_CMD_PVLOG	7
 #define DBG_CMD_PVLOG	7
 
 
+
+static str _dbg_cmd_list[] = {
+	str_init("nop"),
+	str_init("err"),
+	str_init("read"),
+	str_init("next"),
+	str_init("move"),
+	str_init("show"),
+	str_init("pveval"),
+	str_init("pvlog"),
+	{0, 0}
+};
+
+str *dbg_get_cmd_name(int t)
+{
+	switch(t) {
+		case DBG_CMD_NOP:
+			return &_dbg_cmd_list[0];
+		case DBG_CMD_ERR:
+			return &_dbg_cmd_list[1];
+		case DBG_CMD_READ:
+			return &_dbg_cmd_list[2];
+		case DBG_CMD_NEXT:
+			return &_dbg_cmd_list[3];
+		case DBG_CMD_MOVE:
+			return &_dbg_cmd_list[4];
+		case DBG_CMD_SHOW:
+			return &_dbg_cmd_list[5];
+		case DBG_CMD_PVEVAL:
+			return &_dbg_cmd_list[6];
+		case DBG_CMD_PVLOG:
+			return &_dbg_cmd_list[7];
+	}
+	return &_dbg_state_list[0];
+}
+
 /**
 /**
  *
  *
  */
  */
@@ -153,6 +233,7 @@ int dbg_cfg_trace(void *data)
 	pv_spec_t pvs;
 	pv_spec_t pvs;
     pv_value_t val;
     pv_value_t val;
 	void **srevp;
 	void **srevp;
+	str *an;
 
 
 	srevp = (void**)data;
 	srevp = (void**)data;
 
 
@@ -162,14 +243,16 @@ int dbg_cfg_trace(void *data)
 	if(a==NULL || msg==NULL)
 	if(a==NULL || msg==NULL)
 		return 0;
 		return 0;
 
 
+	an = dbg_get_action_name(a);
+
 	if(_dbg_pid_list[process_no].set&DBG_CFGTRACE_ON)
 	if(_dbg_pid_list[process_no].set&DBG_CFGTRACE_ON)
 	{
 	{
 		if(is_printable(_dbg_cfgtrace_level))
 		if(is_printable(_dbg_cfgtrace_level))
 		{
 		{
 			LOG_(_dbg_cfgtrace_facility, _dbg_cfgtrace_level,
 			LOG_(_dbg_cfgtrace_facility, _dbg_cfgtrace_level,
 					_dbg_cfgtrace_prefix,
 					_dbg_cfgtrace_prefix,
-					" c=[%s] l=%d a=%d\n",
-					a->cfile, a->cline, a->type
+					" c=[%s] l=%d a=%d n=%.*s\n",
+					a->cfile, a->cline, a->type, an->len, an->s
 				);
 				);
 		}
 		}
 	}
 	}
@@ -182,9 +265,9 @@ int dbg_cfg_trace(void *data)
 	if(_dbg_pid_list[process_no].state==DBG_STATE_INIT)
 	if(_dbg_pid_list[process_no].state==DBG_STATE_INIT)
 	{
 	{
 		LOG(_dbg_cfgtrace_level,
 		LOG(_dbg_cfgtrace_level,
-					"breakpoint hit: p=[%u] c=[%s] l=%d a=%d\n",
+					"breakpoint hit: p=[%u] c=[%s] l=%d a=%d n=%.*s\n",
 					_dbg_pid_list[process_no].pid,
 					_dbg_pid_list[process_no].pid,
-					a->cfile, a->cline, a->type
+					a->cfile, a->cline, a->type, an->len, an->s
 				);
 				);
 		_dbg_pid_list[process_no].in.cmd = DBG_CMD_NOP;
 		_dbg_pid_list[process_no].in.cmd = DBG_CMD_NOP;
 		_dbg_pid_list[process_no].state = DBG_STATE_WAIT;
 		_dbg_pid_list[process_no].state = DBG_STATE_WAIT;
@@ -211,8 +294,8 @@ int dbg_cfg_trace(void *data)
 				_dbg_pid_list[process_no].in.cmd = DBG_CMD_NOP;
 				_dbg_pid_list[process_no].in.cmd = DBG_CMD_NOP;
 				olen = snprintf(_dbg_pid_list[process_no].out.buf,
 				olen = snprintf(_dbg_pid_list[process_no].out.buf,
 						DBG_CMD_SIZE,
 						DBG_CMD_SIZE,
-						"exec [%s:%d] a=%d",
-						a->cfile, a->cline, a->type);
+						"exec [%s:%d] a=%d n=%.*s",
+						a->cfile, a->cline, a->type, an->len, an->s);
 				if(olen<0)
 				if(olen<0)
 				{
 				{
 					_dbg_pid_list[process_no].out.cmd = DBG_CMD_ERR;
 					_dbg_pid_list[process_no].out.cmd = DBG_CMD_ERR;
@@ -312,8 +395,8 @@ int dbg_cfg_trace(void *data)
 				_dbg_pid_list[process_no].out.cmd = DBG_CMD_NOP;
 				_dbg_pid_list[process_no].out.cmd = DBG_CMD_NOP;
 				olen = snprintf(_dbg_pid_list[process_no].out.buf,
 				olen = snprintf(_dbg_pid_list[process_no].out.buf,
 						DBG_CMD_SIZE,
 						DBG_CMD_SIZE,
-						"at bkp [%s:%d] a=%d",
-						a->cfile, a->cline, a->type);
+						"at bkp [%s:%d] a=%d n=%.*s",
+						a->cfile, a->cline, a->type, an->len, an->s);
 				if(olen<0)
 				if(olen<0)
 				{
 				{
 					_dbg_pid_list[process_no].out.cmd = DBG_CMD_ERR;
 					_dbg_pid_list[process_no].out.cmd = DBG_CMD_ERR;