"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

symbol.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "host.h"
#include "misc.h"
#include "target-pisa/ecoff.h"
#include "loader.h"
#include "symbol.h"

Include dependency graph for target-pisa/symbol.c:

Include dependency graph

Go to the source code of this file.

Defines

Functions

Variables


Define Documentation

#define RELEVANT_SCOPE SYM   
 

Value:

(                                                       \
 ((SYM)->flags & BSF_GLOBAL)                                            \
 || (                                                   \
     (((SYM)->flags & (BSF_LOCAL|BSF_DEBUGGING)) == BSF_LOCAL)          \
     && (SYM)->name[0] != '$')                                          \
 || (                                           \
     load_locals                                                        \
     && ((                                      \
          ((SYM)->flags&(BSF_LOCAL|BSF_DEBUGGING))==(BSF_LOCAL|BSF_DEBUGGING)\
          && (SYM)->name[0] == '$')                                     \
         || (                           \
             ((SYM)->flags & (BSF_LOCAL|BSF_DEBUGGING)) == (BSF_LOCAL)  \
             && (SYM)->name[0] == '$'))))

Definition at line 220 of file target-pisa/symbol.c.


Function Documentation

int acmp struct sym_sym_t **    sym1,
struct sym_sym_t **    sym2
[static]
 

Definition at line 208 of file target-pisa/symbol.c.

Referenced by sym_loadsyms().

00209 {
00210   return (int)((*sym1)->addr - (*sym2)->addr);
00211 }

int ncmp struct sym_sym_t **    sym1,
struct sym_sym_t **    sym2
[static]
 

Definition at line 215 of file target-pisa/symbol.c.

Referenced by sym_loadsyms().

00216 {
00217   return strcmp((*sym1)->name, (*sym2)->name);
00218 }

struct sym_sym_t* sym_bind_addr md_addr_t    addr,
int *    pindex,
int    exact,
enum sym_db_t    db
 

Definition at line 722 of file target-pisa/symbol.c.

References sym_sym_t::addr, MAX, panic(), sdb_any, sdb_data, sdb_text, sym_sym_t::size, sym_ndatasyms, sym_nsyms, and sym_ntextsyms.

Referenced by sim_main().

00726 {
00727   int nsyms, low, high, pos;
00728   struct sym_sym_t **syms;
00729 
00730   switch (db)
00731     {
00732     case sdb_any:
00733       syms = sym_syms;
00734       nsyms = sym_nsyms;
00735       break;
00736     case sdb_text:
00737       syms = sym_textsyms;
00738       nsyms = sym_ntextsyms;
00739       break;
00740     case sdb_data:
00741       syms = sym_datasyms;
00742       nsyms = sym_ndatasyms;
00743       break;
00744     default:
00745       panic("bogus symbol database");
00746     }
00747 
00748   /* any symbols to search? */
00749   if (!nsyms)
00750     {
00751       if (pindex)
00752         *pindex = -1;
00753       return NULL;
00754     }
00755 
00756   /* binary search symbol database (sorted by address) */
00757   low = 0;
00758   high = nsyms-1;
00759   pos = (low + high) >> 1;
00760   while (!(/* exact match */
00761            (exact && syms[pos]->addr == addr)
00762            /* in bounds match */
00763            || (!exact
00764                && syms[pos]->addr <= addr
00765                && addr < (syms[pos]->addr + MAX(1, syms[pos]->size)))))
00766     {
00767       if (addr < syms[pos]->addr)
00768         high = pos - 1;
00769       else
00770         low = pos + 1;
00771       if (high >= low)
00772         pos = (low + high) >> 1;
00773       else
00774         {
00775           if (pindex)
00776             *pindex = -1;
00777           return NULL;
00778         }
00779     }
00780 
00781   /* bound! */
00782   if (pindex)
00783     *pindex = pos;
00784   return syms[pos];
00785 }

struct sym_sym_t* sym_bind_name char *    name,
int *    pindex,
enum sym_db_t    db
 

Definition at line 791 of file target-pisa/symbol.c.

References panic(), sdb_any, sdb_data, sdb_text, sym_ndatasyms, sym_nsyms, and sym_ntextsyms.

Referenced by dlite_symbol(), ident_evaluator(), and range_parse_pos().

00794 {
00795   int nsyms, low, high, pos, cmp;
00796   struct sym_sym_t **syms;
00797 
00798   switch (db)
00799     {
00800     case sdb_any:
00801       syms = sym_syms_by_name;
00802       nsyms = sym_nsyms;
00803       break;
00804     case sdb_text:
00805       syms = sym_textsyms_by_name;
00806       nsyms = sym_ntextsyms;
00807       break;
00808     case sdb_data:
00809       syms = sym_datasyms_by_name;
00810       nsyms = sym_ndatasyms;
00811       break;
00812     default:
00813       panic("bogus symbol database");
00814     }
00815 
00816   /* any symbols to search? */
00817   if (!nsyms)
00818     {
00819       if (pindex)
00820         *pindex = -1;
00821       return NULL;
00822     }
00823 
00824   /* binary search symbol database (sorted by name) */
00825   low = 0;
00826   high = nsyms-1;
00827   pos = (low + high) >> 1;
00828   while (!(/* exact string match */!(cmp = strcmp(syms[pos]->name, name))))
00829     {
00830       if (cmp > 0)
00831         high = pos - 1;
00832       else
00833         low = pos + 1;
00834       if (high >= low)
00835         pos = (low + high) >> 1;
00836       else
00837         {
00838           if (pindex)
00839             *pindex = -1;
00840           return NULL;
00841         }
00842     }
00843 
00844   /* bound! */
00845   if (pindex)
00846     *pindex = pos;
00847   return syms[pos];
00848 }

void sym_dumpstate FILE *    fd
 

Definition at line 685 of file target-pisa/symbol.c.

References sym_dumpsym(), sym_ndatasyms, sym_nsyms, and sym_ntextsyms.

00686 {
00687   int i;
00688 
00689   if (fd == NULL)
00690     fd = stderr;
00691 
00692   fprintf(fd, "** All symbols sorted by address:\n");
00693   for (i=0; i < sym_nsyms; i++)
00694     sym_dumpsym(sym_syms[i], fd);
00695 
00696   fprintf(fd, "\n** All symbols sorted by name:\n");
00697   for (i=0; i < sym_nsyms; i++)
00698     sym_dumpsym(sym_syms_by_name[i], fd);
00699 
00700   fprintf(fd, "** Text symbols sorted by address:\n");
00701   for (i=0; i < sym_ntextsyms; i++)
00702     sym_dumpsym(sym_textsyms[i], fd);
00703 
00704   fprintf(fd, "\n** Text symbols sorted by name:\n");
00705   for (i=0; i < sym_ntextsyms; i++)
00706     sym_dumpsym(sym_textsyms_by_name[i], fd);
00707 
00708   fprintf(fd, "** Data symbols sorted by address:\n");
00709   for (i=0; i < sym_ndatasyms; i++)
00710     sym_dumpsym(sym_datasyms[i], fd);
00711 
00712   fprintf(fd, "\n** Data symbols sorted by name:\n");
00713   for (i=0; i < sym_ndatasyms; i++)
00714     sym_dumpsym(sym_datasyms_by_name[i], fd);
00715 }

void sym_dumpsym struct sym_sym_t   sym,
FILE *    fd
 

Definition at line 659 of file target-pisa/symbol.c.

References sym_sym_t::addr, sym_sym_t::initialized, sym_sym_t::local, sym_sym_t::name, sym_sym_t::pub, sym_sym_t::seg, sym_sym_t::size, and ss_data.

Referenced by dlite_dsymbols(), dlite_symbol(), dlite_symbols(), dlite_tsymbols(), sym_dumpstate(), and sym_dumpsyms().

00661 {
00662   fprintf(fd,
00663     "sym `%s': %s seg, init-%s, pub-%s, local-%s, addr=0x%08x, size=%d\n",
00664           sym->name,
00665           sym->seg == ss_data ? "data" : "text",
00666           sym->initialized ? "y" : "n",
00667           sym->pub ? "y" : "n",
00668           sym->local ? "y" : "n",
00669           sym->addr,
00670           sym->size);
00671 }

void sym_dumpsyms FILE *    fd
 

Definition at line 675 of file target-pisa/symbol.c.

References sym_dumpsym(), and sym_nsyms.

00676 {
00677   int i;
00678 
00679   for (i=0; i < sym_nsyms; i++)
00680     sym_dumpsym(sym_syms[i], fd);
00681 }

void sym_loadsyms char *    fname,
int    load_locals
 

Definition at line 238 of file target-pisa/symbol.c.

References acmp(), sym_sym_t::addr, ecoff_EXTR::asym, ecoff_symhdr_t::cbSsOffset, ecoff_filehdr::f_magic, ecoff_filehdr::f_symptr, FALSE, fatal(), ecoff_symhdr_t::iextMax, ecoff_SYMR::index, sym_sym_t::initialized, ecoff_SYMR::iss, ecoff_symhdr_t::issExtMax, ecoff_symhdr_t::issMax, ecoff_symhdr_t::isymMax, len, sym_sym_t::local, ecoff_symhdr_t::magic, mystrdup(), sym_sym_t::name, ncmp(), panic(), sym_sym_t::pub, RELEVANT_SCOPE, ecoff_SYMR::sc, sym_sym_t::seg, sym_sym_t::size, ss_data, ss_text, ecoff_SYMR::st, sym_ndatasyms, sym_nsyms, sym_ntextsyms, syms_loaded, TRUE, and ecoff_SYMR::value.

Referenced by dlite_dsymbols(), dlite_symbol(), dlite_symbols(), dlite_tsymbols(), ident_evaluator(), range_parse_pos(), and sim_reg_stats().

00240 {
00241   int i, debug_cnt;
00242 #ifdef BFD_LOADER
00243   bfd *abfd;
00244   asymbol **syms;
00245   int storage, i, nsyms, debug_cnt;
00246 #else /* !BFD_LOADER */
00247   int len;
00248   FILE *fobj;
00249   struct ecoff_filehdr fhdr;
00250   struct ecoff_aouthdr ahdr;
00251   struct ecoff_symhdr_t symhdr;
00252   char *strtab = NULL;
00253   struct ecoff_EXTR *extr;
00254 #endif /* BFD_LOADER */
00255 
00256   if (syms_loaded)
00257     {
00258       /* symbols are already loaded */
00259       /* FIXME: can't handle symbols from multiple files */
00260       return;
00261     }
00262 
00263 #ifdef BFD_LOADER
00264 
00265   /* load the program into memory, try both endians */
00266   if (!(abfd = bfd_openr(fname, "ss-coff-big")))
00267     if (!(abfd = bfd_openr(fname, "ss-coff-little")))
00268       fatal("cannot open executable `%s'", fname);
00269 
00270   /* this call is mainly for its side effect of reading in the sections.
00271      we follow the traditional behavior of `strings' in that we don't
00272      complain if we don't recognize a file to be an object file.  */
00273   if (!bfd_check_format(abfd, bfd_object))
00274     {
00275       bfd_close(abfd);
00276       fatal("cannot open executable `%s'", fname);
00277     }
00278 
00279   /* sanity check, endian should be the same as loader.c encountered */
00280   if (abfd->xvec->byteorder_big_p != (unsigned)ld_target_big_endian)
00281     panic("binary endian changed");
00282 
00283   if ((bfd_get_file_flags(abfd) & (HAS_SYMS|HAS_LOCALS)))
00284     {
00285       /* file has locals, read them in */
00286       storage = bfd_get_symtab_upper_bound(abfd);
00287       if (storage <= 0)
00288         fatal("HAS_SYMS is set, but `%s' still lacks symbols", fname);
00289 
00290       syms = (asymbol **)calloc(storage, 1);
00291       if (!syms)
00292         fatal("out of virtual memory");
00293 
00294       nsyms = bfd_canonicalize_symtab (abfd, syms);
00295       if (nsyms <= 0)
00296         fatal("HAS_SYMS is set, but `%s' still lacks symbols", fname);
00297 
00298       /*
00299        * convert symbols to local format
00300        */
00301 
00302       /* first count symbols */
00303       sym_ndatasyms = 0; sym_ntextsyms = 0;
00304       for (i=0; i < nsyms; i++)
00305         {
00306           asymbol *sym = syms[i];
00307 
00308           /* decode symbol type */
00309           if (/* from the data section */
00310               (!strcmp(sym->section->name, ".rdata")
00311                || !strcmp(sym->section->name, ".data")
00312                || !strcmp(sym->section->name, ".sdata")
00313                || !strcmp(sym->section->name, ".bss")
00314                || !strcmp(sym->section->name, ".sbss"))
00315               /* from a scope we are interested in */
00316               && RELEVANT_SCOPE(sym))
00317             {
00318               /* data segment symbol */
00319               sym_ndatasyms++;
00320 #ifdef PRINT_SYMS
00321               fprintf(stderr,
00322                       "+sym: %s  sect: %s  flags: %s  value: 0x%08lx\n",
00323                       sym->name, sym->section->name, flags2str(sym->flags),
00324                       sym->value + sym->section->vma);
00325 #endif /* PRINT_SYMS */
00326             }
00327           else if (/* from the text section */
00328                    !strcmp(sym->section->name, ".text")
00329                    /* from a scope we are interested in */
00330                    && RELEVANT_SCOPE(sym))
00331             {
00332               /* text segment symbol */
00333               sym_ntextsyms++;
00334 #ifdef PRINT_SYMS
00335               fprintf(stderr,
00336                       "+sym: %s  sect: %s  flags: %s  value: 0x%08lx\n",
00337                       sym->name, sym->section->name, flags2str(sym->flags),
00338                       sym->value + sym->section->vma);
00339 #endif /* PRINT_SYMS */
00340             }
00341           else
00342             {
00343               /* non-segment sections */
00344 #ifdef PRINT_SYMS
00345               fprintf(stderr,
00346                       "-sym: %s  sect: %s  flags: %s  value: 0x%08lx\n",
00347                       sym->name, sym->section->name, flags2str(sym->flags),
00348                       sym->value + sym->section->vma);
00349 #endif /* PRINT_SYMS */
00350             }
00351         }
00352       sym_nsyms = sym_ntextsyms + sym_ndatasyms;
00353       if (sym_nsyms <= 0)
00354         fatal("`%s' has no text or data symbols", fname);
00355 
00356       /* allocate symbol space */
00357       sym_db = (struct sym_sym_t *)calloc(sym_nsyms, sizeof(struct sym_sym_t));
00358       if (!sym_db)
00359         fatal("out of virtual memory");
00360 
00361       /* convert symbols to internal format */
00362       for (debug_cnt=0, i=0; i < nsyms; i++)
00363         {
00364           asymbol *sym = syms[i];
00365 
00366           /* decode symbol type */
00367           if (/* from the data section */
00368               (!strcmp(sym->section->name, ".rdata")
00369                || !strcmp(sym->section->name, ".data")
00370                || !strcmp(sym->section->name, ".sdata")
00371                || !strcmp(sym->section->name, ".bss")
00372                || !strcmp(sym->section->name, ".sbss"))
00373               /* from a scope we are interested in */
00374               && RELEVANT_SCOPE(sym))
00375             {
00376               /* data segment symbol, insert into symbol database */
00377               sym_db[debug_cnt].name = mystrdup((char *)sym->name);
00378               sym_db[debug_cnt].seg = ss_data;
00379               sym_db[debug_cnt].initialized =
00380                 (!strcmp(sym->section->name, ".rdata")
00381                  || !strcmp(sym->section->name, ".data")
00382                  || !strcmp(sym->section->name, ".sdata"));
00383               sym_db[debug_cnt].pub = (sym->flags & BSF_GLOBAL);
00384               sym_db[debug_cnt].local = (sym->name[0] == '$');
00385               sym_db[debug_cnt].addr = sym->value + sym->section->vma;
00386 
00387               debug_cnt++;
00388             }
00389           else if (/* from the text section */
00390                    !strcmp(sym->section->name, ".text")
00391                    /* from a scope we are interested in */
00392                    && RELEVANT_SCOPE(sym))
00393             {
00394               /* text segment symbol, insert into symbol database */
00395               sym_db[debug_cnt].name = mystrdup((char *)sym->name);
00396               sym_db[debug_cnt].seg = ss_text;
00397               sym_db[debug_cnt].initialized = /* seems reasonable */TRUE;
00398               sym_db[debug_cnt].pub = (sym->flags & BSF_GLOBAL);
00399               sym_db[debug_cnt].local = (sym->name[0] == '$');
00400               sym_db[debug_cnt].addr = sym->value + sym->section->vma;
00401 
00402               debug_cnt++;
00403             }
00404           else
00405             {
00406               /* non-segment sections */
00407             }
00408         }
00409       /* sanity check */
00410       if (debug_cnt != sym_nsyms)
00411         panic("could not locate all counted symbols");
00412 
00413       /* release bfd symbol storage */
00414       free(syms);
00415     }
00416 
00417   /* done with file, close if */
00418   if (!bfd_close(abfd))
00419     fatal("could not close executable `%s'", fname);
00420 
00421 #else /* !BFD_LOADER */
00422 
00423   /* load the program into memory, try both endians */
00424 #if defined(__CYGWIN32__) || defined(_MSC_VER)
00425   fobj = fopen(fname, "rb");
00426 #else
00427   fobj = fopen(fname, "r");
00428 #endif
00429   if (!fobj)
00430     fatal("cannot open executable `%s'", fname);
00431 
00432   if (fread(&fhdr, sizeof(struct ecoff_filehdr), 1, fobj) < 1)
00433     fatal("cannot read header from executable `%s'", fname);
00434 
00435   /* record endian of target */
00436   if (fhdr.f_magic != ECOFF_EB_MAGIC && fhdr.f_magic != ECOFF_EL_MAGIC)
00437     fatal("bad magic number in executable `%s'", fname);
00438 
00439   if (fread(&ahdr, sizeof(struct ecoff_aouthdr), 1, fobj) < 1)
00440     fatal("cannot read AOUT header from executable `%s'", fname);
00441 
00442   /* seek to the beginning of the symbolic header */
00443   fseek(fobj, fhdr.f_symptr, 0);
00444 
00445   if (fread(&symhdr, sizeof(struct ecoff_symhdr_t), 1, fobj) < 1)
00446     fatal("could not read symbolic header from executable `%s'", fname);
00447 
00448   if (symhdr.magic != ECOFF_magicSym)
00449     fatal("bad magic number (0x%x) in symbolic header", symhdr.magic);
00450 
00451   /* allocate space for the string table */
00452   len = symhdr.issMax + symhdr.issExtMax;
00453   strtab = (char *)calloc(len, sizeof(char));
00454   if (!strtab)
00455     fatal("out of virtual memory");
00456 
00457   /* read all the symbol names into memory */
00458   fseek(fobj, symhdr.cbSsOffset, 0);
00459   if (fread(strtab, len, 1, fobj) < 0)
00460     fatal("error while reading symbol table names");
00461 
00462   /* allocate symbol space */
00463   len = symhdr.isymMax + symhdr.iextMax;
00464   if (len <= 0)
00465     fatal("`%s' has no text or data symbols", fname);
00466   sym_db = (struct sym_sym_t *)calloc(len, sizeof(struct sym_sym_t));
00467   if (!sym_db)
00468     fatal("out of virtual memory");
00469 
00470   /* allocate space for the external symbol entries */
00471   extr =
00472     (struct ecoff_EXTR *)calloc(symhdr.iextMax, sizeof(struct ecoff_EXTR));
00473   if (!extr)
00474     fatal("out of virtual memory");
00475 
00476   fseek(fobj, symhdr.cbExtOffset, 0);
00477   if (fread(extr, sizeof(struct ecoff_EXTR), symhdr.iextMax, fobj) < 0)
00478     fatal("error reading external symbol entries");
00479 
00480   sym_nsyms = 0; sym_ndatasyms = 0; sym_ntextsyms = 0;
00481 
00482   /* convert symbols to internal format */
00483   for (i=0; i < symhdr.iextMax; i++)
00484     {
00485       int str_offset;
00486 
00487       str_offset = symhdr.issMax + extr[i].asym.iss;
00488 
00489 #if 0
00490       printf("ext %2d: ifd = %2d, iss = %3d, value = %8x, st = %3x, "
00491              "sc = %3x, index = %3x\n",
00492              i, extr[i].ifd,
00493              extr[i].asym.iss, extr[i].asym.value,
00494              extr[i].asym.st, extr[i].asym.sc,
00495              extr[i].asym.index);
00496       printf("       %08x %2d %2d %s\n",
00497              extr[i].asym.value,
00498              extr[i].asym.st,
00499              extr[i].asym.sc,
00500              &strtab[str_offset]);
00501 #endif
00502 
00503       switch (extr[i].asym.st)
00504         {
00505         case ECOFF_stGlobal:
00506         case ECOFF_stStatic:
00507           /* from data segment */
00508           sym_db[sym_nsyms].name = mystrdup(&strtab[str_offset]);
00509           sym_db[sym_nsyms].seg = ss_data;
00510           sym_db[sym_nsyms].initialized = /* FIXME: ??? */TRUE;
00511           sym_db[sym_nsyms].pub = /* FIXME: ??? */TRUE;
00512           sym_db[sym_nsyms].local = /* FIXME: ??? */FALSE;
00513           sym_db[sym_nsyms].addr = extr[i].asym.value;
00514           sym_nsyms++;
00515           sym_ndatasyms++;
00516           break;
00517 
00518         case ECOFF_stProc:
00519         case ECOFF_stStaticProc:
00520         case ECOFF_stLabel:
00521           /* from text segment */
00522           sym_db[sym_nsyms].name = mystrdup(&strtab[str_offset]);
00523           sym_db[sym_nsyms].seg = ss_text;
00524           sym_db[sym_nsyms].initialized = /* FIXME: ??? */TRUE;
00525           sym_db[sym_nsyms].pub = /* FIXME: ??? */TRUE;
00526           sym_db[sym_nsyms].local = /* FIXME: ??? */FALSE;
00527           sym_db[sym_nsyms].addr = extr[i].asym.value;
00528           sym_nsyms++;
00529           sym_ntextsyms++;
00530           break;
00531 
00532         default:
00533           /* FIXME: ignored... */;
00534         }
00535     }
00536   free(extr);
00537 
00538   /* done with the executable, close it */
00539   if (fclose(fobj))
00540     fatal("could not close executable `%s'", fname);
00541 
00542 #endif /* BFD_LOADER */
00543 
00544   /*
00545    * generate various sortings
00546    */
00547 
00548   /* all symbols sorted by address and name */
00549   sym_syms =
00550     (struct sym_sym_t **)calloc(sym_nsyms, sizeof(struct sym_sym_t *));
00551   if (!sym_syms)
00552     fatal("out of virtual memory");
00553 
00554   sym_syms_by_name =
00555     (struct sym_sym_t **)calloc(sym_nsyms, sizeof(struct sym_sym_t *));
00556   if (!sym_syms_by_name)
00557     fatal("out of virtual memory");
00558 
00559   for (debug_cnt=0, i=0; i<sym_nsyms; i++)
00560     {
00561       sym_syms[debug_cnt] = &sym_db[i];
00562       sym_syms_by_name[debug_cnt] = &sym_db[i];
00563       debug_cnt++;
00564     }
00565   /* sanity check */
00566   if (debug_cnt != sym_nsyms)
00567     panic("could not locate all symbols");
00568 
00569   /* sort by address */
00570   qsort(sym_syms, sym_nsyms, sizeof(struct sym_sym_t *), (void *)acmp);
00571 
00572   /* sort by name */
00573   qsort(sym_syms_by_name, sym_nsyms, sizeof(struct sym_sym_t *), (void *)ncmp);
00574 
00575   /* text segment sorted by address and name */
00576   sym_textsyms =
00577     (struct sym_sym_t **)calloc(sym_ntextsyms, sizeof(struct sym_sym_t *));
00578   if (!sym_textsyms)
00579     fatal("out of virtual memory");
00580 
00581   sym_textsyms_by_name =
00582     (struct sym_sym_t **)calloc(sym_ntextsyms, sizeof(struct sym_sym_t *));
00583   if (!sym_textsyms_by_name)
00584     fatal("out of virtual memory");
00585 
00586   for (debug_cnt=0, i=0; i<sym_nsyms; i++)
00587     {
00588       if (sym_db[i].seg == ss_text)
00589         {
00590           sym_textsyms[debug_cnt] = &sym_db[i];
00591           sym_textsyms_by_name[debug_cnt] = &sym_db[i];
00592           debug_cnt++;
00593         }
00594     }
00595   /* sanity check */
00596   if (debug_cnt != sym_ntextsyms)
00597     panic("could not locate all text symbols");
00598 
00599   /* sort by address */
00600   qsort(sym_textsyms, sym_ntextsyms, sizeof(struct sym_sym_t *), (void *)acmp);
00601 
00602   /* sort by name */
00603   qsort(sym_textsyms_by_name, sym_ntextsyms,
00604         sizeof(struct sym_sym_t *), (void *)ncmp);
00605 
00606   /* data segment sorted by address and name */
00607   sym_datasyms =
00608     (struct sym_sym_t **)calloc(sym_ndatasyms, sizeof(struct sym_sym_t *));
00609   if (!sym_datasyms)
00610     fatal("out of virtual memory");
00611 
00612   sym_datasyms_by_name =
00613     (struct sym_sym_t **)calloc(sym_ndatasyms, sizeof(struct sym_sym_t *));
00614   if (!sym_datasyms_by_name)
00615     fatal("out of virtual memory");
00616 
00617   for (debug_cnt=0, i=0; i<sym_nsyms; i++)
00618     {
00619       if (sym_db[i].seg == ss_data)
00620         {
00621           sym_datasyms[debug_cnt] = &sym_db[i];
00622           sym_datasyms_by_name[debug_cnt] = &sym_db[i];
00623           debug_cnt++;
00624         }
00625     }
00626   /* sanity check */
00627   if (debug_cnt != sym_ndatasyms)
00628     panic("could not locate all data symbols");
00629       
00630   /* sort by address */
00631   qsort(sym_datasyms, sym_ndatasyms, sizeof(struct sym_sym_t *), (void *)acmp);
00632 
00633   /* sort by name */
00634   qsort(sym_datasyms_by_name, sym_ndatasyms,
00635         sizeof(struct sym_sym_t *), (void *)ncmp);
00636 
00637   /* compute symbol sizes */
00638   for (i=0; i<sym_ntextsyms; i++)
00639     {
00640       sym_textsyms[i]->size =
00641         (i != (sym_ntextsyms - 1)
00642          ? (sym_textsyms[i+1]->addr - sym_textsyms[i]->addr)
00643          : ((ld_text_base + ld_text_size) - sym_textsyms[i]->addr));
00644     }
00645   for (i=0; i<sym_ndatasyms; i++)
00646     {
00647       sym_datasyms[i]->size =
00648         (i != (sym_ndatasyms - 1)
00649          ? (sym_datasyms[i+1]->addr - sym_datasyms[i]->addr)
00650          : ((ld_data_base + ld_data_size) - sym_datasyms[i]->addr));
00651     }
00652 
00653   /* symbols are now available for use */
00654   syms_loaded = TRUE;
00655 }


Variable Documentation

struct sym_sym_t** sym_datasyms = NULL
 

Definition at line 107 of file target-pisa/symbol.c.

struct sym_sym_t** sym_datasyms_by_name = NULL
 

Definition at line 110 of file target-pisa/symbol.c.

struct sym_sym_t* sym_db = NULL
 

Definition at line 89 of file target-pisa/symbol.c.

int sym_ndatasyms = 0
 

Definition at line 106 of file target-pisa/symbol.c.

Referenced by sym_bind_addr(), sym_bind_name(), sym_dumpstate(), and sym_loadsyms().

int sym_nsyms = 0
 

Definition at line 92 of file target-pisa/symbol.c.

Referenced by sym_bind_addr(), sym_bind_name(), sym_dumpstate(), sym_dumpsyms(), and sym_loadsyms().

int sym_ntextsyms = 0
 

Definition at line 99 of file target-pisa/symbol.c.

Referenced by sym_bind_addr(), sym_bind_name(), sym_dumpstate(), and sym_loadsyms().

struct sym_sym_t** sym_syms = NULL
 

Definition at line 93 of file target-pisa/symbol.c.

struct sym_sym_t** sym_syms_by_name = NULL
 

Definition at line 96 of file target-pisa/symbol.c.

struct sym_sym_t** sym_textsyms = NULL
 

Definition at line 100 of file target-pisa/symbol.c.

struct sym_sym_t** sym_textsyms_by_name = NULL
 

Definition at line 103 of file target-pisa/symbol.c.

int syms_loaded = FALSE [static]
 

Definition at line 113 of file target-pisa/symbol.c.

Referenced by sym_loadsyms().



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214