/[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 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC revision 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: symbol.c,v 1.26 2005/06/21 16:22:52 debug Exp $   *  $Id: symbol.c,v 1.35 2006/03/22 21:39:23 debug Exp $
29   *   *
30   *  Address to symbol translation routines.   *  Address to symbol translation routines.
31   *   *
32   *  This module is (probably) independant from the rest of the emulator.   *  This module is (probably) independent from the rest of the emulator.
33   *  symbol_init() must be called before any other function in this   *  symbol_init() must be called before any other function in this file is used.
  *  file is used.  
34   */   */
35    
36  #include <stdio.h>  #include <stdio.h>
37  #include <stdlib.h>  #include <stdlib.h>
38  #include <string.h>  #include <string.h>
39    
 #include "misc.h"  
   
40  #include "symbol.h"  #include "symbol.h"
41    
42    
# Line 94  int get_symbol_addr(struct symbol_contex Line 91  int get_symbol_addr(struct symbol_contex
91    
92    
93  /*  /*
94   *  get_symbol_name():   *  get_symbol_name_and_n_args():
95   *   *
96   *  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
97   *  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 104  int get_symbol_addr(struct symbol_contex
104   *  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
105   *  *offset will be set to 0x8.   *  *offset will be set to 0x8.
106   *   *
107     *  If n_argsp is non-NULL, *n_argsp is set to the symbol's n_args value.
108     *
109   *  If no symbol was found, NULL is returned instead.   *  If no symbol was found, NULL is returned instead.
110   */   */
111  static char symbol_buf[SYMBOLBUF_MAX+1];  static char symbol_buf[SYMBOLBUF_MAX+1];
112  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,
113          uint64_t *offset)          uint64_t *offset, int *n_argsp)
114  {  {
115          struct symbol *s;          struct symbol *s;
116          int stepsize, ofs;          int stepsize, ofs;
# Line 141  char *get_symbol_name(struct symbol_cont Line 140  char *get_symbol_name(struct symbol_cont
140                                              (addr - s->addr));                                              (addr - s->addr));
141                                  if (offset != NULL)                                  if (offset != NULL)
142                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
143                                    if (n_argsp != NULL)
144                                            *n_argsp = s->n_args;
145                                  return symbol_buf;                                  return symbol_buf;
146                          }                          }
147                          s = s->next;                          s = s->next;
# Line 163  char *get_symbol_name(struct symbol_cont Line 164  char *get_symbol_name(struct symbol_cont
164                                              (addr - s->addr));                                              (addr - s->addr));
165                                  if (offset != NULL)                                  if (offset != NULL)
166                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
167                                    if (n_argsp != NULL)
168                                            *n_argsp = s->n_args;
169                                  return symbol_buf;                                  return symbol_buf;
170                          }                          }
171    
# Line 190  char *get_symbol_name(struct symbol_cont Line 193  char *get_symbol_name(struct symbol_cont
193    
194    
195  /*  /*
196     *  get_symbol_name():
197     *
198     *  See get_symbol_name_and_n_args().
199     */
200    char *get_symbol_name(struct symbol_context *sc, uint64_t addr, uint64_t *offs)
201    {
202            return get_symbol_name_and_n_args(sc, addr, offs, NULL);
203    }
204    
205    
206    /*
207   *  add_symbol_name():   *  add_symbol_name():
208   *   *
209   *  Add a symbol to the symbol list.   *  Add a symbol to the symbol list.
210   */   */
211  void add_symbol_name(struct symbol_context *sc,  void add_symbol_name(struct symbol_context *sc,
212          uint64_t addr, uint64_t len, char *name, int type)          uint64_t addr, uint64_t len, char *name, int type, int n_args)
213  {  {
214          struct symbol *s;          struct symbol *s;
215    
# Line 214  void add_symbol_name(struct symbol_conte Line 228  void add_symbol_name(struct symbol_conte
228                  return;                  return;
229    
230          /*  TODO: Maybe this should be optional?  */          /*  TODO: Maybe this should be optional?  */
231          if (name[0] == '$')          if (name[0] == '.' || name[0] == '$')
232                  return;                  return;
233    
234            /*  Quick test-hack:  */
235            if (n_args < 0) {
236                    if (strcmp(name, "strlen") == 0)
237                            n_args = 1;
238                    if (strcmp(name, "strcmp") == 0)
239                            n_args = 2;
240                    if (strcmp(name, "strcpy") == 0)
241                            n_args = 2;
242                    if (strcmp(name, "strncpy") == 0)
243                            n_args = 3;
244                    if (strcmp(name, "strlcpy") == 0)
245                            n_args = 3;
246                    if (strcmp(name, "strlcat") == 0)
247                            n_args = 3;
248                    if (strcmp(name, "strncmp") == 0)
249                            n_args = 3;
250                    if (strcmp(name, "memset") == 0)
251                            n_args = 3;
252                    if (strcmp(name, "memcpy") == 0)
253                            n_args = 3;
254                    if (strcmp(name, "bzero") == 0)
255                            n_args = 2;
256                    if (strcmp(name, "bcopy") == 0)
257                            n_args = 3;
258            }
259    
260          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))
261                  addr |= 0xffffffff00000000ULL;                  addr |= 0xffffffff00000000ULL;
262    
# Line 226  void add_symbol_name(struct symbol_conte Line 266  void add_symbol_name(struct symbol_conte
266                  exit(1);                  exit(1);
267          }          }
268    
269          s->name = strdup(name);          memset(s, 0, sizeof(struct symbol));
270    
271            s->name = symbol_demangle_cplusplus(name);
272    
273          if (s->name == NULL) {          if (s->name == NULL) {
274                  fprintf(stderr, "out of memory\n");                  s->name = strdup(name);
275                  exit(1);                  if (s->name == NULL) {
276                            fprintf(stderr, "out of memory\n");
277                            exit(1);
278                    }
279          }          }
280          s->addr = addr;  
281          s->len  = len;          s->addr   = addr;
282          s->type = type;          s->len    = len;
283            s->type   = type;
284            s->n_args = n_args;
285    
286          sc->n_symbols ++;          sc->n_symbols ++;
287    
# Line 292  void symbol_readfile(struct symbol_conte Line 340  void symbol_readfile(struct symbol_conte
340                  if (type == 't' || type == 'r' || type == 'g')                  if (type == 't' || type == 'r' || type == 'g')
341                          continue;                          continue;
342    
343                  add_symbol_name(sc, addr, len, b4, type);                  add_symbol_name(sc, addr, len, b4, type, -1);
344          }          }
345    
346          fclose(f);          fclose(f);

Legend:
Removed from v.10  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26