pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:79:   {   }   #endif      static void low_enter_compiler(struct object *ce, int inherit);   static void exit_program_struct(struct program *);   static size_t add_xstorage(size_t size,    size_t alignment,    ptrdiff_t modulo_orig);    + /* mapping(int:string) */ + static struct mapping *reverse_symbol_table = NULL; +    static struct block_allocator program_allocator = BA_INIT_PAGES(sizeof(struct program), 4);      ATTRIBUTE((malloc))   struct program * alloc_program(void) {    return ba_alloc(&program_allocator);   }      void really_free_program(struct program * p) {    exit_program_struct(p);    ba_free(&program_allocator, p);
pike.git/src/program.c:11301: Inside #if defined(FIND_FUNCTION_HASHSIZE)
   {    if(cache[e].name)    {    free_string(cache[e].name);    cache[e].name=0;    }    }   #endif      #ifdef DO_PIKE_CLEANUP +  if (reverse_symbol_table) { +  free_mapping(reverse_symbol_table); +  reverse_symbol_table = NULL; +  } +     if(pike_trampoline_program)    {    free_program(pike_trampoline_program);    pike_trampoline_program=0;    }       if(null_program)    {    free_program(null_program);    null_program=0;
pike.git/src/program.c:12696:    if (!comment[0]) comment = NULL;    } else {    string_builder_sprintf(s, " # %s\n", comment);    comment = NULL;    }    } else {    string_builder_sprintf(s, "\n");    }    }   } +  + PMOD_EXPORT void add_reverse_symbol(struct pike_string *sym, void *addr) + { +  struct svalue key; +  struct svalue val; +  SET_SVAL(key, PIKE_T_INT, NUMBER_NUMBER, integer, (ptrdiff_t)addr); +  SET_SVAL(val, PIKE_T_STRING, 0, string, sym); +  low_mapping_insert(reverse_symbol_table, &key, &val, 1); + } +  + PMOD_EXPORT void simple_add_reverse_symbol(const char *sym, void *addr) + { +  struct pike_string *s = make_shared_string(sym); +  add_reverse_symbol(s, addr); +  free_string(s); + } +  + PMOD_EXPORT void init_reverse_symbol_table() + { +  int op; +  +  if (reverse_symbol_table) return; +  reverse_symbol_table = allocate_mapping(256); +  +  /* Initialize with the most popular symbols. */ + #define ADD_SYMBOL(SYM) simple_add_reverse_symbol(#SYM "()", (void *)(SYM)) + #ifdef PIKE_DEBUG +  ADD_SYMBOL(simple_debug_instr_prologue_0); +  ADD_SYMBOL(simple_debug_instr_prologue_1); +  ADD_SYMBOL(simple_debug_instr_prologue_2); + #endif +  ADD_SYMBOL(low_return); +  ADD_SYMBOL(low_return_pop); +  ADD_SYMBOL(really_free_svalue); +  ADD_SYMBOL(lvalue_to_svalue_no_free); +  ADD_SYMBOL(f_add); +  ADD_SYMBOL(really_free_string); +  ADD_SYMBOL(pike_sizeof); +  ADD_SYMBOL(o_subtract); +  ADD_SYMBOL(svalue_is_true); +  ADD_SYMBOL(assign_lvalue); +  ADD_SYMBOL(really_free_array); +  ADD_SYMBOL(object_low_set_index); +  ADD_SYMBOL(low_object_index_no_free); +  ADD_SYMBOL(assign_to_short_svalue); +  ADD_SYMBOL(really_free_short_svalue_ptr); +  ADD_SYMBOL(mega_apply); +  +  simple_add_reverse_symbol("Pike_interpreter_pointer", +  &Pike_interpreter_pointer); +  + #ifdef PIKE_USE_MACHINE_CODE +  /* Add the opcodes as well. */ +  for (op = 1; op < (F_MAX_INSTR - F_OFFSET); op++) { +  if (!instrs[op].address) continue; +  simple_add_reverse_symbol(instrs[op].name, instrs[op].address); +  } + #endif /* PIKE_USE_MACHINE_CODE */ + } +  + PMOD_EXPORT struct pike_string *reverse_symbol_lookup(void *addr) + { +  struct svalue key; +  struct svalue *s; +  if (!reverse_symbol_table) { +  init_reverse_symbol_table(); +  } +  SET_SVAL(key, PIKE_T_INT, NUMBER_NUMBER, integer, (ptrdiff_t)addr); +  s = low_mapping_lookup(reverse_symbol_table, &key); +  +  /* FIXME: Fall back to using dladdr() on supported OSes? */ +  if (!s || (TYPEOF(*s) != PIKE_T_STRING)) return NULL; +  return s->u.string; + }