symtab.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Ondrej Palkovsky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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                 /* Find a ':' in name */
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         /* Allow completion of pointers  */
00163         if (name[0] == '*' || name[0] == '&')
00164                 name++;
00165 
00166         /* Do not print everything */
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 

Generated on Sun Jun 18 17:28:03 2006 for HelenOS Kernel (ppc64) by  doxygen 1.4.6