📄 mips-tdump.c
字号:
(used) ? " " : "* ", auxi, (long) u.isym, (long) u.rndx.rfd, (long) u.rndx.index, u.ti.bt, u.ti.fBitfield, u.ti.continued, u.ti.tq0, u.ti.tq1, u.ti.tq2, u.ti.tq3, u.ti.tq4, u.ti.tq5);}/* Write aggregate information to a string. */voidemit_aggregate (string, u, u2, which, fdp) char *string; AUXU u; AUXU u2; const char *which; FDR *fdp;{ unsigned int ifd = u.rndx.rfd; unsigned int index = u.rndx.index; const char *name; if (ifd == ST_RFDESCAPE) ifd = u2.isym; /* An ifd of -1 is an opaque type. An escaped index of 0 is a struct return type of a procedure compiled without -g. */ if (ifd == 0xffffffff || (u.rndx.rfd == ST_RFDESCAPE && index == 0)) name = "<undefined>"; else if (index == indexNil) name = "<no name>"; else { if (fdp == 0 || sym_hdr.crfd == 0) fdp = &file_desc[ifd]; else fdp = &file_desc[rfile_desc[fdp->rfdBase + ifd]]; name = &l_strings[fdp->issBase + l_symbols[index + fdp->isymBase].iss]; } sprintf (string, "%s %s { ifd = %u, index = %u }", which, name, ifd, index);}/* Print out information about a file descriptor, and the symbols, procedures, and line numbers within it. */voidprint_file_desc (fdp, number) FDR *fdp; int number;{ char *str_base; AUXU *aux_base; int symi, pdi; int width = 20; char *used_base; str_base = l_strings + fdp->issBase; aux_base = aux_symbols + fdp->iauxBase; used_base = aux_used + (aux_base - aux_symbols); printf ("\nFile #%d, \"%s\"\n\n", number, str_base + fdp->rss); printf (" Name index = %-10ld Readin = %s\n", (long) fdp->rss, (fdp->fReadin) ? "Yes" : "No"); printf (" Merge = %-10s Endian = %s\n", (fdp->fMerge) ? "Yes" : "No", (fdp->fBigendian) ? "BIG" : "LITTLE"); printf (" Debug level = %-10s Language = %s\n", glevel_to_string (fdp->glevel), lang_to_string((lang_t) fdp->lang)); printf (" Adr = 0x%08lx\n\n", (long) fdp->adr); printf(" %-*s %11s %11s %11s %11s\n", width, "Info", "Start", "Number", "Size", "Offset"); printf(" %-*s %11s %11s %11s %11s\n", width, "====", "=====", "======", "====", "======"); printf(" %-*s %11lu %11lu %11lu %11lu\n", width, "Local strings", (ulong) fdp->issBase, (ulong) fdp->cbSs, (ulong) fdp->cbSs, (ulong) (fdp->issBase + sym_hdr.cbSsOffset)); printf(" %-*s %11lu %11lu %11lu %11lu\n", width, "Local symbols", (ulong) fdp->isymBase, (ulong) fdp->csym, (ulong) (fdp->csym * sizeof (SYMR)), (ulong) (fdp->isymBase * sizeof (SYMR) + sym_hdr.cbSymOffset)); printf(" %-*s %11lu %11lu %11lu %11lu\n", width, "Line numbers", (ulong) fdp->cbLineOffset, (ulong) fdp->cline, (ulong) fdp->cbLine, (ulong) (fdp->cbLineOffset + sym_hdr.cbLineOffset)); printf(" %-*s %11lu %11lu %11lu %11lu\n", width, "Optimization symbols", (ulong) fdp->ioptBase, (ulong) fdp->copt, (ulong) (fdp->copt * sizeof (OPTR)), (ulong) (fdp->ioptBase * sizeof (OPTR) + sym_hdr.cbOptOffset)); printf(" %-*s %11lu %11lu %11lu %11lu\n", width, "Procedures", (ulong) fdp->ipdFirst, (ulong) fdp->cpd, (ulong) (fdp->cpd * sizeof (PDR)), (ulong) (fdp->ipdFirst * sizeof (PDR) + sym_hdr.cbPdOffset)); printf(" %-*s %11lu %11lu %11lu %11lu\n", width, "Auxiliary symbols", (ulong) fdp->iauxBase, (ulong) fdp->caux, (ulong) (fdp->caux * sizeof (AUXU)), (ulong) (fdp->iauxBase * sizeof(AUXU) + sym_hdr.cbAuxOffset)); printf(" %-*s %11lu %11lu %11lu %11lu\n", width, "Relative Files", (ulong) fdp->rfdBase, (ulong) fdp->crfd, (ulong) (fdp->crfd * sizeof (ulong)), (ulong) (fdp->rfdBase * sizeof(ulong) + sym_hdr.cbRfdOffset)); if (want_scope && cur_scope != (scope_t *) 0) printf ("\n Warning scope does not start at 0!\n"); /* * print the info about the symbol table. */ printf ("\n There are %lu local symbols, starting at %lu\n", (ulong) fdp->csym, (ulong) (fdp->isymBase + sym_hdr.cbSymOffset)); for(symi = fdp->isymBase; symi < (fdp->csym + fdp->isymBase); symi++) print_symbol (&l_symbols[symi], symi - fdp->isymBase, str_base, aux_base, -1, fdp); if (want_scope && cur_scope != (scope_t *) 0) printf ("\n Warning scope does not end at 0!\n"); /* * print the aux. table if desired. */ if (want_aux && fdp->caux != 0) { int auxi; printf ("\n There are %lu auxiliary table entries, starting at %lu.\n\n", (ulong) fdp->caux, (ulong) (fdp->iauxBase + sym_hdr.cbAuxOffset)); for (auxi = fdp->iauxBase; auxi < (fdp->caux + fdp->iauxBase); auxi++) print_aux (aux_base[auxi], auxi, used_base[auxi]); } /* * print the relative file descriptors. */ if (want_rfd && fdp->crfd != 0) { ulong *rfd_ptr, i; printf ("\n There are %lu relative file descriptors, starting at %lu.\n", (ulong) fdp->crfd, (ulong) fdp->rfdBase); rfd_ptr = rfile_desc + fdp->rfdBase; for (i = 0; i < fdp->crfd; i++) { printf ("\t#%-5ld %11ld, 0x%08lx\n", i, *rfd_ptr, *rfd_ptr); rfd_ptr++; } } /* * do the procedure descriptors. */ printf ("\n There are %lu procedure descriptor entries, ", (ulong) fdp->cpd); printf ("starting at %lu.\n", (ulong) fdp->ipdFirst); for (pdi = fdp->ipdFirst; pdi < (fdp->cpd + fdp->ipdFirst); pdi++) { PDR *proc_ptr = &proc_desc[pdi]; printf ("\n\tProcedure descriptor %d:\n", (pdi - fdp->ipdFirst)); printf ("\t Name index = %-11ld Name = \"%s\"\n", (long) l_symbols[proc_ptr->isym + fdp->isymBase].iss, l_symbols[proc_ptr->isym + fdp->isymBase].iss + str_base); printf ("\t .mask 0x%08lx,%-9ld .fmask 0x%08lx,%ld\n", (long) proc_ptr->regmask, (long) proc_ptr->regoffset, (long) proc_ptr->fregmask, (long) proc_ptr->fregoffset); printf ("\t .frame $%d,%ld,$%d\n", (int) proc_ptr->framereg, (long) proc_ptr->frameoffset, (int) proc_ptr->pcreg); printf ("\t Opt. start = %-11ld Symbols start = %ld\n", (long) proc_ptr->iopt, (long) proc_ptr->isym); printf ("\t First line # = %-11ld Last line # = %ld\n", (long) proc_ptr->lnLow, (long) proc_ptr->lnHigh); printf ("\t Line Offset = %-11ld Address = 0x%08lx\n", (long) proc_ptr->cbLineOffset, (long) proc_ptr->adr); /* * print the line number entries. */ if (want_line && fdp->cline != 0) { int delta, count; long cur_line = proc_ptr->lnLow; uchar *line_ptr = (((uchar *)lines) + proc_ptr->cbLineOffset + fdp->cbLineOffset); uchar *line_end; if (pdi == fdp->cpd + fdp->ipdFirst - 1) /* last procedure */ line_end = ((uchar *)lines) + fdp->cbLine + fdp->cbLineOffset; else /* not last proc. */ line_end = (((uchar *)lines) + proc_desc[pdi+1].cbLineOffset + fdp->cbLineOffset); printf ("\n\tThere are %lu bytes holding line numbers, starting at %lu.\n", (ulong) (line_end - line_ptr), (ulong) (fdp->ilineBase + sym_hdr.cbLineOffset)); while (line_ptr < line_end) { /* sign extend nibble */ delta = ((*line_ptr >> 4) ^ 0x8) - 0x8; count = (*line_ptr & 0xf) + 1; if (delta != -8) line_ptr++; else { delta = (((line_ptr[1]) & 0xff) << 8) + ((line_ptr[2]) & 0xff); delta = (delta ^ 0x8000) - 0x8000; line_ptr += 3; } cur_line += delta; printf ("\t Line %11ld, delta %5d, count %2d\n", cur_line, delta, count); } } }}/* Read in the portions of the .T file that we will print out. */voidread_tfile __proto((void)){ short magic; off_t sym_hdr_offset = 0; (void) read_seek ((PTR_T) &magic, sizeof (magic), (off_t) 0, "Magic number"); if (!tfile) { /* Print out the global header, since this is not a T-file. */ (void) read_seek ((PTR_T) &global_hdr, sizeof (global_hdr), (off_t) 0, "Global file header"); print_global_hdr (&global_hdr); if (global_hdr.f_symptr == 0) { printf ("No symbolic header, Goodbye!\n"); exit (1); } sym_hdr_offset = global_hdr.f_symptr; } (void) read_seek ((PTR_T) &sym_hdr, sizeof (sym_hdr), sym_hdr_offset, "Symbolic header"); print_sym_hdr (&sym_hdr); lines = (LINER *) read_seek ((PTR_T) 0, sym_hdr.cbLine, sym_hdr.cbLineOffset, "Line numbers"); dense_nums = (DNR *) read_seek ((PTR_T) 0, sym_hdr.idnMax * sizeof (DNR), sym_hdr.cbDnOffset, "Dense numbers"); proc_desc = (PDR *) read_seek ((PTR_T) 0, sym_hdr.ipdMax * sizeof (PDR), sym_hdr.cbPdOffset, "Procedure tables"); l_symbols = (SYMR *) read_seek ((PTR_T) 0, sym_hdr.isymMax * sizeof (SYMR), sym_hdr.cbSymOffset, "Local symbols"); opt_symbols = (OPTR *) read_seek ((PTR_T) 0, sym_hdr.ioptMax * sizeof (OPTR), sym_hdr.cbOptOffset, "Optimization symbols"); aux_symbols = (AUXU *) read_seek ((PTR_T) 0, sym_hdr.iauxMax * sizeof (AUXU), sym_hdr.cbAuxOffset, "Auxiliary symbols"); if (sym_hdr.iauxMax > 0) { aux_used = calloc (sym_hdr.iauxMax, 1); if (aux_used == (char *) 0) { perror ("calloc"); exit (1); } } l_strings = (char *) read_seek ((PTR_T) 0, sym_hdr.issMax, sym_hdr.cbSsOffset, "Local string table"); e_strings = (char *) read_seek ((PTR_T) 0, sym_hdr.issExtMax, sym_hdr.cbSsExtOffset, "External string table"); file_desc = (FDR *) read_seek ((PTR_T) 0, sym_hdr.ifdMax * sizeof (FDR), sym_hdr.cbFdOffset, "File tables"); rfile_desc = (ulong *) read_seek ((PTR_T) 0, sym_hdr.crfd * sizeof (ulong), sym_hdr.cbRfdOffset, "Relative file tables"); e_symbols = (EXTR *) read_seek ((PTR_T) 0, sym_hdr.iextMax * sizeof (EXTR), sym_hdr.cbExtOffset, "External symbols");}intmain (argc, argv) int argc; char **argv;{ int i, opt; /* * Process arguments */ while ((opt = getopt (argc, argv, "alrst")) != EOF) switch (opt) { default: errors++; break; case 'a': want_aux++; break; /* print aux table */ case 'l': want_line++; break; /* print line numbers */ case 'r': want_rfd++; break; /* print relative fd's */ case 's': want_scope++; break; /* print scope info */ case 't': tfile++; break; /* this is a tfile (without header), and not a .o */ } if (errors || optind != argc - 1) { fprintf (stderr, "Calling Sequence:\n"); fprintf (stderr, "\t%s [-alrst] <object-or-T-file>\n", argv[0]); fprintf (stderr, "\n"); fprintf (stderr, "switches:\n"); fprintf (stderr, "\t-a Print out auxiliary table.\n"); fprintf (stderr, "\t-l Print out line numbers.\n"); fprintf (stderr, "\t-r Print out relative file descriptors.\n"); fprintf (stderr, "\t-s Print out the current scopes for an item.\n"); fprintf (stderr, "\t-t Assume there is no global header (ie, a T-file).\n"); return 1; } /* * Open and process the input file. */ tfile_fd = open (argv[optind], O_RDONLY); if (tfile_fd < 0) { perror (argv[optind]); return 1; } read_tfile (); /* * Print any global aux words if any. */ if (want_aux) { long last_aux_in_use; if (sym_hdr.ifdMax != 0 && file_desc[0].iauxBase != 0) { printf ("\nGlobal auxiliary entries before first file:\n"); for (i = 0; i < file_desc[0].iauxBase; i++) print_aux (aux_symbols[i], 0, aux_used[i]); } if (sym_hdr.ifdMax == 0) last_aux_in_use = 0; else last_aux_in_use = (file_desc[sym_hdr.ifdMax-1].iauxBase + file_desc[sym_hdr.ifdMax-1].caux - 1); if (last_aux_in_use < sym_hdr.iauxMax-1) { printf ("\nGlobal auxiliary entries after last file:\n"); for (i = last_aux_in_use; i < sym_hdr.iauxMax; i++) print_aux (aux_symbols[i], i - last_aux_in_use, aux_used[i]); } } /* * Print the information for each file. */ for (i = 0; i < sym_hdr.ifdMax; i++) print_file_desc (&file_desc[i], i); /* * Print the external symbols. */ want_scope = 0; /* scope info is meaning for extern symbols */ printf ("\nThere are %lu external symbols, starting at %lu\n", (ulong) sym_hdr.iextMax, (ulong) sym_hdr.cbExtOffset); for(i = 0; i < sym_hdr.iextMax; i++) print_symbol (&e_symbols[i].asym, i, e_strings, aux_symbols + file_desc[e_symbols[i].ifd].iauxBase, e_symbols[i].ifd, &file_desc[e_symbols[i].ifd]); /* * Print unused aux symbols now. */ if (want_aux) { int first_time = 1; for (i = 0; i < sym_hdr.iauxMax; i++) { if (! aux_used[i]) { if (first_time) { printf ("\nThe following auxiliary table entries were unused:\n\n"); first_time = 0; } printf (" #%-5d %11ld 0x%08lx %s\n", i, (long) aux_symbols[i].isym, (long) aux_symbols[i].isym, type_to_string (aux_symbols, i, (FDR *) 0)); } } } return 0;}voidfancy_abort (){ fprintf (stderr, "mips-tdump internal error"); exit (1);}voidfatal(s)char *s;{ fprintf(stderr, "%s\n", s); exit(1);}/* Same as `malloc' but report error if no memory available. */PTR_Txmalloc (size) unsigned size;{ register PTR_T value = malloc (size); if (value == 0) fatal ("Virtual memory exhausted."); return value;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -