Back to index

lightning-sunbird  0.9+nobinonly
Typedefs | Functions
sym_file.h File Reference
#include <Files.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct sym_file

Functions

sym_fileopen_sym_file (const FSSpec *symSpec)
void close_sym_file (sym_file *symbols)
int get_source (sym_file *symbols, UInt32 codeOffset, char symbolName[256], char fileName[256], UInt32 *fileOffset)

Typedef Documentation

typedef struct sym_file

Definition at line 47 of file sym_file.h.


Function Documentation

void close_sym_file ( sym_file symbols)

Definition at line 349 of file SymFiles.cpp.

{
       if (symbols != NULL) {
              delete symbols;
       }
}

Here is the caller graph for this function:

int get_source ( sym_file symbols,
UInt32  codeOffset,
char  symbolName[256],
char  fileName[256],
UInt32 fileOffset 
)

Definition at line 257 of file SymFiles.cpp.

{
       const DiskSymbolHeaderBlock& header = symbols->mHeader;
       const ResourceTableEntry& codeEntry = symbols->mCodeEntry;

       // since module entries can't span pages, must compute which page module entry size.
       UInt32 modulesPerPage = (header.dshb_page_size / sizeof(ModulesTableEntry));

       // search for MTE nearest specified offset.
       // seek to first MTE.
       for (UInt16 i = codeEntry.rte_mte_first; i <= codeEntry.rte_mte_last; i++) {
              ModulesTableEntry moduleEntry;
              UInt32 modulePage = (i / modulesPerPage);
              UInt32 moduleIndex = (i % modulesPerPage);
              symbols->seek((header.dshb_mte.dti_first_page + modulePage) * header.dshb_page_size + moduleIndex * sizeof(ModulesTableEntry));
              if (symbols->read(&moduleEntry, sizeof(moduleEntry)) == sizeof(moduleEntry)) {
                     if (isMeatyModule(moduleEntry) && (codeOffset >= moduleEntry.mte_res_offset) && (codeOffset - moduleEntry.mte_res_offset) < moduleEntry.mte_size) {
                            FileReferenceTableEntry frte;
                            if (getFileReferenceTableEntry(symbols, moduleEntry.mte_imp_fref, &frte)) {
                                   UInt32 length;
                                   // get the name of the symbol.
                                   const UInt8* moduleName = symbols->getName(moduleEntry.mte_nte_index);
                                   // printf("module name = %#s\n", moduleName);
                                   // trim off the leading "."
                                   length = moduleName[0] - 1;
                                   BlockMoveData(moduleName + 2, symbolName, length);
                                   symbolName[length] = '\0';
                                   // get the name of the file.
                                   const UInt8* name = symbols->getName(frte.frte_fn.nte_index);
                                   length = name[0];
                                   BlockMoveData(name + 1, fileName, length);
                                   fileName[length] = '\0';
                                   // printf("file name = %s\n", fileName);
                                   // try to refine the location, using the contained statements table entries.
                                   UInt32 closestFileOffset = moduleEntry.mte_imp_fref.fref_offset;
                                   UInt32 closestCodeOffset = moduleEntry.mte_res_offset;
                                   UInt32 closestCodeDelta = 0xFFFFFFFF;
                                   UInt32 currentFileOffset, currentCodeOffset = moduleEntry.mte_res_offset, currentCodeDelta;
                                   for (UInt32 j = moduleEntry.mte_csnte_idx_1; j <= moduleEntry.mte_csnte_idx_2; j++) {
                                          // only consider offsets less than the actual code offset, so we'll be sure
                                          // to match the nearest line before the code offset. this could probably be
                                          // a termination condition as well.
                                          if (currentCodeOffset > codeOffset)
                                                 break;
                                          ContainedStatementsTableEntry statementEntry;
                                          if (getContainedStatementTableEntry(symbols, j, &statementEntry)) {
                                                 switch (statementEntry.csnte_file.change) {
                                                 case kSourceFileChange:
                                                        currentFileOffset = statementEntry.csnte_file.fref.fref_offset;
                                                        break;
                                                 case kEndOfList:
                                                        break;
                                                 default:
                                                        currentFileOffset += statementEntry.csnte.file_delta;
                                                        currentCodeOffset = moduleEntry.mte_res_offset + statementEntry.csnte.mte_offset;
                                                        if (currentCodeOffset <= codeOffset) {
                                                               currentCodeDelta = delta(currentCodeOffset, codeOffset);
                                                               if (currentCodeDelta < closestCodeDelta) {
                                                                      closestFileOffset = currentFileOffset;
                                                                      closestCodeOffset = currentCodeOffset;
                                                                      closestCodeDelta = currentCodeDelta;
                                                               }
                                                        }
                                                        break;
                                                 }
                                          }
                                   }
                                   *fileOffset = closestFileOffset;
                                   // printf("closest file offset = %d\n", closestFileOffset);
                                   // printf("closest code offset = %d\n", closestCodeOffset);
                                   return 1;
                            }
                     }
              }
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 335 of file SymFiles.cpp.

{
       sym_file* symbols = new sym_file(symSpec);
       if (symbols != NULL) {
              if (!symbols->init()) {
                     delete symbols;
                     return NULL;
              }
              // don't leave the file open, if possible.
              symbols->close();
       }
       return symbols;
}

Here is the call graph for this function:

Here is the caller graph for this function: