pike.git / src / interpret.c

version» Context lines:

pike.git/src/interpret.c:99: Inside #if defined(INTERNAL_PROFILING)
  #ifdef INTERNAL_PROFILING   PMOD_EXPORT unsigned long evaluator_callback_calls = 0;   #endif         int fast_check_threads_counter = 0;      PMOD_EXPORT int Pike_stack_size = EVALUATOR_STACK_SIZE;      static void do_trace_call(struct byte_buffer *buf, INT32 args); - static void do_trace_func_return (int got_retval, struct object *o, int fun); + static void do_trace_func_return (struct object *o, int fun, int got_retval);   static void do_trace_return (struct byte_buffer *buf, int got_retval); - static void do_trace_efun_call(const struct svalue *s, INT32 args); +    #ifdef PIKE_DEBUG -  + static void do_trace_efun_call(const struct svalue *s, INT32 args);   static void do_trace_efun_return(const struct svalue *s, int got_retval);   #endif      void push_sp_mark(void)   {    if(Pike_mark_sp == Pike_interpreter.mark_stack + Pike_stack_size)    Pike_error("No more mark stack!\n");    *Pike_mark_sp++=Pike_sp;   }   ptrdiff_t pop_sp_mark(void)
pike.git/src/interpret.c:1814:   #include "interpreter.h"   #endif         #endif /* PIKE_USE_MACHINE_CODE */      #undef REAL_PIKE_DEBUG   #undef DO_IF_REAL_DEBUG   #undef DO_IF_NOT_REAL_DEBUG    -  +    ATTRIBUTE((noinline))   static void do_trace_call(struct byte_buffer *b, INT32 args)   {    struct pike_string *filep = NULL;    char *file;    const char *s;    INT_TYPE linep;    INT32 e;    ptrdiff_t len = 0;   
pike.git/src/interpret.c:1882:    } else {    fprintf(stderr, "- %s: %s\n", file, s);    }       if (filep) {    free_string(filep);    }    buffer_free(b);   }    + #ifdef PIKE_DEBUG   ATTRIBUTE((noinline)) - static void do_dtrace_function_call(struct object *o, const struct identifier *function, INT32 args) { -  /* DTrace enter probe -  arg0: function name -  arg1: object -  */ -  struct byte_buffer obj_name = BUFFER_INIT(); -  struct svalue obj_sval; -  SET_SVAL(obj_sval, T_OBJECT, 0, object, o); -  safe_describe_svalue(&obj_name, &obj_sval, 0, NULL); -  PIKE_FN_START(function->name->size_shift == 0 ? -  function->name->str : "[widestring fn name]", -  buffer_get_string(s)); -  buffer_free(&obj_name); + static void do_trace_efun_call(const struct svalue *s, INT32 args) { +  if (Pike_interpreter.trace_level > 1) { +  struct byte_buffer buf = BUFFER_INIT(); +  if (s->u.efun->name->size_shift) +  buffer_add_str (&buf, "[widestring function name]"); +  else +  buffer_add_str (&buf, s->u.efun->name->str); +  do_trace_call(&buf, args);    } -  - ATTRIBUTE((noinline)) - static void do_dtrace_func_return(struct object *o, int fun) { -  /* DTrace leave probe -  arg0: function name -  */ -  char *fn = "(unknown)"; -  if (o && o->prog) { -  struct identifier *id = ID_FROM_INT(o->prog, fun); -  fn = id->name->size_shift == 0 ? id->name->str : "[widestring fn name]"; -  } -  PIKE_FN_DONE(fn); - } -  - ATTRIBUTE((noinline)) - static void do_dtrace_efun_call(const struct svalue *s, INT32 args) { +  if (PIKE_FN_START_ENABLED()) {    /* DTrace enter probe    arg0: function name    arg1: object    */    PIKE_FN_START(s->u.efun->name->size_shift == 0 ?    s->u.efun->name->str : "[widestring fn name]",    "");    } - ATTRIBUTE((noinline)) - static void do_dtrace_efun_return(const struct svalue *s, INT32 args) { -  /* DTrace leave probe -  arg0: function name -  */ -  PIKE_FN_DONE(s->u.efun->name->size_shift == 0 ? -  s->u.efun->name->str : "[widestring fn name]"); +    }      ATTRIBUTE((noinline)) - static void do_trace_function_call(const struct object *o, const struct identifier *function, INT32 args) { -  struct byte_buffer buffer = BUFFER_INIT(); -  char buf[50]; -  -  sprintf(buf, "%lx->", (long) PTR_TO_INT (o)); -  buffer_add_str(&buffer, buf); -  if (function->name->size_shift) -  buffer_add_str (&buffer, "[widestring function name]"); -  else -  buffer_add_str(&buffer, function->name->str); -  do_trace_call(&buffer, args); - } -  - ATTRIBUTE((noinline)) - static void do_trace_efun_call(const struct svalue *s, INT32 args) { + static void do_trace_efun_return(const struct svalue *s, int got_retval) { +  if (Pike_interpreter.trace_level > 1) {    struct byte_buffer buf = BUFFER_INIT();    if (s->u.efun->name->size_shift)    buffer_add_str (&buf, "[widestring function name]");    else    buffer_add_str (&buf, s->u.efun->name->str); -  do_trace_call(&buf, args); +  buffer_add_str (&buf, "() "); +  do_trace_return (&buf, got_retval);    } -  - ATTRIBUTE((noinline)) - static void do_trace_svalue_call(const struct svalue *s, INT32 args) { -  struct byte_buffer buf = BUFFER_INIT(); -  safe_describe_svalue(&buf, s,0,0); -  do_trace_call(&buf, args); +  if (PIKE_FN_DONE_ENABLED()) { +  /* DTrace leave probe +  arg0: function name +  */ +  PIKE_FN_DONE(s->u.efun->name->size_shift == 0 ? +  s->u.efun->name->str : "[widestring fn name]");    } -  + } + #endif    -  +    ATTRIBUTE((noinline)) - static void do_trace_func_return (int got_retval, struct object *o, int fun) + static void do_trace_func_return (struct object *o, int fun, int got_retval)   {    struct byte_buffer b = BUFFER_INIT();    if (o) {    if (o->prog) {    struct identifier *id = ID_FROM_INT (o->prog, fun);    char buf[50];    sprintf(buf, "%lx->", (long) PTR_TO_INT (o));    buffer_add_str(&b, buf);    if (id->name->size_shift)    buffer_add_str (&b, "[widestring function name]");    else    buffer_add_str(&b, id->name->str);    buffer_add_str (&b, "() ");    }    else    buffer_add_str (&b, "function in destructed object ");    }    do_trace_return (&b, got_retval);   }    - #ifdef PIKE_DEBUG +    ATTRIBUTE((noinline)) - static void do_trace_efun_return(const struct svalue *s, int got_retval) { -  struct byte_buffer buf = BUFFER_INIT(); -  if (s->u.efun->name->size_shift) -  buffer_add_str (&buf, "[widestring function name]"); -  else -  buffer_add_str (&buf, s->u.efun->name->str); -  buffer_add_str (&buf, "() "); -  do_trace_return (&buf, got_retval); - } - #endif -  - ATTRIBUTE((noinline)) +    static void do_trace_return (struct byte_buffer *b, int got_retval)   {    struct pike_string *filep = NULL;    char *file;    const char *s;    INT_TYPE linep;       if (got_retval) {    buffer_add_str (b, "returns: ");    safe_describe_svalue(b, Pike_sp-1,0,0);
pike.git/src/interpret.c:2300:    if( objects_to_destruct )    destruct_objects_to_destruct();    }      #ifdef PIKE_DEBUG    if(save_sp+1 > Pike_sp && !pop)    Pike_fatal("Pike function did not leave a return value\n");   #endif       if(UNLIKELY(Pike_interpreter.trace_level>1)) -  do_trace_func_return (1, o, fun); +  do_trace_func_return (o, fun, 1);      #if defined (PIKE_USE_MACHINE_CODE) && defined (OPCODE_RETURN_JUMPADDR)    free_object (o);   #endif   }      void unlink_previous_frame(void)   {    struct pike_frame *current, *prev;   
pike.git/src/interpret.c:3310: Inside #if defined(DO_PIKE_CLEANUP)
   free_all_pike_frame_blocks();    free_all_catch_context_blocks();   #endif   }      /*    * Low level function call API.    *    */    + static void callsite_trace_return(const struct pike_callsite *c); + static void callsite_trace_call_fun(const struct pike_callsite *c); + static void callsite_trace_call_svalue(const struct pike_callsite *c, const struct svalue *s); +    ATTRIBUTE((noreturn, noinline))   static void callsite_svalue_error(struct pike_callsite *c, const struct svalue *s) {    INT32 args = c->args;       switch(TYPEOF(*s))    {    case T_INT:    if (!s->u.integer) {    PIKE_ERROR("0", "Attempt to call the NULL-value\n", Pike_sp, args);    } else {
pike.git/src/interpret.c:3474:    } while (IDENTIFIER_IS_ALIAS(function->identifier_flags));       callsite_resolve_fun(c, o, fun);    return;    }   #ifdef PIKE_DEBUG    Pike_fatal("Unknown identifier type.\n");   #endif    UNREACHABLE(break);    } -  +     /*    * The cases which do _not_ return, have a frame created. These are:    * CALLTYPE_CFUN, CALLTYPE_PIKEFUN and CALLTYPE_PARENT_CLONE.    */       add_ref(o);    add_ref(p);       struct pike_frame *frame = alloc_pike_frame();   
pike.git/src/interpret.c:3510:    frame->scope = scope;    frame->save_mark_sp=Pike_mark_sp;    frame->return_addr = NULL;    frame_set_save_sp(frame, c->retval);       Pike_fp = frame;    c->frame = frame;       check_stack(256);    check_mark_stack(256); +  +  if (PIKE_NEEDS_TRACE()) +  callsite_trace_call_fun(c);   }      PMOD_EXPORT void callsite_resolve_lfun(struct pike_callsite *c, struct object *o, int lfun) {    struct program *p = o->prog;      #ifdef PIKE_DEBUG    if(lfun < 0 || lfun >= NUM_LFUNS)    Pike_fatal("Illegal lfun.\n");   #endif    if(!p)
pike.git/src/interpret.c:3562:    c->ptr = s->u.type;    break;    case T_PROGRAM:    c->type = CALLTYPE_CLONE;    c->ptr = s->u.program;    break;    case T_OBJECT:    callsite_resolve_lfun(c, s->u.object, LFUN_CALL);    return;    } +  if (PIKE_NEEDS_TRACE()) +  callsite_trace_call_svalue(c, s);   }      PMOD_EXPORT void callsite_reset_pikecall(struct pike_callsite *c) {    struct pike_frame *frame;      #ifdef PIKE_DEBUG    if (c->type != CALLTYPE_PIKEFUN)    Pike_fatal("Calling callsite_reset_pikecall() on non pike frame.\n");   #endif   
pike.git/src/interpret.c:3732:    push_int(0);    } else got_retval = 0;    } else if (retval+1 < sp) {    /* garbage left on the stack */    if (pop)    pop_n_elems(sp-retval);    else    stack_pop_n_elems_keep_top (sp - retval - 1);    low_destruct_objects_to_destruct();    } +  +  if (PIKE_NEEDS_TRACE()) +  callsite_trace_return(c);   }    -  + ATTRIBUTE((noinline)) + static void callsite_trace_call_fun(const struct pike_callsite *c) { +  struct object *o = Pike_fp->current_object; +  struct identifier *function = ID_FROM_INT (o->prog, Pike_fp->fun); +  +  if (Pike_interpreter.trace_level > 1) { +  struct byte_buffer buf = BUFFER_INIT(); +  char tmp[50]; +  +  sprintf(tmp, "%lx->", (long) PTR_TO_INT (o)); +  buffer_add_str(&buf, tmp); +  if (function->name->size_shift) +  buffer_add_str (&buf, "[widestring function name]"); +  else +  buffer_add_str(&buf, function->name->str); +  do_trace_call(&buf, c->args); +  } +  if (PIKE_FN_START_ENABLED()) { +  /* DTrace enter probe +  arg0: function name +  arg1: object +  */ +  struct byte_buffer buf = BUFFER_INIT(); +  struct svalue obj_sval; +  SET_SVAL(obj_sval, T_OBJECT, 0, object, o); +  safe_describe_svalue(&buf, &obj_sval, 0, NULL); +  PIKE_FN_START(function->name->size_shift == 0 ? +  function->name->str : "[widestring fn name]", +  buffer_get_string(s)); +  buffer_free(&buf); +  } + } +  + ATTRIBUTE((noinline)) + static void callsite_trace_call_svalue(const struct pike_callsite *c, const struct svalue *s) { +  if (Pike_interpreter.trace_level > 1) { +  struct byte_buffer buf = BUFFER_INIT(); +  +  switch (c->type) { +  case CALLTYPE_EFUN: +  if (s->u.efun->name->size_shift) +  buffer_add_str (&buf, "[widestring function name]"); +  else +  buffer_add_str (&buf, s->u.efun->name->str); +  break; +  default: +  /* this is CAST, CALL_ARRAY and the CLONE variants */ +  safe_describe_svalue(&buf, s, 0, 0); +  break; +  } +  +  do_trace_call(&buf, c->args); +  } +  if (PIKE_FN_START_ENABLED()) { +  struct byte_buffer buf = BUFFER_INIT(); +  const char *str; +  +  switch (c->type) { +  case CALLTYPE_EFUN: +  if (s->u.efun->name->size_shift) +  buffer_add_str (&buf, "[widestring function name]"); +  else +  buffer_add_str (&buf, s->u.efun->name->str); +  break; +  default: +  /* this is CAST, CALL_ARRAY and the CLONE variants */ +  safe_describe_svalue(&buf, s, 0, 0); +  break; +  } +  +  PIKE_FN_START(buffer_get_string(&buf), ""); +  buffer_free(&buf); +  } + } +  + ATTRIBUTE((noinline)) + static void callsite_trace_return(const struct pike_callsite *c) { +  if (Pike_interpreter.trace_level > 1) { +  int got_retval = c->retval < Pike_sp; +  +  if (c->type == CALLTYPE_CFUN || c->type == CALLTYPE_PIKEFUN) { +  do_trace_func_return(c->frame->current_object, c->frame->fun, got_retval); +  } else { +  struct byte_buffer buf = BUFFER_INIT(); +  +  if (c->type == CALLTYPE_EFUN) { +  buffer_add_str(&buf, "EFUN"); +  } else { +  struct svalue sv; +  +  switch (c->type) { +  case CALLTYPE_PARENT_CLONE: +  case CALLTYPE_CLONE: +  SET_SVAL(sv, T_PROGRAM, 0, program, c->ptr); +  break; +  case CALLTYPE_CAST: +  SET_SVAL(sv, T_TYPE, 0, type, c->ptr); +  break; +  default: +  /* not really reachable */ +  SET_SVAL(sv, T_INT, 0, integer, 0); +  break; +  } +  safe_describe_svalue(&buf, &sv, 0, 0); +  } +  +  do_trace_return(&buf, got_retval); +  } +  } +  if (PIKE_FN_DONE_ENABLED()) { +  /* TODO: fixme */ +  } + } +  +    /* Without fancy accounting stuff. This one can't assume there is an    * identifier corresponding to the frame (i.e. _fp_->ident might be    * bogus). */   void LOW_POP_PIKE_FRAME(struct pike_frame *frame) {    struct pike_frame *tmp_=frame->next;    if(!sub_ref(frame))    {    really_free_pike_frame(frame);    }else{    ptrdiff_t exp_offset = frame->expendible_offset;