/[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 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2007  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.37 2006/12/30 13:30:52 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 210  void add_symbol_name(struct symbol_conte Line 224  void add_symbol_name(struct symbol_conte
224                  exit(1);                  exit(1);
225          }          }
226    
227            if (addr == 0 && strcmp(name, "_DYNAMIC_LINK") == 0)
228                    return;
229    
230          if (name[0] == '\0')          if (name[0] == '\0')
231                  return;                  return;
232    
233          /*  TODO: Maybe this should be optional?  */          /*  TODO: Maybe this should be optional?  */
234          if (name[0] == '$')          if (name[0] == '.' || name[0] == '$')
235                  return;                  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, "strncpy") == 0)
246                            n_args = 3;
247                    if (strcmp(name, "strlcpy") == 0)
248                            n_args = 3;
249                    if (strcmp(name, "strlcat") == 0)
250                            n_args = 3;
251                    if (strcmp(name, "strncmp") == 0)
252                            n_args = 3;
253                    if (strcmp(name, "memset") == 0)
254                            n_args = 3;
255                    if (strcmp(name, "memcpy") == 0)
256                            n_args = 3;
257                    if (strcmp(name, "bzero") == 0)
258                            n_args = 2;
259                    if (strcmp(name, "bcopy") == 0)
260                            n_args = 3;
261            }
262    
263          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))          if ((addr >> 32) == 0 && (addr & 0x80000000ULL))
264                  addr |= 0xffffffff00000000ULL;                  addr |= 0xffffffff00000000ULL;
265    
# Line 226  void add_symbol_name(struct symbol_conte Line 269  void add_symbol_name(struct symbol_conte
269                  exit(1);                  exit(1);
270          }          }
271    
272          s->name = strdup(name);          memset(s, 0, sizeof(struct symbol));
273    
274            s->name = symbol_demangle_cplusplus(name);
275    
276          if (s->name == NULL) {          if (s->name == NULL) {
277                  fprintf(stderr, "out of memory\n");                  s->name = strdup(name);
278                  exit(1);                  if (s->name == NULL) {
279                            fprintf(stderr, "out of memory\n");
280                            exit(1);
281                    }
282          }          }
283          s->addr = addr;  
284          s->len  = len;          s->addr   = addr;
285          s->type = type;          s->len    = len;
286            s->type   = type;
287            s->n_args = n_args;
288    
289          sc->n_symbols ++;          sc->n_symbols ++;
290    
# Line 292  void symbol_readfile(struct symbol_conte Line 343  void symbol_readfile(struct symbol_conte
343                  if (type == 't' || type == 'r' || type == 'g')                  if (type == 't' || type == 'r' || type == 'g')
344                          continue;                          continue;
345    
346                  add_symbol_name(sc, addr, len, b4, type);                  add_symbol_name(sc, addr, len, b4, type, -1);
347          }          }
348    
349          fclose(f);          fclose(f);

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

  ViewVC Help
Powered by ViewVC 1.1.26