diff options
Diffstat (limited to 'other/Kermit/lib/SymbolTable.cpp')
| -rw-r--r-- | other/Kermit/lib/SymbolTable.cpp | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/other/Kermit/lib/SymbolTable.cpp b/other/Kermit/lib/SymbolTable.cpp new file mode 100644 index 0000000..1d412e0 --- /dev/null +++ b/other/Kermit/lib/SymbolTable.cpp | |||
| @@ -0,0 +1,205 @@ | |||
| 1 | /* | ||
| 2 | * SymbolTable.cpp: | ||
| 3 | * written by palmers / teso | ||
| 4 | */ | ||
| 5 | #include <SymbolTable.hpp> | ||
| 6 | |||
| 7 | |||
| 8 | /* | ||
| 9 | * helper classes | ||
| 10 | */ | ||
| 11 | class DumpTable | ||
| 12 | { | ||
| 13 | private: | ||
| 14 | string file; | ||
| 15 | |||
| 16 | public: | ||
| 17 | DumpTable (string a) | ||
| 18 | { | ||
| 19 | file = string (a); | ||
| 20 | } | ||
| 21 | |||
| 22 | ~DumpTable () | ||
| 23 | { | ||
| 24 | } | ||
| 25 | |||
| 26 | void operator() (zzSym *foo) | ||
| 27 | { | ||
| 28 | ofstream dump (file.c_str ()); | ||
| 29 | if (!dump.is_open ()) | ||
| 30 | { | ||
| 31 | cerr << "Pfff..." << endl; | ||
| 32 | abort (); | ||
| 33 | } | ||
| 34 | dump << foo->Name << "\tE\t" << foo->Address << endl; | ||
| 35 | dump.close (); | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | |||
| 39 | |||
| 40 | class FindFind | ||
| 41 | { | ||
| 42 | private: | ||
| 43 | string search; | ||
| 44 | |||
| 45 | public: | ||
| 46 | FindFind (string a) | ||
| 47 | { | ||
| 48 | search = string (a); | ||
| 49 | } | ||
| 50 | |||
| 51 | bool operator() (struct zzSym *foo) | ||
| 52 | { | ||
| 53 | if (search.compare (foo->Name, search.length ())) | ||
| 54 | { | ||
| 55 | return true; | ||
| 56 | } | ||
| 57 | return false; | ||
| 58 | } | ||
| 59 | }; | ||
| 60 | |||
| 61 | |||
| 62 | /* | ||
| 63 | * member functions | ||
| 64 | */ | ||
| 65 | bool SymbolTable::loadFiles (string a, string b) | ||
| 66 | { | ||
| 67 | /* check for System.map */ | ||
| 68 | mapp = SystemMap (a); | ||
| 69 | |||
| 70 | /* load a dumped cache */ | ||
| 71 | rest = SystemMap (b); | ||
| 72 | return true; | ||
| 73 | } | ||
| 74 | |||
| 75 | |||
| 76 | bool SymbolTable::createObjects (rwKernel *a) | ||
| 77 | { | ||
| 78 | if (a == NULL) | ||
| 79 | patt = new DevMemPatt (); | ||
| 80 | else | ||
| 81 | patt = new DevMemPatt (a); | ||
| 82 | fing = new SymbolFingp (); | ||
| 83 | return true; | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | SymbolTable::SymbolTable () | ||
| 88 | { | ||
| 89 | loadFiles (DEFAULTSYSTEMMAP, DEFAULTDUMP); | ||
| 90 | createObjects (NULL); | ||
| 91 | |||
| 92 | /* XXX, init set of exported symbols */ | ||
| 93 | if (false) | ||
| 94 | { | ||
| 95 | exported = SystemMap (); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | SymbolTable::SymbolTable (string res, string sys) | ||
| 101 | { | ||
| 102 | loadFiles (sys, res); | ||
| 103 | createObjects (NULL); | ||
| 104 | |||
| 105 | /* XXX, init set of exported symbols */ | ||
| 106 | if (false) | ||
| 107 | { | ||
| 108 | exported = SystemMap (); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | SymbolTable::SymbolTable (rwKernel *f) | ||
| 114 | { | ||
| 115 | loadFiles (DEFAULTSYSTEMMAP, DEFAULTDUMP); | ||
| 116 | createObjects (f); | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | SymbolTable::~SymbolTable () | ||
| 121 | { | ||
| 122 | delete fing; | ||
| 123 | delete patt; | ||
| 124 | clearCache (); | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | void SymbolTable::setSaveFile (string file) | ||
| 129 | { | ||
| 130 | dump_file = string (file); | ||
| 131 | } | ||
| 132 | |||
| 133 | |||
| 134 | unsigned int SymbolTable::getSymbol (string name) | ||
| 135 | { | ||
| 136 | zzSymList::iterator x; | ||
| 137 | zzSym *y = NULL; | ||
| 138 | |||
| 139 | x = find_if (symList.begin (), symList.end (), FindFind (name)); | ||
| 140 | if (x == symList.end ()) | ||
| 141 | return 0; | ||
| 142 | y = *x; | ||
| 143 | return y->Address; | ||
| 144 | } | ||
| 145 | |||
| 146 | |||
| 147 | bool SymbolTable::findSymbol (string name) | ||
| 148 | { | ||
| 149 | unsigned int x = 0; | ||
| 150 | /* | ||
| 151 | * first check if the symbol can be found in restore date | ||
| 152 | * second check if the symbol can be found using SymbolFingp | ||
| 153 | * third is list of exported symbols | ||
| 154 | * fourth System.map (if supplied) | ||
| 155 | */ | ||
| 156 | if (rest.contains (name)) | ||
| 157 | { | ||
| 158 | addSymbolToCache (name, rest[name]); | ||
| 159 | return true; | ||
| 160 | } | ||
| 161 | |||
| 162 | if ((x = patt->find_patt (fing->getFinger (name))) != 0) | ||
| 163 | { | ||
| 164 | addSymbolToCache (name, x); | ||
| 165 | return true; | ||
| 166 | } | ||
| 167 | |||
| 168 | if (exported.contains (name)) | ||
| 169 | { | ||
| 170 | addSymbolToCache (name, exported[name]); | ||
| 171 | return true; | ||
| 172 | } | ||
| 173 | |||
| 174 | if (mapp.contains (name)) | ||
| 175 | { | ||
| 176 | addSymbolToCache (name, mapp[name]); | ||
| 177 | return true; | ||
| 178 | } | ||
| 179 | |||
| 180 | return false; | ||
| 181 | } | ||
| 182 | |||
| 183 | |||
| 184 | void SymbolTable::addSymbolToCache (string name, unsigned int add) | ||
| 185 | { | ||
| 186 | zzSym *x = new zzSym; | ||
| 187 | |||
| 188 | x->Name = string (name); | ||
| 189 | x->Address = add; | ||
| 190 | symList.push_back (x); | ||
| 191 | } | ||
| 192 | |||
| 193 | |||
| 194 | void SymbolTable::clearCache () | ||
| 195 | { | ||
| 196 | symList.clear (); | ||
| 197 | } | ||
| 198 | |||
| 199 | |||
| 200 | bool SymbolTable::saveCache () | ||
| 201 | { | ||
| 202 | for_each (symList.begin (), symList.end (), DumpTable (dump_file)); | ||
| 203 | return true; | ||
| 204 | } | ||
| 205 | |||
