00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <iostream>
00028 #include <stdio.h>
00029 #include <elf.h>
00030 #include "elf_reader.h"
00031 #include "elf_reader64.h"
00032 #include <string.h>
00033 #include <vector>
00034 #include "messg.h"
00035 #include "rta.h"
00036 #include "rta_manager.h"
00037 #include "wn_reader.h"
00038 #include "rta_reader.h"
00039
00040 using namespace std;
00041
00042
00043 static inline void print(FILE *fp, INT sz, unsigned char *stream)
00044 {
00045 #if defined(DEBUG)
00046 INT j = 0;
00047 while (j < sz) {
00048 if ((j % 8) == 0)
00049 fprintf(fp, "\n");
00050
00051 fprintf(fp, " %2x", *stream);
00052 stream++;
00053 j++;
00054 }
00055 fprintf(fp, "\n");
00056 #endif
00057 }
00058
00059 void PU_SectBin::PrintBits(FILE *fp, INT i)
00060 {
00061 #if defined(DEBUG)
00062 if (NumsectNone())
00063 return;
00064
00065 FmtAssert((i <= Numsect()), ("index %s larger than number of sections %x", i, Numsect()));
00066
00067 vector<RTABuf> ppu = PuSects();
00068 INT sz = ppu[i].Size();
00069 fprintf(fp, "%d-th (pc=%llx), size is %x\n",i, ppu[i].Pc(), sz);
00070 BITS b = ppu[i].Bits();
00071 print(fp, sz, b);
00072 #endif
00073 }
00074
00075 void PU_SectBin::PrintBits(FILE *fp)
00076 {
00077 #if defined(DEBUG)
00078 if (NumsectNone())
00079 return;
00080 INT i = Numsect();
00081 while (i-- > 0) {
00082 PrintBits(fp, i);
00083 }
00084 #endif
00085 }
00086
00087 BOOL PU_SectBin::VerifyHdr(const Rta_Hdr *prta)
00088 {
00089 if (Rta_hdr_magic(prta) != V_0_9 && Rta_hdr_magic(prta) != V_1_0)
00090 FmtAssert(0, ("Wrong magic"));
00091
00092 if ((Rta_hdr_type(prta) != RTA_DYNAMIC)
00093 && (Rta_hdr_type(prta) != RTA_STATIC))
00094 FmtAssert(0, ("Wrong type"));
00095
00096 if (Rta_hdr_pu_off(prta) == 0 && Rta_hdr_pu_num(prta) == 0)
00097 FmtAssert(0, ("Rta header inconsistent numb of pu %x, with pu offset 0",
00098 Rta_hdr_pu_off(prta)));
00099
00100 return true;
00101 }
00102
00103 BOOL PU_SectBin::QuickChk(FILE *fp, INT i)
00104 {
00105 if (NumsectNone()) {
00106 cout << i << "-th rta section does not exist\n";
00107 return false;
00108 }
00109
00110 FmtAssert(i <= Numsect(), ("index larger than number of sections"));
00111
00112 vector<RTABuf> ppu = PuSects();
00113 INT sz = ppu[i].Size();
00114 UINT64 pc = ppu[i].Pc();
00115
00116 if (sz < sizeof(Rta_Hdr))
00117 FmtAssert(0, ("section size smaller than Rta_Hdr"));
00118
00119 Rta_Manager rta((void*)ppu[i].Bits());
00120 Print_rta_hdr(fp, &(rta.Hdr()), " ");
00121 Print_rta_pu_title(fp, " ");
00122 Rta_Manager::Pu_Iter it = rta.begin();
00123 for ( ; it != rta.end(); it++) {
00124 Print_rta_pu(fp, &(*it), " ");
00125
00126 Print_rta_bb_title(fp, " ");
00127 Rta_Manager::Bb_Iter itb = rta.begin(it);
00128 for (INT j=0 ; itb != rta.end(it); itb++, j++) {
00129 Print_rta_bb(fp, pc, &(*itb), j, " ");
00130 }
00131
00132 }
00133 return true;
00134 }
00135
00136
00137 BOOL PU_SectBin::QuickChk(FILE *fp)
00138 {
00139 #if defined(DEBUG)
00140 if (NumsectNone())
00141 return true;
00142 INT i = Numsect();
00143 while (i-- > 0) {
00144 QuickChk(fp, i);
00145 }
00146 #endif
00147 return true;
00148 }