📄 mdb.mx
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f mdb@a Martin Kersten@v 1@+ MAL debugger interfaceThis module provides access to the functionality offeredby the MonetDB debugger and interpreter status.It is primarilly used in interactive sessions to activatethe debugger at a given point. Furthermore, the instructionsprovide the necessary handle to generate informationfor post-mortum analysis.To enable ease of debugging and performance monitoring, the MAL interpretercomes with a hardwired gdb-like text-based debugger.A limited set of instructions can be included in the programs themselves,but beware that debugging has a global effect. Any concurrent userwill be affected by breakpoints being set.The prime scheme to inspect the MAL interpreter status is to usethe MAL debugger directly. However, in case of automatic exception handlingit helps to be able to obtain BAT versions of the critical information,such as stack frame table, stack trace,and the instruction(s) where an exception occurred.The inspection typically occurs in the exception handling part of theMAL block.Beware, a large class of internal errors can not easily captured this way.For example, bus-errors and segmentation faults lead to prematuretermination of the process. Similar, creation of the post-mortuminformation may fail due to an inconsistent state or insufficient resources.@malmodule mdb;pattern start():void address MDBstartcomment "Start interactive debugger";pattern stop():voidaddress MDBstopcomment "Stop the interactive debugger";pattern inspect(mod:str,fcn:str):voidaddress MDBinspectcomment "Run the debugger on a specific function";pattern setTrace(b:bit):voidaddress MDBsetTracecomment "Turn on/off tracing of current routine";pattern setCatch(b:bit):voidaddress MDBsetCatchcomment "Turn on/off catching exceptions";command setTimer(b:bit):voidaddress MDBsetTimercomment "Turn on/off performance timer for debugger";command setFlow(b:bit):voidaddress MDBsetFlowcomment "Turn on/off memory flow debugger";command setMemory(b:bit):voidaddress MDBsetMemorycomment "Turn on/off memory statistics tracing.";command setIO(b:bit):voidaddress MDBsetIOcomment "Turn on/off io statistics tracing";command getDebug():intaddress MDBgetDebugcomment "Get the kernel debugging bit-set.See the MonetDB configuration file for details";command setDebug(flg:int):intaddress MDBsetDebugcomment "Set the kernel debugging bit-set and return its previous value.See the MonetDB configuration file for details";command getException(s:str):straddress MDBgetExceptionVariablecomment "Extract the variable name from the exception message";command getReason(s:str):straddress MDBgetExceptionReasoncomment "Extract the reason from the exception message";command getContext(s:str):straddress MDBgetExceptionContextcomment "Extract the context string from the exception message";pattern list():void address MDBlistcomment "Dump the current routine on standard out.";pattern list(M:str,F:str):void address MDBlist3comment "Dump the routine M.F on standard out.";pattern List():void address MDBlistDetailcomment "Dump the current routine on standard out.";pattern List(M:str,F:str):void address MDBlist3Detailcomment "Dump the routine M.F on standard out.";pattern var():void address MDBvarcomment "Dump the symboltable of current routine on standard out.";pattern var(M:str,F:str):void address MDBvar3comment "Dump the symboltable of routine M.F on standard out.";pattern dot(M:str,F:str,s:str):void address MDBshowFlowGraphcomment "Dump the data flow of the function M.F in a format recognizable by the command 'dot' on the file s";pattern getStackDepth():int address MDBStkDepthcomment "Return the depth of the calling stack.";pattern getStackFrame(i:int):bat[:str,:str] address MDBgetStackFrameN;pattern getStackFrame():bat[:str,:str] address MDBgetStackFramecomment "Collect variable binding of current (n-th) stack frame.";pattern getStackTrace():bat[:void,:str]address MDBStkTrace;pattern getDefinition():bat[:void,:str] address MDBgetDefinitioncomment "Returns a string representation of the current function with typing information attached";@-@{@+ Implementation@include prelude.mx@h#ifdef _MDB_H#endif /* _MDB_H */@c#include "mal_config.h"#include "gdk.h"#include <stdarg.h>#include <time.h>#include "mal_resolve.h"#include "mal_client.h"#include "mal_exception.h"#include "mal_debugger.h"#include "mal_interpreter.h"#include "mal_namespace.h"#ifdef WIN32#ifndef LIBMDB#define mdb_export extern __declspec(dllimport)#else#define mdb_export extern __declspec(dllexport)#endif#else#define mdb_export extern#endifmdb_export str MDBstart(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBstop(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBinspect(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBsetTrace(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBgetDebug(int *ret);mdb_export str MDBsetDebug(int *ret, int *flg);mdb_export str MDBsetCatch(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBsetTimer(int *ret, bit *flag);mdb_export str MDBsetFlow(int *ret, bit *flag);mdb_export str MDBsetMemory(int *ret, bit *flag);mdb_export str MDBsetIO(int *ret, bit *flag);mdb_export str MDBgetExceptionVariable(str *ret, str *msg);mdb_export str MDBgetExceptionReason(str *ret, str *msg);mdb_export str MDBgetExceptionContext(str *ret, str *msg);mdb_export str MDBlist(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBshowFlowGraph(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBlist3(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBlistDetail(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBlist3Detail(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBvar(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBvar3(MalBlkPtr mb, MalStkPtr stk, InstrPtr p);mdb_export str MDBStkDepth(MalBlkPtr mb, MalStkPtr s, InstrPtr p);mdb_export str MDBgetStackFrameN(MalBlkPtr m, MalStkPtr s, InstrPtr p);mdb_export str MDBgetStackFrame(MalBlkPtr m, MalStkPtr s, InstrPtr p);mdb_export str MDBStkTrace(MalBlkPtr m, MalStkPtr s, InstrPtr p);mdb_export str MDBgetDefinition(MalBlkPtr m, MalStkPtr stk, InstrPtr p);@-The primary debugger controls@c#define MDBstatus(X) \ if( stk->cmd && X==0 ) \ stream_printf(cntxt->fdout,"#Monet Debugger off\n"); \ else if(stk->cmd==0 && X) \ stream_printf(cntxt->fdout,"#Monet Debugger on\n");strMDBtoggle(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ Client cntxt = MCgetClient(); int b = 0; (void) mb; /* still unused */ if (p->argc == 1) { /* Toggle */ stk->cmd = stk->cmd ? 0 : 's'; cntxt->itrace = cntxt->itrace ? 0 : 's'; if (stk->cmd) MDBdelay = 1; /* wait for real command */ if (stk->up) stk->up->cmd = 0; return MAL_SUCCEED; } if (p->argc > 1) { b = *(int *) getArgReference(stk, p, 1); } else b = stk->cmd; if (b) MDBdelay = 1; /* wait for real command */ MDBstatus(b); stk->cmd = b ? 'n' : 0; if (stk->up) stk->up->cmd = b ? 'n' : 0; cntxt->itrace = b ? 'n' : 0; return MAL_SUCCEED;}strMDBstart(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ Client cntxt = MCgetClient(); stk->cmd = 'n'; cntxt->itrace = 'n'; cntxt->debugOptimizer= TRUE; (void) mb; (void) p; return MAL_SUCCEED;}strMDBstop(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ Client cntxt = MCgetClient(); stk->cmd = 0; cntxt->itrace = 0; cntxt->debugOptimizer= FALSE; (void) mb; (void) p; return MAL_SUCCEED;}voidMDBtraceFlag(Client cntxt, MalStkPtr stk, int b){ if (b) { cntxt->timer = GDKusec(); stk->cmd = b; cntxt->itrace = b; } else { cntxt->timer = 0; stk->cmd = 0; cntxt->itrace = 0; }}strMDBsetTrace(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int b; (void) mb; /* still unused */ b = *(chr *) getArgReference(stk, p, 1); MDBtraceFlag(MCgetClient(), stk, (b? (int) 't':0)); return MAL_SUCCEED;}strMDBgetDebug(int *ret){ *ret = GDKdebug; return MAL_SUCCEED;}strMDBsetDebug(int *ret, int *flg){ *ret = GDKdebug; GDKdebug = *flg; return MAL_SUCCEED;}strMDBsetCatch(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){ int b; Client cntxt= MCgetClient(); (void) mb; /* still unused */ b = *(chr *) getArgReference(stk, p, 1); stk->cmd = cntxt->itrace = (b? (int) 'C':0); return MAL_SUCCEED;}strMDBsetTimer(int *ret, bit *flag){ Client cntxt = MCgetClient(); (void) ret; if( *flag) cntxt->flags |= timerFlag; else cntxt->flags &= ~timerFlag; cntxt->timer= GDKusec(); return MAL_SUCCEED;}strMDBsetFlow(int *ret, bit *flag){ Client cntxt = MCgetClient(); (void) ret; if( *flag) cntxt->flags |= flowFlag; else cntxt->flags &= ~flowFlag; return MAL_SUCCEED;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -