sourcepawn/compiler/amxdbg.h
author David Anderson <dvander@alliedmods.net>
Mon Oct 16 04:08:18 2006 +0000 (2006-10-16)
changeset 119 b81809fc34cf
parent 62 7c24f0801ae1
child 365 d830b2b0414f
permissions -rw-r--r--
fixed dynamic arrays not generating stack correctly
     1 /*  Abstract Machine for the Pawn compiler, debugger support
     2  *
     3  *  This file contains extra definitions that are convenient for debugger
     4  *  support.
     5  *
     6  *  Copyright (c) ITB CompuPhase, 2005-2006
     7  *
     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.
    11  *
    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:
    15  *
    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.
    23  *
    24  *  Version: $Id: amxdbg.h 3612 2006-07-22 09:59:46Z thiadmer $
    25  */
    26 
    27 #ifndef AMXDBG_H_INCLUDED
    28 #define AMXDBG_H_INCLUDED
    29 
    30 #ifndef AMX_H_INCLUDED
    31   #include "amx.h"
    32 #endif
    33 
    34 #ifdef  __cplusplus
    35 extern  "C" {
    36 #endif
    37 
    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...
    40  */
    41 #if defined SN_TARGET_PS2 || defined __GNUC__
    42   #define AMX_NO_ALIGN
    43 #endif
    44 
    45 #if !defined AMX_NO_ALIGN
    46   #if defined LINUX || defined __FreeBSD__
    47     #pragma pack(1)         /* structures must be packed (byte-aligned) */
    48   #elif defined MACOS && defined __MWERKS__
    49 	#pragma options align=mac68k
    50   #else
    51     #pragma pack(push)
    52     #pragma pack(1)         /* structures must be packed (byte-aligned) */
    53     #if defined __TURBOC__
    54       #pragma option -a-    /* "pack" pragma for older Borland compilers */
    55     #endif
    56   #endif
    57 #endif
    58 
    59 typedef struct tagAMX_DBG_HDR {
    60   int32_t size          ; /* size of the debug information chunk */
    61   uint16_t magic        ; /* signature, must be 0xf1ef */
    62   char    file_version  ; /* file format version */
    63   char    amx_version   ; /* required version of the AMX */
    64   int16_t flags         ; /* currently unused */
    65   int16_t files         ; /* number of entries in the "file" table */
    66   int16_t lines         ; /* number of entries in the "line" table */
    67   int16_t symbols       ; /* number of entries in the "symbol" table */
    68   int16_t tags          ; /* number of entries in the "tag" table */
    69   int16_t automatons    ; /* number of entries in the "automaton" table */
    70   int16_t states        ; /* number of entries in the "state" table */
    71 } AMX_DBG_HDR;
    72 #define AMX_DBG_MAGIC   0xf1ef
    73 
    74 typedef struct tagAMX_DBG_FILE {
    75   ucell   address       ; /* address in the code segment where generated code (for this file) starts */
    76   const char name[1]    ; /* ASCII string, zero-terminated */
    77 } AMX_DBG_FILE;
    78 
    79 typedef struct tagAMX_DBG_LINE {
    80   ucell   address       ; /* address in the code segment where generated code (for this line) starts */
    81   int32_t line          ; /* line number */
    82 } AMX_DBG_LINE;
    83 
    84 typedef struct tagAMX_DBG_SYMBOL {
    85   ucell   address       ; /* address in the data segment or relative to the frame */
    86   int16_t tag           ; /* tag for the symbol */
    87   ucell   codestart     ; /* address in the code segment from which this symbol is valid (in scope) */
    88   ucell   codeend       ; /* address in the code segment until which this symbol is valid (in scope) */
    89   char    ident         ; /* kind of symbol (function/variable) */
    90   char    vclass        ; /* class of symbol (global/local) */
    91   int16_t dim           ; /* number of dimensions */
    92   const char name[1]    ; /* ASCII string, zero-terminated */
    93 } AMX_DBG_SYMBOL;
    94 
    95 typedef struct tagAMX_DBG_SYMDIM {
    96   int16_t tag           ; /* tag for the array dimension */
    97   ucell   size          ; /* size of the array dimension */
    98 } AMX_DBG_SYMDIM;
    99 
   100 typedef struct tagAMX_DBG_TAG {
   101   int16_t tag           ; /* tag id */
   102   const char name[1]    ; /* ASCII string, zero-terminated */
   103 } AMX_DBG_TAG;
   104 
   105 typedef struct tagAMX_DBG_MACHINE {
   106   int16_t automaton     ; /* automaton id */
   107   ucell address         ; /* address of state variable */
   108   const char name[1]    ; /* ASCII string, zero-terminated */
   109 } AMX_DBG_MACHINE;
   110 
   111 typedef struct tagAMX_DBG_STATE {
   112   int16_t state         ; /* state id */
   113   int16_t automaton     ; /* automaton id */
   114   const char name[1]    ; /* ASCII string, zero-terminated */
   115 } AMX_DBG_STATE;
   116 
   117 typedef struct tagAMX_DBG {
   118   AMX_DBG_HDR     *hdr           ; /* points to the AMX_DBG header */
   119   AMX_DBG_FILE    **filetbl      ;
   120   AMX_DBG_LINE    *linetbl       ;
   121   AMX_DBG_SYMBOL  **symboltbl    ;
   122   AMX_DBG_TAG     **tagtbl       ;
   123   AMX_DBG_MACHINE **automatontbl ;
   124   AMX_DBG_STATE   **statetbl     ;
   125 } AMX_DBG;
   126 
   127 #if !defined iVARIABLE
   128   #define iVARIABLE  1  /* cell that has an address and that can be fetched directly (lvalue) */
   129   #define iREFERENCE 2  /* iVARIABLE, but must be dereferenced */
   130   #define iARRAY     3
   131   #define iREFARRAY  4  /* an array passed by reference (i.e. a pointer) */
   132   #define iFUNCTN    9
   133 #endif
   134 
   135 
   136 int AMXAPI dbg_FreeInfo(AMX_DBG *amxdbg);
   137 int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, FILE *fp);
   138 
   139 int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename);
   140 int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcname);
   141 int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line);
   142 
   143 int AMXAPI dbg_GetFunctionAddress(AMX_DBG *amxdbg, const char *funcname, const char *filename, ucell *address);
   144 int AMXAPI dbg_GetLineAddress(AMX_DBG *amxdbg, long line, const char *filename, ucell *address);
   145 int AMXAPI dbg_GetAutomatonName(AMX_DBG *amxdbg, int automaton, const char **name);
   146 int AMXAPI dbg_GetStateName(AMX_DBG *amxdbg, int state, const char **name);
   147 int AMXAPI dbg_GetTagName(AMX_DBG *amxdbg, int tag, const char **name);
   148 int AMXAPI dbg_GetVariable(AMX_DBG *amxdbg, const char *symname, ucell scopeaddr, const AMX_DBG_SYMBOL **sym);
   149 int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX_DBG_SYMDIM **symdim);
   150 
   151 
   152 #if !defined AMX_NO_ALIGN
   153   #if defined LINUX || defined __FreeBSD__
   154     #pragma pack()    /* reset default packing */
   155   #elif defined MACOS && defined __MWERKS__
   156     #pragma options align=reset
   157   #else
   158     #pragma pack(pop) /* reset previous packing */
   159   #endif
   160 #endif
   161 
   162 #ifdef  __cplusplus
   163 }
   164 #endif
   165 
   166 #endif /* AMXDBG_H_INCLUDED */