Changeset 13909


Ignore:
Timestamp:
Apr 7, 2000, 4:47:01 AM (25 years ago)
Author:
bird
Message:

Implemented Source/Linenumbers.

Location:
tags/trunk/tools/dbginfo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified tags/trunk/tools/dbginfo/kHll.cpp

    r13863 r13909  
    1 /* $Id: kHll.cpp,v 1.9 2000-03-31 15:35:09 bird Exp $
     1/* $Id: kHll.cpp,v 1.10 2000-04-07 02:47:00 bird Exp $
    22 *
    33 * kHll - Implementation of the class kHll.
     
    146146/**
    147147 * Write this entry to file.
    148  * @returns   Number of bytes written.
    149  * @param     phFile    File handle.
     148 * @returns   Count of bytes written (on success).
     149 *            -3    Invalid offsets.
     150 *            -2    Seek error.
     151 *            -1    Write error.
     152 *            0     No data written. Concidered as an error!
     153 * @param     phFile    Filehandle.
    150154 */
    151155int kHllPubSymEntry::write(FILE *phFile)
     
    156160                  offsetof(HLLPUBLICSYM, achName) + pPubSym->cchName,
    157161                  phFile);
     162}
     163
     164
     165
     166
     167
     168
     169
     170/*******************************************************************************
     171*                                                                              *
     172*   kHllLineNumberChunk                                                        *
     173*                                                                              *
     174*   kHllLineNumberChunk                                                        *
     175*                                                                              *
     176*******************************************************************************/
     177
     178
     179
     180
     181    int                 cLines;
     182    PHLLLINENUMBERENTRY paLines;
     183    HLLFIRSTENTRY       FirstEntry;
     184
     185/**
     186 * Constructor.
     187 * @param     iSeg      Segment number for these linenumbers.
     188 * @param     offBase   Base offset for all line number offsets. (defaults to 0)
     189 */
     190kHllLineNumberChunk::kHllLineNumberChunk(
     191    unsigned short int iSeg,
     192    unsigned long int offBase /*= 0*/
     193    )
     194{
     195    memset(&FirstEntry, 0, sizeof(FirstEntry));
     196    FirstEntry.hll04.iSeg = iSeg;
     197    FirstEntry.hll04.u1.offBase = offBase;
     198    FirstEntry.hll04.uchType = 0;
     199}
     200
     201
     202
     203/**
     204 * Destructor.
     205 */
     206kHllLineNumberChunk::~kHllLineNumberChunk()
     207{
     208    if (paLines != NULL)
     209        free(paLines);
     210    paLines = 0;
     211    FirstEntry.hll04.cEntries = 0;
     212}
     213
     214
     215
     216/**
     217 * Adds a line information.
     218 * @returns   Success indicator.
     219 * @param     iusFile       File index.
     220 * @param     usLine        Line number
     221 * @param     off           Offset into object.
     222 */
     223BOOL                kHllLineNumberChunk::addLineInfo(
     224                        unsigned short int  iusFile,
     225                        unsigned short int  usLine,
     226                        unsigned long int   off
     227                        )
     228{
     229    /*
     230     * Allocate more memory?
     231     */
     232    if (FirstEntry.hll04.cEntries % 20 == 0)
     233        {
     234        void *pv = realloc(paLines, (FirstEntry.hll04.cEntries + 20) * sizeof(paLines[0].hll04));
     235        assert(pv != NULL);
     236        if (pv == NULL)
     237            return FALSE;
     238        paLines = (PHLLLINENUMBERENTRY)pv;
     239        }
     240
     241    /*
     242     * Add line info entry.
     243     */
     244    paLines[FirstEntry.hll04.cEntries].hll04.iusSourceFile  = iusFile;
     245    paLines[FirstEntry.hll04.cEntries].hll04.off            = off;
     246    paLines[FirstEntry.hll04.cEntries].hll04.usLine         = usLine;
     247    FirstEntry.hll04.cEntries++;
     248
     249    return FALSE;
     250}
     251
     252
     253/**
     254 * Write this entry to file.
     255 * @returns   Count of bytes written (on success).
     256 *            -3    Invalid offsets.
     257 *            -2    Seek error.
     258 *            -1    Write error.
     259 *            0     No data written. Concidered as an error!
     260 * @param     phFile    Filehandle.
     261 */
     262int     kHllLineNumberChunk::write(FILE *phFile)
     263{
     264    int cb;
     265    int cbWritten;
     266
     267    /*
     268     * First entry
     269     */
     270    cb = sizeof(paLines[0])*FirstEntry.hll04.cEntries;
     271    cbWritten = fwrite(&FirstEntry, 1, cb, phFile);
     272    if (cbWritten != cb)
     273        return -1;
     274
     275    /*
     276     * Line array.
     277     */
     278    cb = sizeof(paLines[0])*FirstEntry.hll04.cEntries;
     279    cbWritten = fwrite(paLines, 1, cb, phFile);
     280    if (cbWritten != cb)
     281        return -1;
     282
     283    return cbWritten + sizeof(FirstEntry.hll04);
     284}
     285
     286
     287
     288
     289
     290/*******************************************************************************
     291*                                                                              *
     292*   kHllSrcEntry                                                               *
     293*                                                                              *
     294*   kHllSrcEntry                                                               *
     295*                                                                              *
     296*******************************************************************************/
     297
     298
     299
     300
     301
     302/**
     303 * Constructor.
     304 */
     305kHllSrcEntry::kHllSrcEntry()
     306    :
     307    cFilenames(0),
     308    pachFilenames(NULL),
     309    cbFilenames(0),
     310    cbFilenamesAllocated(0)
     311{
     312}
     313
     314
     315/**
     316 * Destructor.
     317 */
     318kHllSrcEntry::~kHllSrcEntry()
     319{
     320    if (pachFilenames != NULL)
     321        free(pachFilenames);
     322    pachFilenames = NULL;
     323    cFilenames = cbFilenames = cbFilenamesAllocated = 0;
     324}
     325
     326
     327
     328/**
     329 * Add/queries a Linenumber chunk.
     330 * A linenumber chunk is a collection of linenumber information for a
     331 * module segement.
     332 * @returns   Pointer to linenumber chunk which you may add linenumber info to.
     333 *            NULL on failiure.
     334 * @param     iSeg      Segment number for these linenumbers.
     335 * @param     offBase   Base offset for all line number offsets. (defaults to 0)
     336 */
     337kHllLineNumberChunk *
     338                    kHllSrcEntry::addLineNumberChunk(
     339                        unsigned short int  iSeg,
     340                        unsigned long int   offBase/* = 0*/
     341                        )
     342{
     343    kHllLineNumberChunk *pChunk;
     344
     345    /*
     346     * Try find existing chunk.
     347     */
     348    pChunk = Lines.getFirst();
     349    while (pChunk != NULL && pChunk->getSeg() != iSeg)
     350        pChunk = (kHllLineNumberChunk*)pChunk->getNext();
     351
     352    /*
     353     * If not found, then create a new one and add it to the list.
     354     */
     355    if (pChunk != NULL)
     356    {
     357        pChunk = new kHllLineNumberChunk(iSeg, offBase);
     358        assert(pChunk != NULL);
     359        if (pChunk != NULL)
     360            Lines.insert(pChunk);
     361    }
     362
     363    return pChunk;
     364}
     365
     366
     367
     368/**
     369 * Adds a file for this module.
     370 * @returns   Filename index used when adding linenumbers.
     371 * @param     pszFilename  Pointer to filaname string.
     372 */
     373unsigned short      kHllSrcEntry::addFile(
     374                        const char *        pszFilename
     375                        )
     376{
     377    return addFile(pszFilename, strlen(pszFilename));
     378}
     379
     380
     381
     382/**
     383 * Adds a file for this module.
     384 * @returns   Filename index used when adding linenumbers.
     385 *            0 on error.
     386 * @param     pachFilename  Pointer to filaname string (not zero terminated).
     387 * @param     cchFilename   Length of filename.
     388 */
     389unsigned short      kHllSrcEntry::addFile(
     390                        const char *        pachFilename,
     391                        int                 cchFilename
     392                        )
     393{
     394    assert(pachFilename != NULL);
     395    assert(cchFilename < 256);
     396    if (cchFilename >= 256)
     397        cchFilename = 255;
     398
     399    /*
     400     * Allocate more memory?
     401     */
     402    if ((cbFilenames + cchFilename + 1) >= cbFilenamesAllocated)
     403    {
     404        void *pv = realloc(pachFilenames, cbFilenamesAllocated + 256);
     405        assert(pv != NULL);
     406        if (pv == NULL)
     407            return 0;
     408        pachFilenames = (char*)pv;
     409        cbFilenamesAllocated += 256;
     410    }
     411
     412
     413    /*
     414     * Add filename
     415     */
     416    pachFilenames[cbFilenames++] = cchFilename;
     417    memcpy(&pachFilenames[cbFilenames], pachFilename, cchFilename);
     418    cbFilenames += cchFilename;
     419
     420    return ++cFilenames;
     421}
     422
     423
     424
     425/**
     426 * Write this entry to file.
     427 * @returns   Count of bytes written (on success).
     428 *            -3    Invalid offsets.
     429 *            -2    Seek error.
     430 *            -1    Write error.
     431 *            0     No data written. Concidered as an error!
     432 * @param     phFile    Filehandle.
     433 */
     434int                 kHllSrcEntry::write(FILE *phFile)
     435{
     436    HLLFIRSTENTRY       FirstEntry;
     437    HLLFILENAMEENTRY    FilenameEntry;
     438    int                 cb;
     439    int                 cbWrote;
     440    int                 cbWritten;
     441
     442    /*
     443     *  Filenames - if no filename present we'll add a dummy filename!
     444     *      First entry for the filenames.
     445     *      Filename entry header.
     446     *      Write filename entries.
     447     */
     448    FirstEntry.hll04.usLine = 0;
     449    FirstEntry.hll04.uchType = 3;       /* filename */
     450    FirstEntry.hll04.uchReserved = 0;
     451    FirstEntry.hll04.cEntries = max(cFilenames, 1);
     452    FirstEntry.hll04.iSeg = 0;
     453    FirstEntry.hll04.u1.cbFileNameTable = cbFilenames > 0 ? cbFilenames : 8;
     454    cb = sizeof(FirstEntry.hll04);
     455    cbWritten = cbWrote = fwrite(&FirstEntry, 1, cb, phFile);
     456    if (cb != cbWrote)
     457        return -1;
     458
     459    FilenameEntry.cSourceFiles = max(cFilenames, 1);
     460    FilenameEntry.offSource = 0;
     461    FilenameEntry.cSourceRecords = 0;
     462    cb = offsetof(HLLFILENAMEENTRY, cchName);
     463    cbWritten += cbWrote = fwrite(&FilenameEntry, 1, cb, phFile);
     464    if (cbWrote != cb)
     465        return -1;
     466
     467    if (cbFilenames > 0)
     468    {
     469        cbWritten += cbWrote = fwrite(pachFilenames, 1, cbFilenames, phFile);
     470        if (cbWrote != cbFilenames)
     471            return -1;
     472    }
     473    else
     474    {   /* no filename - write dummy empty */
     475        cbWritten += cbWrote = fwrite("\07dummy.c", 1, 8, phFile);
     476        if (cbWrote != 8)
     477            return -1;
     478    }
     479
     480
     481    /*
     482     * Write linenumbers.
     483     */
     484    if (Lines.getFirst() != NULL)
     485    {
     486        cbWritten += cbWrote = kHllBaseEntry::writeList(phFile, Lines.getFirst());
     487        if (cbWrote < 0)
     488            return cbWrote;
     489    }
     490
     491    return cbWritten;
    158492}
    159493
     
    369703/**
    370704 * Write this HLL entry to file.
    371  * @returns   Count of bytes written. -1 on error.
     705 * @returns   Count of bytes written.
     706 *            -3    Invalid offsets.
     707 *            -2    Seek error.
     708 *            -1    Write error.
    372709 * @param     phFile    Filehandle.
    373710 * @param     off       Current offset into the HLL data.
     
    425762    cchWritten += cch;
    426763    off += cch;
     764    */
    427765
    428766    offSource = off;
    429     cbSource = cch = kHllBaseEntry::writeList(phFile, Source.getFirst());
     767    cbSource = cch = Source.write(phFile);
    430768    if (cch < 0)
    431769        return cch;
    432770    cchWritten += cch;
    433771    off += cch;
    434     */
    435772
    436773    /*
     
    519856        cchWritten += cch;
    520857    }
     858    */
    521859
    522860    if (cbSource > 0)
     
    532870    }
    533871
    534     */
    535872
    536873    return cchWritten;
  • TabularUnified tags/trunk/tools/dbginfo/kHll.h

    r13900 r13909  
    1 /* $Id: kHll.h,v 1.6 2000-04-05 18:45:21 bird Exp $
     1/* $Id: kHll.h,v 1.7 2000-04-07 02:47:01 bird Exp $
    22 *
    33 * kHll - Declarations of the class kHll.
     
    6767
    6868/**
     69 * Linenumber chunk.
     70 * @author      knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
     71 */
     72class kHllLineNumberChunk : public kHllBaseEntry
     73{
     74private:
     75    PHLLLINENUMBERENTRY paLines;
     76    HLLFIRSTENTRY       FirstEntry;
     77
     78public:
     79    kHllLineNumberChunk(
     80        unsigned short int  iSeg,
     81        unsigned long int   offBase = 0
     82        );
     83    ~kHllLineNumberChunk();
     84
     85    BOOL            addLineInfo(
     86                        unsigned short int  iusFile,
     87                        unsigned short int  usLine,
     88                        unsigned long int   off
     89                        );
     90
     91    int             write(FILE *phFile);
     92    int             getSeg()    { return FirstEntry.hll04.iSeg; }
     93};
     94
     95
     96/**
    6997 * HLL Source entry.
    70  * @shortdesc
    71  * @dstruct
    72  * @version
    73  * @verdesc
    74  * @author      knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    75  * @approval
     98 * @author      knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    7699 */
    77100class kHllSrcEntry
    78101{
    79102private:
    80     int                 cFilenames;
    81     char *              pchFilenames;
    82 
    83     int                 cLines;
    84     HLLLINENUMBERENTRY  paLines;
    85 
    86 public:
    87 
     103    unsigned long int   cFilenames;
     104    char *              pachFilenames;
     105    unsigned long int   cbFilenames;
     106    unsigned long int   cbFilenamesAllocated;
     107
     108    kList<kHllLineNumberChunk>
     109                        Lines;
     110
     111public:
     112    kHllSrcEntry();
    88113    ~kHllSrcEntry();
    89114
    90     BOOL            addLineInfo(
    91                         int                 iFile,
    92                         int                 iLine,
    93                         unsigned short int  iObject,
    94                         unsigned long int   off
    95                         );
    96     int             addFile(
    97                         const char *        pszFilename,
    98 
    99                         );
    100 
     115    kHllLineNumberChunk *
     116                    addLineNumberChunk(
     117                        unsigned short int  iSeg,
     118                        unsigned long int   offBase = 0
     119                        );
     120    unsigned short  addFile(
     121                        const char *        pszFilename
     122                        );
     123    unsigned short  addFile(
     124                        const char *        pachFilename,
     125                        int                 cchFilename
     126                        );
    101127    int             write(FILE *phFile);
    102128};
     
    123149    kList<kHllTypeEntry>        Types;
    124150    kList<kHllSymEntry>         Symbols;
    125     kList<kHllSrcEntry>         Source;
    126151    */
     152    kHllSrcEntry                Source;
    127153
    128154    BOOL                        fValidOffsetsAndSizes;
     
    180206                        const void *        pvType
    181207                        );
     208    kHllSrcEntry *  getSourceEntry()    { return &Source; }
    182209
    183210
Note: See TracChangeset for help on using the changeset viewer.