| 1 | /* $Id: symfile.h,v 1.3 2001-11-22 13:35:42 phaller Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 4 | * Execution Trace Profiler
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 2001 Patrick Haller <patrick.haller@innotek.de>
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | /****************************************************************************
|
|---|
| 11 | * To Do
|
|---|
| 12 | ****************************************************************************
|
|---|
| 13 |
|
|---|
| 14 | - find and load symbolic debug information file
|
|---|
| 15 | (SYM2IDA)
|
|---|
| 16 | - resolve (relative address) to function name(s)
|
|---|
| 17 | - write result in java.prof style
|
|---|
| 18 | - find tool to nicely work on the output files
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | #ifndef _SYMFILE_H_
|
|---|
| 23 | #define _SYMFILE_H_
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | /****************************************************************************
|
|---|
| 27 | * includes
|
|---|
| 28 | ****************************************************************************/
|
|---|
| 29 |
|
|---|
| 30 | #include "profcollection.h"
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | /****************************************************************************
|
|---|
| 34 | * definitions
|
|---|
| 35 | ****************************************************************************/
|
|---|
| 36 |
|
|---|
| 37 | /* Pointer means offset from beginning of file or beginning of struct */
|
|---|
| 38 | #pragma pack(1)
|
|---|
| 39 | typedef struct {
|
|---|
| 40 | unsigned short int ppNextMap; /* paragraph pointer to next map */
|
|---|
| 41 | unsigned char bFlags; /* symbol types */
|
|---|
| 42 | unsigned char bReserved1; /* reserved */
|
|---|
| 43 | unsigned short int pSegEntry; /* segment entry point value */
|
|---|
| 44 | unsigned short int cConsts; /* count of constants in map */
|
|---|
| 45 | unsigned short int pConstDef; /* pointer to constant chain */
|
|---|
| 46 | unsigned short int cSegs; /* count of segments in map */
|
|---|
| 47 | unsigned short int ppSegDef; /* paragraph pointer to first segment */
|
|---|
| 48 | unsigned char cbMaxSym; /* maximum symbol-name length */
|
|---|
| 49 | unsigned char cbModName; /* length of module name */
|
|---|
| 50 | char achModName[1]; /* cbModName Bytes of module-name member */
|
|---|
| 51 | } MAPDEF, *PMAPDEF;
|
|---|
| 52 |
|
|---|
| 53 | typedef struct {
|
|---|
| 54 | unsigned short int ppNextMap; /* always zero */
|
|---|
| 55 | unsigned char release; /* release number (minor version number) */
|
|---|
| 56 | unsigned char version; /* major version number */
|
|---|
| 57 | } LAST_MAPDEF, *PLAST_MAPDEF;
|
|---|
| 58 |
|
|---|
| 59 | typedef struct {
|
|---|
| 60 | unsigned short int ppNextSeg; /* paragraph pointer to next segment */
|
|---|
| 61 | unsigned short int cSymbols; /* count of symbols in list */
|
|---|
| 62 | unsigned short int pSymDef; /* offset of symbol chain */
|
|---|
| 63 | unsigned short int wReserved1; /* reserved */
|
|---|
| 64 | unsigned short int wReserved2; /* reserved */
|
|---|
| 65 | unsigned short int wReserved3; /* reserved */
|
|---|
| 66 | unsigned short int wReserved4; /* reserved */
|
|---|
| 67 | unsigned char bFlags; /* symbol types */
|
|---|
| 68 | unsigned char bReserved1; /* reserved */
|
|---|
| 69 | unsigned short int ppLineDef; /* offset of line number record */
|
|---|
| 70 | unsigned char bReserved2; /* reserved */
|
|---|
| 71 | unsigned char bReserved3; /* reserved */
|
|---|
| 72 | unsigned char cbSegName; /* length of segment name */
|
|---|
| 73 | char achSegName[1]; /* cbSegName Bytes of segment-name member*/
|
|---|
| 74 | } SEGDEF, *PSEGDEF;
|
|---|
| 75 |
|
|---|
| 76 | typedef struct {
|
|---|
| 77 | unsigned short int wSymVal; /* symbol address or constant */
|
|---|
| 78 | unsigned char cbSymName; /* length of symbol name */
|
|---|
| 79 | char achSymName[1]; /* cbSymName Bytes of symbol-name member */
|
|---|
| 80 | } SYMDEF16, *PSEGDEF16;
|
|---|
| 81 |
|
|---|
| 82 | typedef struct {
|
|---|
| 83 | unsigned int wSymVal; /* symbol address or constant */
|
|---|
| 84 | unsigned char cbSymName; /* length of symbol name */
|
|---|
| 85 | char achSymName[1]; /* cbSymName Bytes of symbol-name member */
|
|---|
| 86 | } SYMDEF32, *PSYMDEF32;
|
|---|
| 87 |
|
|---|
| 88 | typedef struct {
|
|---|
| 89 | unsigned short int ppNextLine; /* ptr to next linedef (0 if last) */
|
|---|
| 90 | unsigned short int wReserved1; /* reserved */
|
|---|
| 91 | unsigned short int pLines; /* pointer to line numbers */
|
|---|
| 92 | unsigned short int cLines; /* reserved */
|
|---|
| 93 | unsigned char cbFileName; /* length of filename */
|
|---|
| 94 | char achFileName[1];/* cbFileName Bytes of filename */
|
|---|
| 95 | } LINEDEF, *PLINEDEF;
|
|---|
| 96 |
|
|---|
| 97 | typedef struct {
|
|---|
| 98 | unsigned short int wCodeOffset; /* executable offset */
|
|---|
| 99 | unsigned short int dwFileOffset; /* source offset */
|
|---|
| 100 | } LINEINF, *PLINEINF;
|
|---|
| 101 |
|
|---|
| 102 | #define SEGDEFOFFSET(MapDef) (MapDef.ppSegDef*16)
|
|---|
| 103 | #define NEXTSEGDEFOFFSET(SegDef) (SegDef.ppNextSeg*16)
|
|---|
| 104 |
|
|---|
| 105 | #define ASYMPTROFFSET(SegDefOffset,Segdef) (SegDefOffset+SegDef.pSymDef)
|
|---|
| 106 | #define SYMDEFOFFSET(SegDefOffset,SegDef,n) (ASYMPTROFFSET(SegDefOffset,SegDef)+(n)*(sizeof(unsigned short int)))
|
|---|
| 107 |
|
|---|
| 108 | #define ACONSTPTROFFSET(MapDef) (MapDef.ppConstDef)
|
|---|
| 109 | #define CONSTDEFOFFSET(MapDef,n) ((MapDef.ppConstDef)+(n)*(sizeof(unsigned short int)))
|
|---|
| 110 |
|
|---|
| 111 | #define LINEDEFOFFSET(SegDef) (SegDef.ppLineDef*16))
|
|---|
| 112 | #define NEXTLINEDEFOFFSET(LineDef) (LineDef.ppNextLine*16)
|
|---|
| 113 | #define LINESOFFSET(LinedefOffset,LineDef) ((LinedefOffset)+LineDef.pLines)
|
|---|
| 114 |
|
|---|
| 115 | #pragma pack()
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | typedef struct tagLXMap
|
|---|
| 119 | {
|
|---|
| 120 |
|
|---|
| 121 | } LXMAP, *PLXMAP;
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | class LXSymbolFile
|
|---|
| 125 | {
|
|---|
| 126 | public:
|
|---|
| 127 | LXSymbolFile(PSZ pszName, PSZ pszFileName);
|
|---|
| 128 | ~LXSymbolFile();
|
|---|
| 129 |
|
|---|
| 130 | APIRET parseFile();
|
|---|
| 131 | BOOL isAvailable();
|
|---|
| 132 |
|
|---|
| 133 | void setErrorMessage(PSZ _pszErrorMessage);
|
|---|
| 134 | PSZ getErrorMessage();
|
|---|
| 135 | PSZ getFileName();
|
|---|
| 136 | PSZ getName() { return pszName; }
|
|---|
| 137 | BOOL getSymbolName(ULONG objNr,
|
|---|
| 138 | ULONG offset,
|
|---|
| 139 | PSZ pszNameBuffer,
|
|---|
| 140 | ULONG ulNameBufferLength,
|
|---|
| 141 | PULONG pulSymbolOffset);
|
|---|
| 142 |
|
|---|
| 143 | protected:
|
|---|
| 144 | PSZ pszName;
|
|---|
| 145 | PSZ pszFileName;
|
|---|
| 146 | PSZ pszErrorMessage;
|
|---|
| 147 |
|
|---|
| 148 | // table: objnr:offset, symbolname
|
|---|
| 149 | PBYTE pSymbolRawData;
|
|---|
| 150 | };
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | class SymbolFilePool
|
|---|
| 154 | {
|
|---|
| 155 | public:
|
|---|
| 156 | SymbolFilePool();
|
|---|
| 157 | ~SymbolFilePool();
|
|---|
| 158 |
|
|---|
| 159 | APIRET searchModule(PSZ pszModule, PBYTE pBuffer, ULONG ulBufferLength);
|
|---|
| 160 | BOOL getSymbolName(PSZ pszModule,
|
|---|
| 161 | ULONG objNr,
|
|---|
| 162 | ULONG offset,
|
|---|
| 163 | PSZ pszNameBuffer,
|
|---|
| 164 | ULONG ulNameBufferLength,
|
|---|
| 165 | PULONG pulSymbolOffset);
|
|---|
| 166 | void printSYMs(FILE *file);
|
|---|
| 167 |
|
|---|
| 168 | protected:
|
|---|
| 169 | CHashtableLookup* pHashModules;
|
|---|
| 170 |
|
|---|
| 171 | // - find module name in internal table
|
|---|
| 172 | // - try to load and parse the module
|
|---|
| 173 | // - if loading failed, cache negative result
|
|---|
| 174 | // so we won't try again (-> isAvailable)
|
|---|
| 175 | };
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 | #endif /* _SYMFILE_H_ */
|
|---|
| 179 |
|
|---|