/[gxemul]/upstream/0.4.6/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 /upstream/0.4.6/src/symbol.c

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

revision 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC revision 40 by dpavlin, Mon Oct 8 16:22:11 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.29 2005/08/09 17:18:22 debug Exp $   *  $Id: symbol.c,v 1.38 2007/04/22 14:32:01 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 116  char *get_symbol_name_and_n_args(struct Line 113  char *get_symbol_name_and_n_args(struct
113          uint64_t *offset, int *n_argsp)          uint64_t *offset, int *n_argsp)
114  {  {
115          struct symbol *s;          struct symbol *s;
         int stepsize, ofs;  
116    
117          if (sc->n_symbols == 0)          if (sc->n_symbols == 0)
118                  return NULL;                  return NULL;
# Line 139  char *get_symbol_name_and_n_args(struct Line 135  char *get_symbol_name_and_n_args(struct
135                                              "%s", s->name);                                              "%s", s->name);
136                                  else                                  else
137                                          snprintf(symbol_buf, SYMBOLBUF_MAX,                                          snprintf(symbol_buf, SYMBOLBUF_MAX,
138                                              "%s+0x%lx", s->name, (long)                                              "%s+0x%"PRIx64, s->name, (uint64_t)
139                                              (addr - s->addr));                                              (addr - s->addr));
140                                  if (offset != NULL)                                  if (offset != NULL)
141                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
# Line 151  char *get_symbol_name_and_n_args(struct Line 147  char *get_symbol_name_and_n_args(struct
147                  }                  }
148          } else {          } else {
149                  /*  Faster, O(log n) search:  */                  /*  Faster, O(log n) search:  */
150                  stepsize = sc->n_symbols / 2;                  int lowest = 0, highest = sc->n_symbols - 1;
151                  ofs = stepsize;                  while (lowest <= highest) {
152                  while (stepsize > 0 || (stepsize == 0 && ofs == 0)) {                          int ofs = (lowest + highest) / 2;
153                          s = sc->first_symbol + ofs;                          s = sc->first_symbol + ofs;
154    
155                          /*  Found a match?  */                          /*  Found a match?  */
# Line 163  char *get_symbol_name_and_n_args(struct Line 159  char *get_symbol_name_and_n_args(struct
159                                              "%s", s->name);                                              "%s", s->name);
160                                  else                                  else
161                                          snprintf(symbol_buf, SYMBOLBUF_MAX,                                          snprintf(symbol_buf, SYMBOLBUF_MAX,
162                                              "%s+0x%lx", s->name, (long)                                              "%s+0x%"PRIx64, s->name, (uint64_t)
163                                              (addr - s->addr));                                              (addr - s->addr));
164    
165                                  if (offset != NULL)                                  if (offset != NULL)
166                                          *offset = addr - s->addr;                                          *offset = addr - s->addr;
167                                  if (n_argsp != NULL)                                  if (n_argsp != NULL)
168                                          *n_argsp = s->n_args;                                          *n_argsp = s->n_args;
169    
170                                  return symbol_buf;                                  return symbol_buf;
171                          }                          }
172    
173                          if (ofs == 0)                          if (addr < s->addr)
174                                  break;                                  highest = ofs - 1;
175                            else
176                          stepsize >>= 1;                                  lowest = ofs + 1;
   
                         /*  Special case for offset 0 (end of search in  
                             the Left direction  */  
                         if (stepsize == 0)  
                                 ofs = 0;  
                         else {  
                                 if (addr < s->addr)  
                                         ofs -= stepsize;  
                                 else  
                                         ofs += stepsize;  
                         }  
177                  }                  }
178          }          }
179    
# Line 227  void add_symbol_name(struct symbol_conte Line 214  void add_symbol_name(struct symbol_conte
214                  exit(1);                  exit(1);
215          }          }
216    
217            if (addr == 0 && strcmp(name, "_DYNAMIC_LINK") == 0)
218                    return;
219    
220          if (name[0] == '\0')          if (name[0] == '\0')
221                  return;                  return;
222    
# Line 242  void add_symbol_name(struct symbol_conte Line 232  void add_symbol_name(struct symbol_conte
232                          n_args = 2;                          n_args = 2;
233                  if (strcmp(name, "strcpy") == 0)                  if (strcmp(name, "strcpy") == 0)
234                          n_args = 2;                          n_args = 2;
235                    if (strcmp(name, "strncpy") == 0)
236                            n_args = 3;
237                    if (strcmp(name, "strlcpy") == 0)
238                            n_args = 3;
239                    if (strcmp(name, "strlcat") == 0)
240                            n_args = 3;
241                  if (strcmp(name, "strncmp") == 0)                  if (strcmp(name, "strncmp") == 0)
242                          n_args = 3;                          n_args = 3;
243                  if (strcmp(name, "memset") == 0)                  if (strcmp(name, "memset") == 0)
# Line 263  void add_symbol_name(struct symbol_conte Line 259  void add_symbol_name(struct symbol_conte
259                  exit(1);                  exit(1);
260          }          }
261    
262          s->name = strdup(name);          memset(s, 0, sizeof(struct symbol));
263    
264            s->name = symbol_demangle_cplusplus(name);
265    
266          if (s->name == NULL) {          if (s->name == NULL) {
267                  fprintf(stderr, "out of memory\n");                  s->name = strdup(name);
268                  exit(1);                  if (s->name == NULL) {
269                            fprintf(stderr, "out of memory\n");
270                            exit(1);
271                    }
272          }          }
273    
274          s->addr   = addr;          s->addr   = addr;
275          s->len    = len;          s->len    = len;
276          s->type   = type;          s->type   = type;
# Line 405  void symbol_recalc_sizes(struct symbol_c Line 408  void symbol_recalc_sizes(struct symbol_c
408                                      - tmp_array[i].addr;                                      - tmp_array[i].addr;
409                          else                          else
410                                  len = 1;                                  len = 1;
411    
412                          tmp_array[i].len = len;                          tmp_array[i].len = len;
413                  }                  }
414    

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

  ViewVC Help
Powered by ViewVC 1.1.26