source: trunk/tools/dbginfo/kHll.h@ 10366

Last change on this file since 10366 was 4130, checked in by bird, 25 years ago

New interface (kHllMain).
Able to spit out symbol files.
Able to read symbol files and the entry table of LX files.

File size: 11.6 KB
Line 
1/* $Id: kHll.h,v 1.10 2000-08-31 03:02:27 bird Exp $
2 *
3 * kHll - Declarations of the class kHll.
4 * That class is used to create HLL debuginfo.
5 *
6 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12
13#ifndef _kHll_h_
14#define _kHll_h_
15
16//wrong placement!
17#include <builtin.h>
18#undef assert
19#define assert(a) (!(a) ? \
20 fprintf(stderr, "assert - %s(%d): %s\n", __FUNCTION__, __LINE__, #a), \
21 __interrupt(3) \
22 : \
23 (void)0, (void)0)
24
25/*******************************************************************************
26* Structures and Typedefs *
27*******************************************************************************/
28
29/**
30 * HLL General entry.
31 * Provided as a base class for kList entries.
32 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
33 */
34class kHllBaseEntry : public kSortedListEntry
35{
36public:
37 /**
38 * Write this HLL entry to file.
39 * @returns Count of bytes written (on success).
40 * -3 Invalid offsets.
41 * -2 Seek error.
42 * -1 Write error.
43 * 0 No data written. Concidered as an error!
44 * @param phFile Filehandle.
45 */
46 virtual int write(FILE *phFile) = 0;
47 static int writeList(FILE *phFile, kHllBaseEntry *pEntry);
48
49 /**
50 * Dumps the HLL entry to ph in a human readable fashion.
51 * @param ph Output file handle the dump is to be written to.
52 * @param cchIndent Number of char to indents the output dump.
53 */
54 virtual void dump(FILE *ph, int cchIndent) = 0;
55 static void dumpList(FILE *ph, int cchIndent, kHllBaseEntry *pEntry);
56
57 /**
58 * Create IDC (IDA Pro) calls which adds info contained in the entry
59 * to the ida pro database.
60 * !!!NOTE!!! THIS IS ONLY TO BE USED FOR YOUR OWN PROGRAMS!!!
61 * @param pFile Output file.
62 */
63 virtual void ida(kFile *pFile) throw(int) = 0;
64 static void idaList(kFile *pFile, kHllBaseEntry *pEntry) throw(int);
65
66 /* temp fix */
67 BOOL operator==(const kSortedListEntry &entry) const { return TRUE; }
68 BOOL operator!=(const kSortedListEntry &entry) const { return FALSE; }
69 BOOL operator< (const kSortedListEntry &entry) const { return TRUE; }
70 BOOL operator<=(const kSortedListEntry &entry) const { return TRUE; }
71 BOOL operator> (const kSortedListEntry &entry) const { return FALSE; }
72 BOOL operator>=(const kSortedListEntry &entry) const { return FALSE; }
73};
74
75
76
77/**
78 * HLL Public symbol entry.
79 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
80 */
81class kHllPubSymEntry : public kHllBaseEntry
82{
83private:
84 PHLLPUBLICSYM pPubSym;
85
86public:
87 kHllPubSymEntry(
88 const char * pachName,
89 int cchName,
90 unsigned long off,
91 unsigned short iObject,
92 unsigned short iType
93 );
94 ~kHllPubSymEntry();
95
96 int write(FILE *phFile);
97 void dump(FILE *ph, int cchIndent);
98 void ida(kFile *pFile) throw(int);
99
100 /** @cat
101 * Get methods.
102 */
103 /** Gets the offset of the symbol location relative to object start. */
104 unsigned long getOffset() { return pPubSym->off; }
105 /** Gets the object (segment/section/what ever) index of the symbol location. */
106 int getObjectIndex(){ return pPubSym->iObject; }
107 /** Gets the Type index of the symbol type. */
108 int getTypeIndex() { return pPubSym->iType; }
109 /** Gets the length of the public symbol. */
110 char getNameLength() { return pPubSym->cchName; }
111 /** Gets ASCIIZ public symbol name. */
112 const char * getName() { return (const char *)&pPubSym->achName[0]; }
113
114
115 BOOL operator==(const kHllPubSymEntry &entry) const;
116 BOOL operator!=(const kHllPubSymEntry &entry) const;
117 BOOL operator< (const kHllPubSymEntry &entry) const;
118 BOOL operator<=(const kHllPubSymEntry &entry) const;
119 BOOL operator> (const kHllPubSymEntry &entry) const;
120 BOOL operator>=(const kHllPubSymEntry &entry) const;
121};
122
123
124
125/**
126 * Linenumber chunk.
127 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
128 */
129class kHllLineNumberChunk : public kHllBaseEntry
130{
131private:
132 PHLLLINENUMBERENTRY paLines;
133 HLLFIRSTENTRY FirstEntry;
134
135public:
136 kHllLineNumberChunk(
137 unsigned short int iSeg,
138 unsigned long int offBase = 0
139 );
140 ~kHllLineNumberChunk();
141
142 BOOL addLineInfo(
143 unsigned short int iusFile,
144 unsigned short int usLine,
145 unsigned long int off
146 );
147
148 int write(FILE *phFile);
149 void dump(FILE *ph, int cchIndent);
150 void ida(kFile *pFile) throw(int);
151
152 int getSeg() { return FirstEntry.hll04.iSeg; }
153};
154
155
156/**
157 * HLL Source entry.
158 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
159 */
160class kHllSrcEntry
161{
162private:
163 unsigned long int cFilenames;
164 char * pachFilenames;
165 unsigned long int cbFilenames;
166 unsigned long int cbFilenamesAllocated;
167
168 kList<kHllLineNumberChunk>
169 Lines;
170
171public:
172 kHllSrcEntry();
173 ~kHllSrcEntry();
174
175 kHllLineNumberChunk *
176 addLineNumberChunk(
177 unsigned short int iSeg,
178 unsigned long int offBase = 0
179 );
180 unsigned short addFile(
181 const char * pszFilename
182 );
183 unsigned short addFile(
184 const char * pachFilename,
185 int cchFilename
186 );
187 int write(FILE *phFile);
188 void dump(FILE *ph, int cchIndent);
189 void ida(kFile *pFile) throw(int);
190};
191
192
193
194/**
195 * HLL Module entry.
196 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
197 */
198class kHllModuleEntry : public kListEntry
199{
200private:
201 /** @cat
202 * Internal data.
203 * HLL Module data.
204 * Lists of HLL elements
205 * Offsets and sizes - set by write(..).
206 */
207 PHLLMODULE pModule;
208
209 kSortedList<kHllPubSymEntry> PublicSymbols;
210 /*
211 kList<kHllTypeEntry> Types;
212 kList<kHllSymEntry> Symbols;
213 */
214 kHllSrcEntry Source;
215
216 BOOL fValidOffsetsAndSizes;
217 unsigned long offModule;
218 unsigned long cbModule;
219 unsigned long offPublicSymbols;
220 unsigned long cbPublicSymbols;
221 unsigned long offTypes;
222 unsigned long cbTypes;
223 unsigned long offSymbols;
224 unsigned long cbSymbols;
225 unsigned long offSource;
226 unsigned long cbSource;
227
228 unsigned long iObjectMax;
229
230
231 /** @cat
232 * Internal methods.
233 */
234 int writeList(FILE *phFile, kList<kHllBaseEntry> &List);
235
236
237public:
238 /** @cat
239 * Constructor and destructor.
240 */
241 kHllModuleEntry(
242 const char * pszName,
243 unsigned short iLib,
244 unsigned char cSegInfo = 0,
245 PHLLSEGINFO paSegInfo = NULL
246 );
247 ~kHllModuleEntry();
248
249
250 /** @cat
251 * Add menthods
252 */
253 BOOL addSegInfo(
254 unsigned short int iObject,
255 unsigned long off,
256 unsigned long cb
257 );
258
259 const void * addPublicSymbol(
260 const char * pszName,
261 unsigned long int off,
262 unsigned short int iObject,
263 const void * pvType
264 );
265 const void * addPublicSymbol(
266 const char * pachName,
267 int cchName,
268 unsigned long int off,
269 unsigned short int iObject,
270 const void * pvType
271 );
272 kHllSrcEntry * getSourceEntry() { return &Source; }
273
274
275 /** @cat
276 * Output.
277 */
278 int write(FILE *phFile, unsigned long off);
279 int writeDirEntries(FILE *phFile, unsigned short iMod);
280 void writeSymSeg(kFile *pFile, int iSeg, PSEGDEF pSegDef,
281 unsigned short * &paoffSyms, int &coffSymsAllocated,
282 unsigned long offSegDef) throw (int);
283
284 /** @cat
285 * Get and queries.
286 */
287 int queryMaxObjectIndex();
288
289 /** @cat
290 * Debug dump function.
291 */
292 void dump(FILE *ph);
293 void ida(kFile *pFile) throw(int);
294};
295
296
297
298/**
299 * HLL Debug Info generator.
300 * @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
301 */
302class kHll
303{
304
305private:
306 /** @cat
307 * Internal data.
308 */
309 kList<kHllModuleEntry> Modules;
310 /*
311 kList<kHllLibraryEntry> Libraries;
312 */
313 char * pszModName;
314
315 /** @cat
316 * Internal methods.
317 */
318 int write(FILE *phFile);
319
320
321public:
322 /** @cat
323 * Constructors and Destructors.
324 */
325 kHll();
326 kHll(kFile *pFile) throw (int);
327 ~kHll();
328
329 /** @cat
330 * Add menthods
331 */
332 kHllModuleEntry * addModule(
333 const char * pszName,
334 const void * pvLib,
335 unsigned cSegInfo = 0,
336 PHLLSEGINFO paSegInfo = NULL
337 );
338 kHllModuleEntry * addModule(
339 const char * pachName,
340 unsigned cchName,
341 const void * pvLib,
342 unsigned cSegInfo = 0,
343 PHLLSEGINFO paSegInfo = NULL
344 );
345 BOOL setModName(
346 const char * pszModName
347 );
348 BOOL setModName(
349 const char * pachModName,
350 int cchModName
351 );
352 const char * getModName();
353
354
355 /** @cat
356 * Output.
357 */
358 BOOL write(
359 const char *pszFilename
360 );
361 APIRET writeToLX(
362 const char *pszFilename
363 );
364 void writeSym(
365 kFile * pFile
366 ) throw(int);
367
368
369 /** @cat
370 * Static read function(s).
371 */
372 static kHll * readLX(
373 const char *pszFilename
374 );
375
376 static kHll * readLXExports(
377 kFileLX *FileLX
378 ) throw(int);
379
380 static kHll * readSym(
381 kFile *pFile,
382 kFileLX *pFileLX = NULL
383 ) throw(int);
384
385
386 /** @cat
387 * Get and queries.
388 */
389 int queryMaxObjectIndex();
390
391
392 /** @cat
393 * Debug dump function.
394 */
395 void dump(FILE *ph);
396 void ida(kFile *pFile) throw(int);
397};
398
399
400
401#endif
402
Note: See TracBrowser for help on using the repository browser.