"Fossies" - the Fresh Open Source Software Archive

Member "dbg-2.15.5/dbg_net.h" (28 Apr 2007, 14578 Bytes) of package /linux/www/old/dbg-2.15.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dbg_net.h" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           dbg_net.h  -  description
    3                              -------------------
    4     begin                : Sun Sep 24 2000
    5     copyright            : (C) 2001 by Dmitri Dmitrienko
    6                          : (C) 2002, 2007 NuSphere Corp.
    7     www                  : http://dd.cron.ru
    8                          : http://www.nusphere.com/
    9     author               : written by Dmitri Dmitrienko
   10     license              : This source file is subject to version 3.0 of 
   11                            the License,  that is bundled with this package 
   12                            in the file LICENSE, and is available at through 
   13                            the world-wide-web at http://www.nusphere.com/dbg
   14  ***************************************************************************/
   15 
   16 #ifndef _DBG_NET_H_
   17 #define _DBG_NET_H_
   18 
   19 #if PHP_WIN32 || defined WIN32
   20 #include <windows.h>
   21 #include <windef.h>
   22 /* on Win32 int is always 32bit */
   23 #define int_32t int
   24 #define int_64t __int64
   25 #endif
   26 
   27 #ifndef int_32t
   28 #if SIZEOF_INT == 4
   29 # define int_32t int
   30 #elif SIZEOF_LONG == 4
   31 # define int_32t long
   32 #elif SIZEOF_SHORT == 4
   33 # define int_32t short
   34 #endif
   35 #endif
   36 
   37 #ifndef int_64t
   38 #if SIZEOF_LONG_LONG == 8
   39 # define int_64t long long
   40 #elif SIZEOF_OFF64_T == 8
   41 # define int_64t off64_t
   42 #elif SIZEOF_OFF_T == 8
   43 # define int_64t off_t
   44 #elif SIZEOF_INT == 8
   45 # define int_64t int
   46 #elif SIZEOF_LONG == 8
   47 # define int_64t long
   48 #elif SIZEOF_SHORT == 8
   49 # define int_64t short
   50 #endif
   51 #endif
   52 
   53 
   54 #ifndef int_32t
   55 #error "could not compile without knowing a native type of 32bit integer for this platform (int_32t)"
   56 #endif
   57 #ifndef int_64t
   58 #error "could not compile without knowing a native type of 64bit integer for this platform (int_64t)"
   59 #endif
   60 
   61 #define DBG_API_MAJOR_VERSION           0x02
   62 #define DBG_API_MINOR_VERSION           0x15
   63 #define DBG_API_RELEASE_STAGE           0x3   /* 0-dev, 1-beta, 2-prerelease, 3-release */
   64 #define DBG_API_MINOR_SUB_VERSION       0x5
   65 
   66 #define DBG_API_MAJOR_VERSION_STR       "2"
   67 #define DBG_API_MINOR_VERSION_STR       "15"
   68 #define DBG_API_RELEASE_STAGE_STR       ""
   69 #define DBG_API_MINOR_SUB_VERSION_STR   ".5"
   70 
   71 #define DBG_API_MAJOR_VERSION_STR_L     L"2"
   72 #define DBG_API_MINOR_VERSION_STR_L     L"15"
   73 #define DBG_API_RELEASE_STAGE_STR_L     L""
   74 #define DBG_API_MINOR_SUB_VERSION_STR_L L".5"
   75 
   76 
   77 #define DBG_API_FULL_VERSION (DBG_API_MAJOR_VERSION << 8 | DBG_API_MINOR_VERSION)
   78 #define DBG_API_FULL_VERSION_STR DBG_API_MAJOR_VERSION_STR "." DBG_API_MINOR_VERSION_STR DBG_API_RELEASE_STAGE_STR DBG_API_MINOR_SUB_VERSION_STR
   79 #define DBG_API_FULL_VERSION_STR_L DBG_API_MAJOR_VERSION_STR_L L"." DBG_API_MINOR_VERSION_STR_L DBG_API_RELEASE_STAGE_STR_L DBG_API_MINOR_SUB_VERSION_STR_L
   80 
   81 #define DBG_PROD_NAME            "DBG php debugger"
   82 #define DBG_PROD_NAME_L         L"DBG php debugger"
   83 #define DBG_API_DESCRIPTION     DBG_PROD_NAME    ", version " DBG_API_FULL_VERSION_STR    ", Copyright 2001, 2007, Dmitri Dmitrienko, www.nusphere.com"
   84 #define DBG_API_DESCRIPTION_L   DBG_PROD_NAME_L L", version " DBG_API_FULL_VERSION_STR_L L", Copyright 2001, 2007, Dmitri Dmitrienko, www.nusphere.com"
   85 
   86 #define DEFAULT_PORT 7869
   87 #define DEFAULT_PORT_STR "7869"
   88 
   89 #define DBGSESSVAR "DBGSESSID"
   90 
   91 typedef enum tagSESSTYPE {
   92     DBG_COMPAT      = 0x0001,
   93     DBG_JIT         = 0x0002,
   94     DBG_REQ         = 0x0003,
   95     DBG_EMB         = 0x0004,
   96 } SESSTYPE;
   97 
   98 
   99 #define dbgint int_32t  /* this must be 32-bit signed integer only! */
  100 #define dbgint64 int_64t /* this must be 64-bit signed integer only! */
  101 
  102 #ifdef HAVE_SOCKLEN_T
  103     #define NET_SIZE_T socklen_t
  104 #else
  105     #if defined(AIX) && (AIX >= 42)
  106     #define NET_SIZE_T size_t
  107     #endif
  108 
  109     #if defined(SEQUENT) && (SEQUENT >= 44)
  110     #define NET_SIZE_T size_t
  111     #endif
  112 
  113     #if defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 0))
  114     #define NET_SIZE_T socklen_t
  115     #endif
  116     #if (defined(__FreeBSD_version) && (__FreeBSD_version >= 400000))
  117     #define NET_SIZE_T socklen_t
  118     #endif
  119 
  120     #if defined(SVR4) || defined(UW) || defined(OS390)
  121     #define NET_SIZE_T size_t
  122     #endif
  123 #endif
  124 
  125 #ifndef NET_SIZE_T
  126 #define NET_SIZE_T int
  127 #endif
  128 
  129 #if PHP_WIN32 || defined WIN32
  130   #ifdef DBG_EXPORTS
  131     #define DBGAPI __declspec(dllexport)
  132   #else
  133     #ifdef DBG_IMPORTS
  134       #define DBGAPI __declspec(dllimport)
  135     #endif
  136   #endif
  137 #endif
  138 
  139 #ifndef DBGAPI
  140   #define DBGAPI
  141 #endif
  142 
  143 #ifndef MAXINT32T
  144 #define MAXINT32T (0x7FFFFFFF)
  145 #endif
  146 
  147 
  148 #if PHP_WIN32 || defined WIN32
  149   #define SCLOSE(a) closesocket(a)
  150 #else
  151   #define SCLOSE(a) close(a)
  152 #endif
  153 
  154 #define SSEND(a,b,c) send(a,b,c,0)
  155 #define SREAD(a,b,c) recv(a,b,c,0)
  156 
  157 #if (PHP_WIN32 || defined WIN32) && !defined(vsnprintf)
  158   #define vsnprintf _vsnprintf
  159 #endif
  160 
  161 
  162 /*********** C O M M A N D   I N T E R F A C E ******************************************/
  163 
  164 
  165 /* debugger_flags */
  166 /* state: */
  167 #define DBGF_STARTED        0x0001      /* debugger has been started */
  168 #define DBGF_FINISHED       0x0002      /* DBGC_END notification has been sent */       
  169 #define DBGF_WAITACK        0x0004      /* awaiting replay|request */
  170 #define DBGF_UNSYNC         0x0008      /* protocol has been unsynchronized */
  171 #define DBGF_REQUESTPENDING 0x0010      /* Debug session request pending */
  172 #define DBGF_REQUESTFOUND   0x0020      /* Debug session request found */
  173 #define DBGF_REJECTIONFOUND 0x0040      /* DBGSESSID=-1 found - session rejection */
  174 /* execution:  */
  175 #define DBGF_STEPINTO       0x0100      /* break on next script instruction */
  176 #define DBGF_STEPOVER       0x0200      /* break on next script instruction on the same context */
  177 #define DBGF_STEPOUT        0x0400      /* break on next script instruction on the outer context */
  178 #define DBGF_ABORT          0x0800      /* stop instruction passed */
  179 
  180 /* standard header */
  181 /*  WARNING! All numbers are in TCP/IP network byte order (which is big-endian) */
  182 #define DBG_SYNC            0x00005953
  183 #define MAX_PACKET_SIZE     10*1024*1024        /* size of packet would never exceed 1M */
  184 #define CHUNKSIZE           128*1024            /* data is transmitted by relatively small portions which size is CHUNKSIZE */
  185 
  186 typedef struct {
  187     dbgint sync;
  188     dbgint cmd;                 /* command one of DBGC_xxxx, DBGR_xxxx, DBGA_xxxx */
  189     dbgint flags;               /* combination of DBGF_xxxx */
  190     dbgint bodysize;            /* size of the rest packet body (pack of all frames) */
  191 } dbg_header_struct;
  192 
  193 typedef int framename;
  194 
  195 /* packet frame structure. All packets must have a header, 
  196   also they may have a body that consists of one ore more frames packed all together */
  197 
  198 typedef struct {
  199     framename name;
  200     dbgint size;                /* size of pure data */
  201 } dbg_frame;
  202 
  203 #define FRAME_DATA_PTR(type,frame) ((type*)((char*)frame+sizeof(dbg_frame)))
  204 
  205 /*
  206   PHP ENGINE to DEBUGGER CLIENT WAY:
  207 */
  208 
  209 /* php-engine commands/events */
  210 #define DBGC_REPLY          0x0000      /* reply to previous DBGA_REQUEST request */
  211 #define DBGC_STARTUP        0x0001      /* script startup */
  212 #define DBGC_END            0x0002      /* script done */
  213 #define DBGC_BREAKPOINT     0x0003      /* user definded breakpoint occured */
  214 #define DBGC_STEPINTO_DONE  0x0004      /* step to the next statement is completed */
  215 #define DBGC_STEPOVER_DONE  0x0005      /* step to the next statement is completed */
  216 #define DBGC_STEPOUT_DONE   0x0006      /* step to the next statement is completed */
  217 #define DBGC_EMBEDDED_BREAK 0x0007      /* breakpoint caused by DebugBreak() function */
  218 #define DBGC_ERROR          0x0010      /* error occured */
  219 #define DBGC_LOG            0x0011      /* logging support */
  220 #define DBGC_SID            0x0012      /* send SID */
  221 #define DBGC_PAUSE          0x0013      /* pause current session as soon as possible */
  222 
  223 #define FRAME_STACK         100000      /* "call:stack" - e.g. backtrace */
  224 #define FRAME_SOURCE        100100      /* source text */
  225 #define FRAME_SRC_TREE      100200      /* tree of source files */
  226 #define FRAME_RAWDATA       100300      /* raw data or string */
  227 #define FRAME_ERROR         100400      /* error notification */
  228 #define FRAME_EVAL          100500      /* evaluating/watching */
  229 #define FRAME_BPS           100600      /* set/remove breakpoint */
  230 #define FRAME_BPL           100700      /* breakpoint(s) request = get the list */
  231 #define FRAME_VER           100800      /* version request */
  232 #define FRAME_SID           100900      /* session id info*/
  233 #define FRAME_SRCLINESINFO  101000      /* source lines info */
  234 #define FRAME_SRCCTXINFO    101100      /* source contexts info */
  235 #define FRAME_LOG           101200      /* logging */
  236 #define FRAME_PROF          101300      /* profiler */
  237 #define FRAME_PROF_C        101400      /* profiler counter/accuracy */
  238 #define FRAME_SET_OPT       101500      /* set/update options */
  239 
  240 
  241 
  242 #define CURLOC_SCOPE_ID 1       /* nested locations are 2,3... and so on in backward order, so 2 represents most out-standing stack context*/
  243 #define GLOBAL_SCOPE_ID -1      /* it is global context, not stacked */
  244 
  245 /* responces: */
  246 
  247 typedef struct tag_dbg_version_body {           /*FRAME_VER*/
  248     dbgint major_version;
  249     dbgint minor_version;
  250     dbgint idescription;
  251 } dbg_version_body;
  252 
  253 typedef struct tag_dbg_sid_body {               /*FRAME_SID*/
  254     dbgint isid;                /* session ID */
  255     dbgint sesstype;
  256 } dbg_sid_body;
  257 
  258 typedef struct tag_dbg_stack_body {             /* FRAME_STACK */
  259     dbgint line_no;
  260     dbgint mod_no;
  261     dbgint scope_id;            /*-1 means current location, 0 never used, +1 first depth*/
  262     dbgint idescr;              /*ID of description string*/
  263 } dbg_stack_body;
  264 
  265 typedef struct tag_dbg_source_body {            /*FRAME_SOURCE*/
  266     dbgint mod_no;      
  267     dbgint from_filepos;        /* file offset */
  268     dbgint error;               /* 0 = ok */    
  269     dbgint full_size;
  270     dbgint imod_name;           /* ID of mod_name string */
  271     dbgint itext;               /* ID of text rawdata */
  272 } dbg_source_body;
  273 
  274 typedef struct tag_dbg_src_tree_body {          /* FRAME_SRC_TREE */
  275     dbgint rsrv1;
  276     dbgint rsrv2;       /* NOT USED */
  277     dbgint mod_no;
  278     dbgint imod_name;
  279 } dbg_src_tree_body;
  280 
  281 typedef struct tag_dbg_rawdata_body {           /* FRAME_RAWDATA */
  282     dbgint rawid;
  283     dbgint datasize;
  284 } dbg_rawdata_body;
  285 
  286 typedef struct tag_dbg_error_body {             /* FRAME_ERROR */
  287     dbgint type;                /* type of error */
  288     dbgint imessage;            /* ID of error message */
  289 } dbg_error_body;
  290 
  291 typedef struct tag_dbg_eval_body {              /*FRAME_EVAL*/
  292     dbgint istr;
  293     dbgint iresult; 
  294     dbgint ierror;  
  295 } dbg_eval_body;
  296 
  297 typedef struct tag_dbg_bpl_body {               /* FRAME_BPL */
  298     dbgint mod_no;
  299     dbgint line_no;
  300     dbgint imod_name;
  301     dbgint state;                   
  302     dbgint istemp;
  303     dbgint hitcount;
  304     dbgint skiphits;
  305     dbgint icondition;
  306     dbgint bp_no;
  307     dbgint isunderhit;
  308 } dbg_bpl_body;
  309 
  310 typedef struct tag_dbg_srclinesinfo_body {      /* FRAME_SRCLINESINFO */
  311     dbgint mod_no;
  312     dbgint start_line_no;
  313     dbgint lines_count;
  314     dbgint ctx_id;
  315 } dbg_srclinesinfo_body;
  316 
  317 typedef struct tag_dbg_srcctxinfo_body {        /* FRAME_SRCCTXINFO */
  318     dbgint mod_no;
  319     dbgint ctx_id;
  320     dbgint ifunction_name;
  321 } dbg_srcctxinfo_body;
  322 
  323 typedef struct tag_dbg_log_body {               /* FRAME_LOG */
  324     dbgint ilog;
  325     dbgint type;
  326     dbgint mod_no;
  327     dbgint line_no;
  328     dbgint imod_name;
  329     dbgint ext_info;
  330 } dbg_log_body;
  331 
  332 typedef struct tag_dbg_prof_body {              /* FRAME_PROF */
  333     dbgint mod_no;
  334     dbgint line_no;
  335     dbgint hit_count;
  336     dbgint tm_min_lo;
  337     dbgint tm_min_hi;
  338     dbgint tm_max_lo;
  339     dbgint tm_max_hi;
  340     dbgint tm_sum_lo;
  341     dbgint tm_sum_hi;
  342 } dbg_prof_body;
  343 
  344 typedef struct tag_dbg_prof_c_body {            /* FRAME_PROF_C */
  345     dbgint tm_freq_lo;
  346     dbgint tm_freq_hi;
  347     dbgint tm_diff_min;
  348     dbgint tm_diff_max;
  349     dbgint tm_diff_m;
  350 } dbg_prof_c_body;
  351 
  352 
  353 
  354 /* requests: */
  355 
  356 
  357 typedef struct tag_dbg_source_request {         /*FRAME_SOURCE*/
  358     dbgint mod_no;
  359     dbgint from_filepos;        /* file offset */
  360 } dbg_source_request;
  361 
  362 /* FRAME_STACK, FRAME_VER and FRAME_SRC_TREE must be requested without any additional parameters (by frame name)*/
  363 /* FRAME_ERROR can not be rerequested at all */
  364 
  365 typedef struct tag_dbg_bpl_request {            /* FRAME_BPL */
  366     dbgint bp_no;
  367 } dbg_bpl_request;
  368 
  369 typedef struct tag_dbg_eval_request {           /* FRAME_EVAL */
  370     dbgint istr;
  371     dbgint scope_id;
  372 } dbg_eval_request;
  373 
  374 typedef struct tag_dbg_bpl_body dbg_bps_request;/* FRAME_BPS */
  375 
  376 typedef struct tag_dbg_srclinesinfo_request {   /* FRAME_SRCLINESINFO */
  377     dbgint mod_no;
  378 } dbg_srclinesinfo_request;
  379 
  380 typedef struct tag_dbg_srcctxinfo_request {     /* FRAME_SRCCTXINFO */
  381     dbgint mod_no;
  382 } dbg_srcctxinfo_request;
  383 
  384 typedef struct tag_dbg_prof_request {           /* FRAME_PROF */
  385     dbgint mod_no;
  386 } dbg_prof_request;
  387 
  388 typedef struct tag_dbg_prof_c_request {         /* FRAME_PROF_C */
  389     dbgint test_loops;
  390 } dbg_prof_c_request;
  391 
  392 typedef struct tag_dbg_set_options_request {    /* FRAME_SET_OPT */
  393     dbgint opt_flags;           /* OF_xxxx */
  394 } dbg_set_options_request;
  395 
  396 /*
  397   DEBUGGER CLIENT to DBG SERVER WAY:
  398 */
  399 
  400 /* debugger client makes acknowledgement */
  401 #define DBGA_CONTINUE       0x8001      /* php should continue run */
  402 #define DBGA_STOP           0x8002
  403 #define DBGA_STEPINTO       0x8003
  404 #define DBGA_STEPOVER       0x8004
  405 #define DBGA_STEPOUT        0x8005
  406 #define DBGA_IGNORE         0x8006
  407 #define DBGA_REQUEST        0x8010      /* debugger client requests some information from PHP engine */
  408 
  409 
  410 /*********** S O F T W A R E   I N T E R F A C E ******************************************/
  411 
  412 
  413 /* buffer to hold frames */
  414 typedef struct {
  415     dbg_frame *buf;
  416     int limit;  /* size of buffer in memory */
  417     int size;   /* actual data size in the buffer */
  418     int lastrawid;
  419 } dbg_packet;
  420 
  421 /* Let packet buffer grows by 128byte-inctrements. 
  422    It reduces reallocation frequency if we add a lot of small frames to one packet. */
  423 
  424 #define PACKET_LIMIT_ROUND(s) \
  425     ((s+127) & ~127) /* round to nearest upper value 128*n */
  426 
  427 #define ALIGN8(s) \
  428     ((s+7) & ~7) /* round to nearest upper value 8*n */
  429 
  430 #ifdef __cplusplus
  431 extern "C"{
  432 #endif
  433 
  434 DBGAPI int dbg_packet_new(dbg_packet *pack);
  435 DBGAPI void dbg_packet_free(dbg_packet *pack);
  436 DBGAPI void dbg_packet_clear(dbg_packet *pack);
  437 DBGAPI int dbg_packet_add_frame(dbg_packet *pack, framename frname, void *data, int datasize);
  438 DBGAPI int dbg_packet_add_rawdata(dbg_packet *pack, const char *data, int datasize);
  439 DBGAPI int dbg_packet_add_stringlen(dbg_packet *pack, const char *str, int len);
  440 
  441 DBGAPI dbg_frame* dbg_packet_firstframe(dbg_packet *pack);
  442 DBGAPI dbg_frame* dbg_packet_nextframe(dbg_packet *pack, dbg_frame *frame);
  443 DBGAPI dbg_frame* dbg_packet_findfirstframe(dbg_packet *pack, framename frname);
  444 DBGAPI dbg_frame* dbg_packet_findnextframe(dbg_packet *pack, framename frname, dbg_frame *frame);
  445 DBGAPI int dbg_packet_findrawdata(dbg_packet *pack, int rawid, char **data, int *datasize);
  446 
  447 DBGAPI int dbg_packet_recv(dbg_header_struct *hdr, dbg_packet *pack, int socket, int timeoutsec);
  448 DBGAPI int dbg_packet_send(int cmd , dbg_packet *pack, int socket, int flags);
  449 
  450 #define dbg_packet_findstring(pack,rawid,data,datasize) dbg_packet_findrawdata(pack,rawid,data,datasize)
  451 #define dbg_packet_add_string(pack,str) ((str) ? (dbg_packet_add_stringlen(pack,str,strlen(str))) : 0)
  452 
  453 
  454 /*** TRACING/DEBUGGING ***/
  455 
  456 void SysError(const char *msg,...);
  457 #define SON(s) ((s) ? (s) : ("(null)"))
  458 
  459 #ifdef DBG_DEBUG
  460 void _dbg_trace(const char *str,...);
  461 #define DBG_TRACE(a) _dbg_trace a
  462 #else
  463 #define DBG_TRACE(a)
  464 #endif
  465 
  466 
  467 #ifdef __cplusplus
  468 }
  469 #endif
  470 
  471 #endif