sourcepawn/compiler/amxdbg.h
author David Anderson <dvander@alliedmods.net>
Wed Feb 25 20:07:12 2009 -0500 (2009-02-25)
changeset 2607 f3b8bbe17f85
parent 1952 b7aa2b626807
child 4149 096fdef5a186
permissions -rw-r--r--
Backed out changeset fa286305bd3f
     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
     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$
    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 __GNUC__
    46   #define PACKED        __attribute__((packed))
    47 #else
    48   #define PACKED
    49 #endif
    50 
    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
    56   #else
    57     #pragma pack(push)
    58     #pragma pack(1)         /* structures must be packed (byte-aligned) */
    59     #if defined __TURBOC__
    60       #pragma option -a-    /* "pack" pragma for older Borland compilers */
    61     #endif
    62   #endif
    63 #endif
    64 
    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 */
    77 } PACKED AMX_DBG_HDR;
    78 #define AMX_DBG_MAGIC   0xf1ef
    79 
    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;
    84 
    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;
    89 
    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;
   100 
   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;
   105 
   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;
   110 
   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;
   116 
   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;
   122 
   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;
   131 } PACKED AMX_DBG;
   132 
   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 */
   136   #define iARRAY     3
   137   #define iREFARRAY  4  /* an array passed by reference (i.e. a pointer) */
   138   #define iFUNCTN    9
   139 #endif
   140 
   141 
   142 int AMXAPI dbg_FreeInfo(AMX_DBG *amxdbg);
   143 int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, void *dbg_addr);
   144 
   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);
   148 
   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);
   156 
   157 
   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
   163   #else
   164     #pragma pack(pop) /* reset previous packing */
   165   #endif
   166 #endif
   167 
   168 #ifdef  __cplusplus
   169 }
   170 #endif
   171 
   172 #endif /* AMXDBG_H_INCLUDED */
   173