/[gxemul]/trunk/src/symbol.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/symbol.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Mon Oct 8 16:17:48 2007 UTC revision 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: symbol.c,v 1.23 2005/03/20 11:11:48 debug Exp $   *  $Id: symbol.c,v 1.29 2005/08/09 17:18:22 debug Exp $
29   *   *
30   *  Address to symbol translation routines.   *  Address to symbol translation routines.
31   *   *
# Line 94  int get_symbol_addr(struct symbol_contex Line 94  int get_symbol_addr(struct symbol_contex
94    
95    
96  /*  /*
97   *  get_symbol_name():   *  get_symbol_name_and_n_args():
98   *   *
99   *  Translate an address into a symbol name.  The return value is a pointer   *  Translate an address into a symbol name.  The return value is a pointer
100   *  to a static char array, containing the symbol name.  (In other words,   *  to a static char array, containing the symbol name.  (In other words,
# Line 107  int get_symbol_addr(struct symbol_contex Line 107  int get_symbol_addr(struct symbol_contex
107   *  0x1008, the symbol's name will be found in the static char array, and   *  0x1008, the symbol's name will be found in the static char array, and
108   *  *offset will be set to 0x8.   *  *offset will be set to 0x8.
109   *   *
110     *  If n_argsp is non-NULL, *n_argsp is set to the symbol's n_args value.
111     *
112   *  If no symbol was found, NULL is returned instead.   *  If no symbol was found, NULL is returned instead.
113   */   */
114  static char symbol_buf[SYMBOLBUF_MAX+1];  static char symbol_buf[SYMBOLBUF_MAX+1];
115  char *get_symbol_name(struct symbol_context *sc, uint64_t addr,  char *get_symbol_name_and_n_args(struct symbol_context *sc, uint64_t addr,
116          uint64_t *offset)          uint64_t *offset, int *n_argsp)
117  {  {
118          struct symbol *s;          struct symbol *s;
119          int stepsize, ofs;          int stepsize, ofs;
# Line 141  char *get_symbol_name(struct symbol_cont Line 143  char *get_symbol_name(struct symbol_cont
143                                              (addr - s->addr));                                              (addr - s->addr));
144                                  if (offset != NULL)                                  if (offset != NULL)
145                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
146                                    if (n_argsp != NULL)
147                                            *n_argsp = s->n_args;
148                                  return symbol_buf;                                  return symbol_buf;
149                          }                          }
150                          s = s->next;                          s = s->next;
# Line 163  char *get_symbol_name(struct symbol_cont Line 167  char *get_symbol_name(struct symbol_cont
167                                              (addr - s->addr));                                              (addr - s->addr));
168                                  if (offset != NULL)                                  if (offset != NULL)
169                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
170                                    if (n_argsp != NULL)
171                                            *n_argsp = s->n_args;
172                                  return symbol_buf;                                  return symbol_buf;
173                          }                          }
174    
# Line 190  char *get_symbol_name(struct symbol_cont Line 196  char *get_symbol_name(struct symbol_cont
196    
197    
198  /*  /*
199     *  get_symbol_name():
200     *
201     *  See get_symbol_name_and_n_args().
202     */
203    char *get_symbol_name(struct symbol_context *sc, uint64_t addr, uint64_t *offs)
204    {
205            return get_symbol_name_and_n_args(sc, addr, offs, NULL);
206    }
207    
208    
209    /*
210   *  add_symbol_name():   *  add_symbol_name():
211   *   *
212   *  Add a symbol to the symbol list.   *  Add a symbol to the symbol list.
213   */   */
214  void add_symbol_name(struct symbol_context *sc,  void add_symbol_name(struct symbol_context *sc,
215          uint64_t addr, uint64_t len, char *name, int type)          uint64_t addr, uint64_t len, char *name, int type, int n_args)
216  {  {
217          struct symbol *s;          struct symbol *s;
218    
# Line 205  void add_symbol_name(struct symbol_conte Line 222  void add_symbol_name(struct symbol_conte
222                  exit(1);                  exit(1);
223          }          }
224    
225            if (name == NULL) {
226                    fprintf(stderr, "add_symbol_name(): name = NULL\n");
227                    exit(1);
228            }
229    
230            if (name[0] == '\0')
231                    return;
232    
233            /*  TODO: Maybe this should be optional?  */
234            if (name[0] == '.' || name[0] == '$')
235                    return;
236    
237            /*  Quick test-hack:  */
238            if (n_args < 0) {
239                    if (strcmp(name, "strlen") == 0)
240                            n_args = 1;
241                    if (strcmp(name, "strcmp") == 0)
242                            n_args = 2;
243                    if (strcmp(name, "strcpy") == 0)
244                            n_args = 2;
245                    if (strcmp(name, "strncmp") == 0)
246                            n_args = 3;
247                    if (strcmp(name, "memset") == 0)
248                            n_args = 3;
249                    if (strcmp(name, "memcpy") == 0)
250                            n_args = 3;
251                    if (strcmp(name, "bzero") == 0)
252                            n_args = 2;
253                    if (strcmp(name, "bcopy") == 0)
254                            n_args = 3;
255            }
256    
257          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))
258                  addr |= 0xffffffff00000000ULL;                  addr |= 0xffffffff00000000ULL;
259    
# Line 219  void add_symbol_name(struct symbol_conte Line 268  void add_symbol_name(struct symbol_conte
268                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
269                  exit(1);                  exit(1);
270          }          }
271          s->addr = addr;          s->addr   = addr;
272          s->len  = len;          s->len    = len;
273          s->type = type;          s->type   = type;
274            s->n_args = n_args;
275    
276          sc->n_symbols ++;          sc->n_symbols ++;
277    
# Line 262  void symbol_readfile(struct symbol_conte Line 312  void symbol_readfile(struct symbol_conte
312                  memset(b4, 0, sizeof(b4));                  memset(b4, 0, sizeof(b4));
313                  fscanf(f, "%s %s\n", b1,b2);                  fscanf(f, "%s %s\n", b1,b2);
314                  if (strlen(b2) < 2 && !(b2[0]>='0' && b2[0]<='9')) {                  if (strlen(b2) < 2 && !(b2[0]>='0' && b2[0]<='9')) {
315                          strcpy(b3, b2);                          strlcpy(b3, b2, sizeof(b3));
316                          strcpy(b2, "0");                          strlcpy(b2, "0", sizeof(b2));
317                          fscanf(f, "%s\n", b4);                          fscanf(f, "%s\n", b4);
318                  } else {                  } else {
319                          fscanf(f, "%s %s\n", b3,b4);                          fscanf(f, "%s %s\n", b3,b4);
# Line 280  void symbol_readfile(struct symbol_conte Line 330  void symbol_readfile(struct symbol_conte
330                  if (type == 't' || type == 'r' || type == 'g')                  if (type == 't' || type == 'r' || type == 'g')
331                          continue;                          continue;
332    
333                  add_symbol_name(sc, addr, len, b4, type);                  add_symbol_name(sc, addr, len, b4, type, -1);
334          }          }
335    
336          fclose(f);          fclose(f);

Legend:
Removed from v.2  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26