⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mal_debugger.mx

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 MX
📖 第 1 页 / 共 4 页
字号:
				skipBlanc(cntxt, b);				if( strncmp("flow",b,1) == 0)					cntxt->flags |= flowFlag;				if( strncmp("memory",b,1) == 0){					struct mallinfo memory;					cntxt->flags |= memoryFlag;					memory = MT_mallinfo();					stream_printf(out,"arena %d ordblks %d smblks %d "						" hblkhd %d hblks %d fsmblks %d uordblks %d\n",						memory.arena,						memory.ordblks,						memory.smblks,						memory.hblkhd,						memory.hblks,						memory.fsmblks,						memory.uordblks					);				}				if (strncmp("timer", b, 1) == 0) {					cntxt->flags |= timerFlag;					cntxt->timer = GDKusec();					stk->cmd = 0;				}				if (strncmp("io", b, 1) == 0) {#ifdef HAVE_SYS_RESOURCE_H					struct  rusage resource;        #endif					cntxt->flags |=ioFlag ;#ifdef HAVE_SYS_RESOURCE_H					getrusage(RUSAGE_SELF, &resource);					stream_printf(out, "#maxrss %d ixrss=%d idrss=%d isrss=%d" 									" minflt=%d majflt=%d nswap=%d inblock=%d oublock=%d\n", 									resource.ru_maxrss, resource.ru_ixrss, 									resource.ru_idrss, resource.ru_isrss,									resource.ru_minflt, resource.ru_majflt, 									resource.ru_nswap, resource.ru_inblock, 									resource.ru_oublock);#endif				}				continue;			}			stk->cmd = *b;			m = 0;			break;		case 'm':	/* display a module */		{			str modname, fcnname;			Module fsym;			Symbol fs;			int i;			skipWord(cntxt, b);			skipBlanc(cntxt,b);			if (*b) {				modname = b;				fcnname = strchr(b, '.');				if (fcnname) {					*fcnname = 0;					fcnname++;				}				fsym = findModule(cntxt->nspace, putName(modname, strlen(modname)));				if (fsym == cntxt->nspace && strcmp(modname,"user") ) {					stream_printf(out, "module '%s' not found\n", modname);					continue;				}				for (i = 0; i < MAXSCOPE; i++) {					fs = fsym->subscope[i];					while (fs != NULL) {						if (fcnname == NULL)							printSignature(out, fs, 0);						else if (strcmp(fcnname, getFcnName(fs->def)) == 0)							printSignature(out, fs, 0);						fs = fs->peer;					}				}				continue;			} else				showModules(out, cntxt->nspace);		}			break;		case 'T':	/* debug type resolver for a function call */			if (strncmp("Trace", b, 5) == 0) {				char *w;				skipWord(cntxt, b);				skipBlanc(cntxt, b);				if ( (w =strchr(b, '\n')) )					*w = 0;				traceFcnName = GDKstrdup(b);			}			break;		case 't':	/* trace a variable toggle */			if (strncmp("trace", b, 5) == 0) {				char *w;				skipWord(cntxt, b);				skipBlanc(cntxt, b);				if ( (w= strchr(b, '\n')) )					*w = 0;				mdbSetBreakRequest(cntxt, mb, b, 't');			} 			break;		case 'v':	/* show the symbol table and bindings */		case 'V':{			str modname, fcnname;			Module fsym;			Symbol fs;			int i, lifespan = *b== 'V';			skipWord(cntxt, b);			if (*b != 0) {				modname = b;				fcnname = strchr(b, '.');				if (fcnname == NULL) {					fsym = findModule(cntxt->nspace, putName(modname, strlen(modname)));					if (fsym == 0) {						stream_printf(out, "%s module not found\n", modname);						continue;					}					for (i = 0; i < MAXSCOPE; i++) {						fs = fsym->subscope[i];						while (fs != NULL) {							printStack(out, fs->def, 0, lifespan);							fs = fs->peer;						}					}					continue;				}				*fcnname = 0;				fcnname++;				fsym = findModule(cntxt->nspace, putName(modname, strlen(modname)));				if (fsym == 0) {					stream_printf(out, "%s module not found\n", modname);					continue;				}				/* display the overloaded symbol definition */				for (i = 0; i < MAXSCOPE; i++) {					fs = fsym->subscope[i];					while (fs != NULL) {						if (strcmp(fs->name, fcnname) == 0)							printStack(out, fs->def, 0,lifespan);						fs = fs->peer;					}				}			} else				printStack(out, mb, stk,lifespan);			break;		}		case 'b':			if (strncmp(b, "bbp",3) == 0) {				int i,limit;				skipWord(cntxt, b);				i = BBPindex(b);				if( i)					limit=i+1;				else {					limit= BBPsize;					i=1;				}				/* the 'dense' qualification only shows entries with a hard ref */				for (; i < limit; i++)					if (BBP_logical(i) && BBP_cache(i) ) {						if( *b=='d' && BBP_refs(i)==0) continue;						stream_printf(out, "[%d] %s lref = %d ref= %d ", 							i, BBP_logical(i), BBP_lrefs(i), BBP_refs(i));						stream_printf(out, " dirty=%d", BATdirty(BBP_cache(i)));						if( *BBP_logical(i) =='.')							stream_printf(out, " zombie ");						if( BBPstatus(i) & BBPLOADED)							stream_printf(out, " loaded ");						if( BBPstatus(i) & BBPSWAPPED)							stream_printf(out, " swapped ");						if( BBPstatus(i) & BBPTMP)							stream_printf(out, " tmp ");						if( BBPstatus(i) & BBPDELETED)							stream_printf(out, " deleted ");						if( BBPstatus(i) & BBPEXISTING)							stream_printf(out, " existing ");						if( BBPstatus(i) & BBPNEW)							stream_printf(out, " new ");						if( BBPstatus(i) & BBPPERSISTENT)							stream_printf(out, " persistent ");						stream_printf(out, "\n");					}				continue;			}			if (strncmp(b, "breakpoints",11) == 0) {				mdbShowBreakpoints(cntxt);				continue;			}			if (strncmp(b, "break", 5) == 0)				b += 4;			if (isspace((int) b[1])) {				skipWord(cntxt, b);				if (*b && !isspace((int) *b))					/* set breakpoints by name */					mdbSetBreakRequest(cntxt, mb, b, 's');				else					/* set breakpoint at current instruction */					mdbSetBreakpoint(cntxt, mb, pc, 's');				continue;			}			continue;		case 'd':			if( strncmp(b, "debug", 5) == 0){				skipWord(cntxt, b);				GDKdebug = atol(b);				stream_printf(out,"Set debug mask to %d\n",GDKdebug);				break;			}			if (strncmp(b, "down", 2) == 0 && stk->down != NULL) {				stream_printf(out, "%sgo down the stack\n", "#mdb ");				stk = stk->down;				mb = stk->blk;				break;			}			if( strncmp(b, "dot", 3) == 0){				/* produce the dot file for graphical display */				/* its argument is the optimizer level followed by filename*/				MalBlkPtr mdot;				char fname[2*PATHLENGTH]="";				char name[PATHLENGTH];				skipWord(cntxt, b);				skipBlanc(cntxt, b);				mdot= mdbLocateMalBlk(mb,b,out);				if( mdot == NULL)					mdot= mb;				/* optional file */				snprintf(name,PATHLENGTH,"/%s-%s.dot",					getModuleId(getInstrPtr(mdot,0)),					getFunctionId(getInstrPtr(mdot,0)));				if( *b == 0){					strcat(fname,name+1);				} else				if( cntxt->cwd && *b !='/'){					strcpy(fname,cntxt->cwd);					strcat(fname,name);				} else 					strcat(fname,name+1);				stream_printf(out,"#dot to %s\n",fname);				showFlowGraph(mdot,0,fname);				break;			}			skipWord(cntxt, b);			/* get rid of break point */			if (*b && !isspace((int) *b)) {				mdbClrBreakRequest(cntxt, b);			} else {				mdbClrBreakpoint(cntxt, pc);			}			continue;		case 'I':		case 'i':		{			int i;			char *t;			/* the user wants information about variables */			if( *b == 'I'){				skipWord(cntxt, b);				for(i=0; i< mb->vtop; i++)					printBatProperties(out, getVar(mb, i), stk->stk + i, b);				continue;			}			skipWord(cntxt, b);			t = b;			skipNonBlanc(cntxt, t);			*t = 0;			/* search the symbol */			i = findVariable(mb, b);			if (i < 0) {				stream_printf(out, "%s Symbol not found\n", "#mdb ");			} else {				printBatInfo(out, getVar(mb, i), stk->stk + i);			}			continue;		}		case 'P':		case 'p':		{			size_t size = 0, first = 0;			int i;			char *t;			char upper= *b;			skipWord(cntxt, b);			t = b;			skipNonBlanc(cntxt, t);			*t = 0;			/* you can identify a start and length */			t++;			skipBlanc(cntxt, t);			if (isdigit((int) *t)) {				size = atol(t);				skipWord(cntxt, t);				if (isdigit((int) *t))					first = atol(t);			}			if( upper == 'P'){				for( i= 0; i<mb->vtop; i++)				if (isaBatType(getVarType(mb,i)) )					printBATelm(out, i, size, first);				continue;			}			/* search the symbol */			i = findVariable(mb, b);			if (i < 0) {				i = BBPindex(b);				if (i != 0)					printBATelm(out, i, size, first);				else					stream_printf(out, "%s Symbol not found\n", "#mdb ");				continue;			}			printStackElm(out, mb, getVar(mb, i), stk->stk + i, i, size, first,0);			continue;		}		case 'S':			dumpNamespaceStatistics(out, 1);			break;		case 'u':			if( strncmp("unset",b,5)){				skipWord(cntxt, b);				skipBlanc(cntxt, b);				if( strncmp("flow",b,1) == 0)					cntxt->flags &= ~flowFlag;				if( strncmp("memory",b,1) == 0)					cntxt->flags &= ~memoryFlag;				if (strncmp("timer", b, 1) == 0)					cntxt->flags &= ~timerFlag;				if (strncmp("io", b, 1) == 0) 					cntxt->flags &= ~ioFlag;				continue;			}			if (stk->up == NULL)				break;			stream_printf(out, "%s go up the stack\n", "#mdb ");			stk = stk->up;			mb = stk->blk;			printCall(cntxt, mb, stk, pc);			continue;		case 'w':		{			MalStkPtr w;			MalBlkPtr mw = mb;			int pci = pc;	/*  how to find enclosing pc */			for (w = stk; w != NULL; w = w->up) {				mw = w->blk;				printCall(cntxt, mw, w, pci);				if (w->up)					pci = w->up->pcup;			}			continue;		}@-While debugging it should be possible to inspect the symboltable using the 'module.function' name. The default is to list allsignatures satisfying the pattern.@c		case 'L':		case 'l':	/* list the current MAL block or module */		{			Module fsym;			Symbol fs;			int i, lstng;			lstng= (*b == 'L' ? LIST_MAL_ALL : LIST_MAL_INSTR | LIST_MAL_PROPS);			skipWord(cntxt, b);			if (*b != 0) {				MalBlkPtr m= mdbLocateMalBlk(mb,b,out);				if( m == NULL && !strchr(b,'.') && 					!strchr(b,'[') && !isdigit((int)*b)){					/* optionally dump the complete module */					fsym = findModule(cntxt->nspace, putName(b, strlen(b)));					if (fsym == 0) {						stream_printf(out, "'%s' not found\n", b);						continue;					}					for (i = 0; i < MAXSCOPE; i++) {						fs = fsym->subscope[i];						while (fs != NULL) {							printFunction(out, fs->def, lstng);							fs = fs->peer;						}					}					continue;				}				printFunction(out, m, lstng);			} else 				printFunction(out, mb, lstng);			continue;		}		case 'o':		case 'O':	/* optimizer steps */		{			MalBlkPtr mdot=mb;			skipWord(cntxt, b);			skipBlanc(cntxt, b);			if (*b) {				mdot=mdbLocateMalBlk(mb,b,out);				if(mdot != NULL)					showMalBlkHistory(mdot);			} else				showMalBlkHistory(mb);			break;		}		case 'r':	/* reset program counter */			stream_printf(out, "%s restart with current stack\n", "#mdb ");			stk->cmd = 'r';			break;		default:			stream_printf(out, "%s debugger command expected\n", "#mdb ");			mdbHelp(out);		}	} while (m);	cntxt->prompt = oldprompt;	cntxt->promptlength = oldpromptlength;}static int mdbSessionActive;int mdbSession(){	return mdbSessionActive;}@-It may be relevant to trap against dangerous situations, suchas underlying types not being aligned with what is expectedat the MAL level. Since such tests can be quite expensiveit should be used with care.@cvoidmdbSanityCheck(Client cntxt, MalBlkPtr mb, MalStkPtr stk, int pc){	int i;	VarPtr n;	ValPtr v;	str nme,nmeOnStk;	(void) stk;	(void) pc;	(void) mb;	for (i=1; i < mb->vtop; i++){		n= getVar(mb,i);		v= stk->stk+i;		if (isaBatType(n->type) && v->val.ival) {			BAT *b;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -