86a45ccab30ea3960c4a65b4983f44bb06b90562
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDBGBase.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9         Vicente Fernando - www.alfersoft.com.ar - Initial implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.internal.debug.core;
12
13 public class PHPDBGBase {
14
15         // Constants
16         // php-engine commands/events
17         public static final int DBGC_REPLY                      = 0x0000;                               // reply to previous DBGA_REQUEST request
18         public static final int DBGC_STARTUP                    = 0x0001;                               // script startup
19         public static final int DBGC_END                                = 0x0002;                               // script done
20         public static final int DBGC_BREAKPOINT         = 0x0003;                               // user definded breakpoint occured
21         public static final int DBGC_STEPINTO_DONE      = 0x0004;                               // step to the next statement is completed
22         public static final int DBGC_STEPOVER_DONE      = 0x0005;                               // step to the next statement is completed
23         public static final int DBGC_STEPOUT_DONE               = 0x0006;                               // step to the next statement is completed
24         public static final int DBGC_EMBEDDED_BREAK     = 0x0007;                               // breakpoint caused by DebugBreak() function
25         public static final int DBGC_ERROR                      = 0x0010;                               // error occured
26         public static final int DBGC_LOG                                = 0x0011;                               // logging support
27         public static final int DBGC_SID                                = 0x0012;                               // send SID
28         public static final int DBGC_PAUSE                      = 0x0013;                               // pause current session as soon as possible
29
30         public static final char[] DBGA_CONTINUE                = IntToChar4(0x8001);   // php should continue run
31         public static final char[] DBGA_STOP                    = IntToChar4(0x8002);
32         public static final char[] DBGA_STEPINTO                = IntToChar4(0x8003);
33         public static final char[] DBGA_STEPOVER                = IntToChar4(0x8004);
34         public static final char[] DBGA_STEPOUT         = IntToChar4(0x8005);
35         public static final char[] DBGA_IGNORE          = IntToChar4(0x8006);
36         public static final char[] DBGA_REQUEST         = IntToChar4(0x8010);   // debugger client requests some information from PHP engine
37
38         public static final int FRAME_STACK                     = 100000;                               // "call:stack" - e.g. backtrace
39         public static final int FRAME_SOURCE                    = 100100;                               // source text
40         public static final int FRAME_SRC_TREE          = 100200;                               // tree of source files
41         public static final int FRAME_RAWDATA                   = 100300;                               // raw data or string
42         public static final int FRAME_ERROR                     = 100400;                               // error notification
43         public static final int FRAME_EVAL                      = 100500;                               // evaluating/watching
44         public static final int FRAME_BPS                               = 100600;                               // set/remove breakpoint
45         public static final int FRAME_BPL                               = 100700;                               // breakpoint(s) request = get the list
46         public static final int FRAME_VER                               = 100800;                               // version request
47         public static final int FRAME_SID                               = 100900;                               // session id info
48         public static final int FRAME_SRCLINESINFO      = 101000;                               // source lines info
49         public static final int FRAME_SRCCTXINFO                = 101100;                               // source contexts info
50         public static final int FRAME_LOG                               = 101200;                               // logging
51         public static final int FRAME_PROF                      = 101300;                               // profiler
52         public static final int FRAME_PROF_C                    = 101400;                               // profiler counter/accuracy
53         public static final int FRAME_SET_OPT                   = 101500;                               // set/update options
54
55         public static final int CURLOC_SCOPE_ID                 = 1;                                    // nested locations are 2,3... and so on in backward order,
56                                                                                                                                                         //  so 2 represents most out-standing stack context
57         public static final int GLOBAL_SCOPE_ID                 = -1;                                   // it is global context, not stacked
58
59         public static final char[] DBGSYNC                      = { 0, 0, (char) 89, (char) 83 };       // DBG syncronization chars
60
61         // Session Types
62         public static final int DBG_COMPAT                      = 0x0001;
63         public static final int DBG_JIT                         = 0x0002;
64         public static final int DBG_REQ                         = 0x0003;
65         public static final int DBG_EMB                         = 0x0004;
66
67         public static final int BPS_DELETED                     = 0;
68         public static final int BPS_DISABLED                    = 1;
69         public static final int BPS_ENABLED                     = 2;
70         public static final int BPS_UNRESOLVED          = 0x100;
71
72         public static final int E_ERROR                         = (1<<0L);
73         public static final int E_WARNING                               = (1<<1L);
74         public static final int E_PARSE                         = (1<<2L);
75         public static final int E_NOTICE                                = (1<<3L);
76         public static final int E_CORE_ERROR                    = (1<<4L);
77         public static final int E_CORE_WARNING          = (1<<5L);
78         public static final int E_COMPILE_ERROR         = (1<<6L);
79         public static final int E_COMPILE_WARNING               = (1<<7L);
80         public static final int E_USER_ERROR                    = (1<<8L);
81         public static final int E_USER_WARNING          = (1<<9L);
82         public static final int E_USER_NOTICE                   = (1<<10L);
83
84         public PHPDBGBase() {
85         }
86
87
88         /**
89          * Copies the number of bytes from a source buffer to a destination buffer
90          * Destination index starts with 0 + tostart,
91          * and source index starts with 0.
92          *
93          * @param to        The destination buffer.
94          * @param from      The source buffer.
95          * @param bytes     The number of bytes which are to copy.
96          * @param tostart   The start index for the destination buffer.
97          */
98         public static void copyCharsTo (char[] to, char[] from, int bytes, int tostart) {
99                 int i;
100
101                 for (i = 0; i < bytes; i++) {                                                           // For the number of bytes which are to copy
102                         to[i + tostart] = from[i];                                                              // Copy from destination to source (+startindex)
103                 }
104         }
105
106         /**
107          * Copies the number of bytes from a source buffer to a destination buffer
108          * Destination index starts with 0,
109          * and source index starts with 0.
110          *
111          * @param to        The destination buffer.
112          * @param from      The source buffer.
113          * @param bytes     The number of bytes which are to copy.
114          */
115         public static void copyChars (char[] to, char[] from, int bytes) {
116                 copyCharsTo (to, from, bytes, 0);
117         }
118
119         /**
120          * Converts a four chars big endian value into
121          * an integer value
122          *
123          * @param ch        The buffer which contains the four chars which are to convert.
124          * @param startPos  The start position (of the four bytes) within the buffer.
125          */
126         public static int Char4ToInt (char[] ch, int startPos) {
127                 int pos = startPos;
128                 int ret = 0;
129
130                 ret += CharToInt (ch[pos++]) << 24;
131                 ret += CharToInt (ch[pos++]) << 16;
132                 ret += CharToInt (ch[pos++]) <<  8;
133                 ret += CharToInt (ch[pos++]) <<  0;
134
135                 return ret;
136         }
137
138         /**
139          * @return The character which is converted to an integer value.
140          */
141         public static int CharToInt (char ch) {
142                 return (int) (ch & 0x00FF);
143         }
144
145         /**
146          * Converts an integer value into a four char big endian number
147          *
148          * @param num The integer value which is to convert to a four char big endian number.
149          * @return    The four byte buffer with the big endian number.
150          */
151         public static char[] IntToChar4 (int num) {
152                 char[] ret = new char[4];
153
154                 ret[0] = (char) ((num >> 24) & 0x00FF);
155                 ret[1] = (char) ((num >> 16) & 0x00FF);
156                 ret[2] = (char) ((num >>  8) & 0x00FF);
157                 ret[3] = (char) ((num >>  0) & 0x00FF);
158
159                 return ret;
160         }
161
162         /**
163          * Converts the chars of an array into a string in form of
164          * (byte value string) (byte value string) (byte value string) ...
165          *
166          * @param cha  The input buffer which contains the chars which are to convert.
167          * @return     The string which contains the bytes as strings.
168          *             E.g.: (123) (11) (46) (213) ...
169          */
170         public static String CharArrayToString (char[] cha) {
171                 String ret = new String ();
172                 int    i;
173                 int    p;
174
175                 for (i = 0; i < cha.length; i++) {                                                      // For all bytes within the input buffer
176                         p   = (int) cha[i];                                                                             // Convert the byte into an integer value
177                         ret = ret + "(" + String.valueOf (p) + ") ";                    // Add the value
178                 }
179
180                 return ret;
181         }
182
183         /**
184          *
185          * @param cha  The input buffer which contains the chars which are to convert.
186          * @return     The byte array which contains the converted chars.
187          */
188         public static byte[] CharArrayToByteArray (char[] cha) {
189                 byte[] ret = new byte[cha.length];                                                      // The resulting byte array
190                 int    i;                                                                                                       // The index for the buffers
191
192                 for (i = 0; i < cha.length; i++) {                                                      // For all chars within the input buffer
193                         ret[i] = (byte) cha[i];                                                                 //  Convert the character to a byte and store to buffer
194                 }
195
196                 return ret;                                                                                                     // Return the byte array
197         }
198 }