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
00028
00038 #include <symtab.h>
00039 #include <typedefs.h>
00040 #include <arch/byteorder.h>
00041 #include <func.h>
00042 #include <print.h>
00043
00053 char * get_symtab_entry(__native addr)
00054 {
00055 count_t i;
00056
00057 for (i=1;symbol_table[i].address_le;++i) {
00058 if (addr < __u64_le2host(symbol_table[i].address_le))
00059 break;
00060 }
00061 if (addr >= __u64_le2host(symbol_table[i-1].address_le))
00062 return symbol_table[i-1].symbol_name;
00063 return NULL;
00064 }
00065
00072 static char * symtab_search_one(const char *name, int *startpos)
00073 {
00074 int namelen = strlen(name);
00075 char *curname;
00076 int i,j;
00077 int colonoffset = -1;
00078
00079 for (i=0;name[i];i++)
00080 if (name[i] == ':') {
00081 colonoffset = i;
00082 break;
00083 }
00084
00085 for (i=*startpos;symbol_table[i].address_le;++i) {
00086
00087 curname = symbol_table[i].symbol_name;
00088 for (j=0; curname[j] && curname[j] != ':'; j++)
00089 ;
00090 if (!curname[j])
00091 continue;
00092 j -= colonoffset;
00093 curname += j;
00094 if (strlen(curname) < namelen)
00095 continue;
00096 if (strncmp(curname, name, namelen) == 0) {
00097 *startpos = i;
00098 return curname+namelen;
00099 }
00100 }
00101 return NULL;
00102 }
00103
00111 __address get_symbol_addr(const char *name)
00112 {
00113 count_t found = 0;
00114 __address addr = NULL;
00115 char *hint;
00116 int i;
00117
00118 i = 0;
00119 while ((hint=symtab_search_one(name, &i))) {
00120 if (!strlen(hint)) {
00121 addr = __u64_le2host(symbol_table[i].address_le);
00122 found++;
00123 }
00124 i++;
00125 }
00126 if (found > 1)
00127 return ((__address) -1);
00128 return addr;
00129 }
00130
00132 void symtab_print_search(const char *name)
00133 {
00134 int i;
00135 __address addr;
00136 char *realname;
00137
00138
00139 i = 0;
00140 while (symtab_search_one(name, &i)) {
00141 addr = __u64_le2host(symbol_table[i].address_le);
00142 realname = symbol_table[i].symbol_name;
00143 printf("%.*p: %s\n", sizeof(__address) * 2, addr, realname);
00144 i++;
00145 }
00146 }
00147
00153 int symtab_compl(char *input)
00154 {
00155 char output[MAX_SYMBOL_NAME+1];
00156 int startpos = 0;
00157 char *foundtxt;
00158 int found = 0;
00159 int i;
00160 char *name = input;
00161
00162
00163 if (name[0] == '*' || name[0] == '&')
00164 name++;
00165
00166
00167 if (!strlen(name))
00168 return 0;
00169
00170
00171 output[0] = '\0';
00172
00173 while ((foundtxt = symtab_search_one(name, &startpos))) {
00174 startpos++;
00175 if (!found)
00176 strncpy(output, foundtxt, strlen(foundtxt)+1);
00177 else {
00178 for (i=0; output[i] && foundtxt[i] && output[i]==foundtxt[i]; i++)
00179 ;
00180 output[i] = '\0';
00181 }
00182 found++;
00183 }
00184 if (!found)
00185 return 0;
00186
00187 if (found > 1 && !strlen(output)) {
00188 printf("\n");
00189 startpos = 0;
00190 while ((foundtxt = symtab_search_one(name, &startpos))) {
00191 printf("%s\n", symbol_table[startpos].symbol_name);
00192 startpos++;
00193 }
00194 }
00195 strncpy(input, output, MAX_SYMBOL_NAME);
00196 return found;
00197
00198 }
00199