1 /* Abstract Machine for the Pawn compiler, debugger support
3 * This file contains extra definitions that are convenient for debugger
6 * Copyright (c) ITB CompuPhase, 2005
8 * This software is provided "as-is", without any express or implied warranty.
9 * In no event will the authors be held liable for any damages arising from
10 * the use of this software.
12 * Permission is granted to anyone to use this software for any purpose,
13 * including commercial applications, and to alter it and redistribute it
14 * freely, subject to the following restrictions:
16 * 1. The origin of this software must not be misrepresented; you must not
17 * claim that you wrote the original software. If you use this software in
18 * a product, an acknowledgment in the product documentation would be
19 * appreciated but is not required.
20 * 2. Altered source versions must be plainly marked as such, and must not be
21 * misrepresented as being the original software.
22 * 3. This notice may not be removed or altered from any source distribution.
27 #ifndef AMXDBG_H_INCLUDED
28 #define AMXDBG_H_INCLUDED
30 #ifndef AMX_H_INCLUDED
38 /* Some compilers do not support the #pragma align, which should be fine. Some
39 * compilers give a warning on unknown #pragmas, which is not so fine...
41 #if defined SN_TARGET_PS2 || defined __GNUC__
46 #define PACKED __attribute__((packed))
51 #if !defined AMX_NO_ALIGN
52 #if defined LINUX || defined __FreeBSD__
53 #pragma pack(1) /* structures must be packed (byte-aligned) */
54 #elif defined MACOS && defined __MWERKS__
55 #pragma options align=mac68k
58 #pragma pack(1) /* structures must be packed (byte-aligned) */
59 #if defined __TURBOC__
60 #pragma option -a- /* "pack" pragma for older Borland compilers */
65 typedef struct tagAMX_DBG_HDR {
66 int32_t size PACKED; /* size of the debug information chunk */
67 uint16_t magic PACKED; /* signature, must be 0xf1ef */
68 char file_version; /* file format version */
69 char amx_version; /* required version of the AMX */
70 int16_t flags PACKED; /* currently unused */
71 int16_t files PACKED; /* number of entries in the "file" table */
72 int16_t lines PACKED; /* number of entries in the "line" table */
73 int16_t symbols PACKED; /* number of entries in the "symbol" table */
74 int16_t tags PACKED; /* number of entries in the "tag" table */
75 int16_t automatons PACKED; /* number of entries in the "automaton" table */
76 int16_t states PACKED; /* number of entries in the "state" table */
78 #define AMX_DBG_MAGIC 0xf1ef
80 typedef struct tagAMX_DBG_FILE {
81 ucell address PACKED; /* address in the code segment where generated code (for this file) starts */
82 const char name[1]; /* ASCII string, zero-terminated */
83 } PACKED AMX_DBG_FILE;
85 typedef struct tagAMX_DBG_LINE {
86 ucell address PACKED; /* address in the code segment where generated code (for this line) starts */
87 int32_t line PACKED; /* line number */
88 } PACKED AMX_DBG_LINE;
90 typedef struct tagAMX_DBG_SYMBOL {
91 ucell address PACKED; /* address in the data segment or relative to the frame */
92 int16_t tag PACKED; /* tag for the symbol */
93 ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */
94 ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */
95 char ident; /* kind of symbol (function/variable) */
96 char vclass; /* class of symbol (global/local) */
97 int16_t dim PACKED; /* number of dimensions */
98 const char name[1]; /* ASCII string, zero-terminated */
99 } PACKED AMX_DBG_SYMBOL;
101 typedef struct tagAMX_DBG_SYMDIM {
102 int16_t tag PACKED; /* tag for the array dimension */
103 ucell size PACKED; /* size of the array dimension */
104 } PACKED AMX_DBG_SYMDIM;
106 typedef struct tagAMX_DBG_TAG {
107 int16_t tag PACKED; /* tag id */
108 const char name[1]; /* ASCII string, zero-terminated */
109 } PACKED AMX_DBG_TAG;
111 typedef struct tagAMX_DBG_MACHINE {
112 int16_t automaton PACKED; /* automaton id */
113 ucell address PACKED; /* address of state variable */
114 const char name[1]; /* ASCII string, zero-terminated */
115 } PACKED AMX_DBG_MACHINE;
117 typedef struct tagAMX_DBG_STATE {
118 int16_t state PACKED; /* state id */
119 int16_t automaton PACKED; /* automaton id */
120 const char name[1]; /* ASCII string, zero-terminated */
121 } PACKED AMX_DBG_STATE;
123 typedef struct tagAMX_DBG {
124 AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */
125 AMX_DBG_FILE _FAR **filetbl PACKED;
126 AMX_DBG_LINE _FAR *linetbl PACKED;
127 AMX_DBG_SYMBOL _FAR **symboltbl PACKED;
128 AMX_DBG_TAG _FAR **tagtbl PACKED;
129 AMX_DBG_MACHINE _FAR **automatontbl PACKED;
130 AMX_DBG_STATE _FAR **statetbl PACKED;
133 #if !defined iVARIABLE
134 #define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */
135 #define iREFERENCE 2 /* iVARIABLE, but must be dereferenced */
137 #define iREFARRAY 4 /* an array passed by reference (i.e. a pointer) */
142 int AMXAPI dbg_FreeInfo(AMX_DBG *amxdbg);
143 int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, void *dbg_addr);
145 int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename);
146 int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcname);
147 int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line);
149 int AMXAPI dbg_GetFunctionAddress(AMX_DBG *amxdbg, const char *funcname, const char *filename, ucell *address);
150 int AMXAPI dbg_GetLineAddress(AMX_DBG *amxdbg, long line, const char *filename, ucell *address);
151 int AMXAPI dbg_GetAutomatonName(AMX_DBG *amxdbg, int automaton, const char **name);
152 int AMXAPI dbg_GetStateName(AMX_DBG *amxdbg, int state, const char **name);
153 int AMXAPI dbg_GetTagName(AMX_DBG *amxdbg, int tag, const char **name);
154 int AMXAPI dbg_GetVariable(AMX_DBG *amxdbg, const char *symname, ucell scopeaddr, const AMX_DBG_SYMBOL **sym);
155 int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX_DBG_SYMDIM **symdim);
158 #if !defined AMX_NO_ALIGN
159 #if defined LINUX || defined __FreeBSD__
160 #pragma pack() /* reset default packing */
161 #elif defined MACOS && defined __MWERKS__
162 #pragma options align=reset
164 #pragma pack(pop) /* reset previous packing */
172 #endif /* AMXDBG_H_INCLUDED */