Branch: Tag:

2003-03-20

2003-03-20 18:02:57 by Martin Stjernholm <mast@lysator.liu.se>

Backported opcode level trace and debug fixes from 7.5.

Rev: lib/master.pike.in:1.242
Rev: src/code/ia32.c:1.25
Rev: src/interpret.c:1.287
Rev: src/interpret.h:1.121
Rev: src/interpreter.h:1.81
Rev: src/program.h:1.175

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: interpret.c,v 1.286 2003/02/26 18:19:08 mast Exp $ + || $Id: interpret.c,v 1.287 2003/03/20 18:02:57 mast Exp $   */      #include "global.h" - RCSID("$Id: interpret.c,v 1.286 2003/02/26 18:19:08 mast Exp $"); + RCSID("$Id: interpret.c,v 1.287 2003/03/20 18:02:57 mast Exp $");   #include "interpret.h"   #include "object.h"   #include "program.h"
695:   }      #ifdef PIKE_DEBUG +    #define BACKLOG 1024   struct backlog   { - #ifdef HAVE_COMPUTED_GOTO -  PIKE_OPCODE_T instruction; - #else /* !HAVE_COMPUTED_GOTO */ -  INT32 instruction; - #endif /* HAVE_COMPUTED_GOTO */ +  PIKE_INSTR_T instruction;    INT32 arg,arg2;    struct program *program;    PIKE_OPCODE_T *pc;
716:   struct backlog backlog[BACKLOG];   int backlogp=BACKLOG-1;    + static inline void low_debug_instr_prologue (PIKE_OPCODE_T *pc, PIKE_INSTR_T instr) + { +  if(t_flag > 2) +  { +  char *file, *f; +  struct pike_string *filep; +  INT32 linep; +  +  filep = get_line(pc,Pike_fp->context.prog,&linep); +  file = filep->str; +  while((f=STRCHR(file,'/'))) +  file=f+1; +  fprintf(stderr,"- %s:%4ld:(%lx): %-25s %4ld %4ld\n", +  file,(long)linep, +  DO_NOT_WARN((long)(pc-Pike_fp->context.prog->program)), + #ifdef HAVE_COMPUTED_GOTO +  get_opcode_name(instr), + #else /* !HAVE_COMPUTED_GOTO */ +  get_f_name(instr + F_OFFSET), + #endif /* HAVE_COMPUTED_GOTO */ +  DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)), +  DO_NOT_WARN((long)(Pike_mark_sp-Pike_interpreter.mark_stack))); +  free_string(filep); +  } +  + #ifdef HAVE_COMPUTED_GOTO +  if (instr) +  ADD_RUNNED(instr); +  else +  Pike_fatal("NULL Instruction!\n"); + #else /* !HAVE_COMPUTED_GOTO */ +  if(instr + F_OFFSET < F_MAX_OPCODE) +  ADD_RUNNED(instr + F_OFFSET); + #endif /* HAVE_COMPUTED_GOTO */ +  +  if(d_flag) +  { +  backlogp++; +  if(backlogp >= BACKLOG) backlogp=0; +  +  if(backlog[backlogp].program) +  free_program(backlog[backlogp].program); +  +  backlog[backlogp].program=Pike_fp->context.prog; +  add_ref(Pike_fp->context.prog); +  backlog[backlogp].instruction=instr; +  backlog[backlogp].pc=pc; +  backlog[backlogp].stack = Pike_sp - Pike_interpreter.evaluator_stack; +  backlog[backlogp].mark_stack = Pike_mark_sp - Pike_interpreter.mark_stack; + #ifdef _REENTRANT +  backlog[backlogp].thread_id=Pike_interpreter.thread_id; + #endif +  + #ifdef _REENTRANT +  CHECK_INTERPRETER_LOCK(); +  if(OBJ2THREAD(Pike_interpreter.thread_id)->state.thread_id != +  Pike_interpreter.thread_id) +  Pike_fatal("Arglebargle glop glyf, thread swap problem!\n"); +  +  if(d_flag>1 && thread_for_id(th_self()) != Pike_interpreter.thread_id) +  Pike_fatal("thread_for_id() (or Pike_interpreter.thread_id) failed in interpreter.h! %p != %p\n",thread_for_id(th_self()),Pike_interpreter.thread_id); + #endif +  +  Pike_sp[0].type=99; /* an invalid type */ +  Pike_sp[1].type=99; +  Pike_sp[2].type=99; +  Pike_sp[3].type=99; +  +  if(Pike_sp<Pike_interpreter.evaluator_stack || +  Pike_mark_sp < Pike_interpreter.mark_stack || Pike_fp->locals>Pike_sp) +  Pike_fatal("Stack error (generic) sp=%p/%p mark_sp=%p/%p locals=%p.\n", +  Pike_sp, +  Pike_interpreter.evaluator_stack, +  Pike_mark_sp, +  Pike_interpreter.mark_stack, +  Pike_fp->locals); +  +  if(Pike_mark_sp > Pike_interpreter.mark_stack+Pike_stack_size) +  Pike_fatal("Mark Stack error (overflow).\n"); +  +  +  if(Pike_mark_sp < Pike_interpreter.mark_stack) +  Pike_fatal("Mark Stack error (underflow).\n"); +  +  if(Pike_sp > Pike_interpreter.evaluator_stack+Pike_stack_size) +  Pike_fatal("stack error (overflow).\n"); +  +  if(/* Pike_fp->fun>=0 && */ Pike_fp->current_object->prog && +  Pike_fp->locals+Pike_fp->num_locals > Pike_sp) +  Pike_fatal("Stack error (stupid!).\n"); +  +  if(Pike_interpreter.recoveries && +  (Pike_sp-Pike_interpreter.evaluator_stack < +  Pike_interpreter.recoveries->stack_pointer)) +  Pike_fatal("Stack error (underflow).\n"); +  +  if(Pike_mark_sp > Pike_interpreter.mark_stack && +  Pike_mark_sp[-1] > Pike_sp) +  Pike_fatal("Stack error (underflow?)\n"); +  +  if(d_flag > 9) do_debug(); +  +  debug_malloc_touch(Pike_fp->current_object); +  switch(d_flag) +  { +  default: +  case 3: +  check_object(Pike_fp->current_object); +  /* break; */ +  +  case 2: +  check_object_context(Pike_fp->current_object, +  Pike_fp->context.prog, +  Pike_fp->current_object->storage+ +  Pike_fp->context.storage_offset); +  case 1: +  case 0: +  break; +  } +  } + } +  + #define DEBUG_LOG_ARG(ARG) \ +  (backlog[backlogp].arg = (ARG), \ +  (t_flag>3 ? \ +  sprintf(trace_buffer, "- Arg = %ld\n", \ +  (long) backlog[backlogp].arg), \ +  write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0)) +  + #define DEBUG_LOG_ARG2(ARG2) \ +  (backlog[backlogp].arg2 = (ARG2), \ +  (t_flag>3 ? \ +  sprintf(trace_buffer, "- Arg2 = %ld\n", \ +  (long) backlog[backlogp].arg2), \ +  write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0)) +    void dump_backlog(void)   {   #ifdef _REENTRANT
745:    }   #endif    -  file = get_line(backlog[e].pc-1,backlog[e].program, &line); +  file = get_line(backlog[e].pc,backlog[e].program, &line);   #ifdef HAVE_COMPUTED_GOTO -  fprintf(stderr,"%s:%ld: %s", +  fprintf(stderr,"%s:%ld:(%"PRINTPTRDIFFT"d): %s",    file->str,    (long)line, -  +  backlog[e].pc - backlog[e].program->program,    get_opcode_name(backlog[e].instruction));   #else /* !HAVE_COMPUTED_GOTO */ -  if(backlog[e].instruction < 0 || backlog[e].instruction+F_OFFSET > F_MAX_OPCODE) +  if(backlog[e].instruction+F_OFFSET > F_MAX_OPCODE)    { -  fprintf(stderr,"%s:%ld: ILLEGAL INSTRUCTION %d\n", +  fprintf(stderr,"%s:%ld:(%"PRINTPTRDIFFT"d): ILLEGAL INSTRUCTION %d\n",    file->str,    (long)line, -  +  backlog[e].pc - backlog[e].program->program,    backlog[e].instruction + F_OFFSET);    free_string(file);    continue;    }    -  fprintf(stderr,"%s:%ld: %s", +  fprintf(stderr,"%s:%ld:(%"PRINTPTRDIFFT"d): %s",    file->str,    (long)line, -  +  backlog[e].pc - backlog[e].program->program,    low_get_f_name(backlog[e].instruction + F_OFFSET, backlog[e].program));    if(instrs[backlog[e].instruction].flags & I_HASARG2)    {
789:    }while(e!=backlogp);   }    - #endif + #else /* PIKE_DEBUG */ +  + #define DEBUG_LOG_ARG(arg) 0 + #define DEBUG_LOG_ARG2(arg2) 0 +  + #endif /* !PIKE_DEBUG */ +    static int o_catch(PIKE_OPCODE_T *pc);      
827:    } while(0)   #endif /* !CALL_MACHINE_CODE */    + #ifdef PIKE_DEBUG +  + static void debug_instr_prologue (PIKE_OPCODE_T *pc, PIKE_INSTR_T instr) + { +  low_debug_instr_prologue (pc, instr); + } +  + #define DEBUG_PROLOGUE(OPCODE, EXTRA) do { \ +  if (d_flag || t_flag > 2) { \ +  debug_instr_prologue (Pike_fp->pc, (OPCODE) - F_OFFSET); \ +  EXTRA; \ +  } \ +  } while (0) +  + /* The following are intended to be called directly from generated +  * machine code. */ + void simple_debug_instr_prologue_0 (PIKE_OPCODE_T *pc, PIKE_INSTR_T instr) + { +  if (d_flag || t_flag > 2) +  low_debug_instr_prologue (pc, instr); + } + void simple_debug_instr_prologue_1 (PIKE_OPCODE_T *pc, PIKE_INSTR_T instr, +  INT32 arg) + { +  if (d_flag || t_flag > 2) { +  low_debug_instr_prologue (pc, instr); +  DEBUG_LOG_ARG (arg); +  } + } + void simple_debug_instr_prologue_2 (PIKE_OPCODE_T *pc, PIKE_INSTR_T instr, +  INT32 arg1, INT32 arg2) + { +  if (d_flag || t_flag > 2) { +  low_debug_instr_prologue (pc, instr); +  DEBUG_LOG_ARG (arg1); +  DEBUG_LOG_ARG2 (arg2); +  } + } +  + #else /* !PIKE_DEBUG */ + #define DEBUG_PROLOGUE(OPCODE, EXTRA) do {} while (0) + #endif /* !PIKE_DEBUG */ +    #define OPCODE0(O,N,F,C) \   void PIKE_CONCAT(opcode_,O)(void) { \    DEF_PROG_COUNTER; \ - DO_IF_DEBUG(if(t_flag > 3) fprintf(stderr,"- (%p,%ld): %s()\n",PROG_COUNTER,DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)),N));\ +  DEBUG_PROLOGUE (O, ;); \   C }      #define OPCODE1(O,N,F,C) \   void PIKE_CONCAT(opcode_,O)(INT32 arg1) {\    DEF_PROG_COUNTER; \ - DO_IF_DEBUG(if(t_flag > 3) fprintf(stderr,"- (%p,%ld): %s(%d)\n",PROG_COUNTER,DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)),N,arg1)); \ +  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1)); \   C }         #define OPCODE2(O,N,F,C) \   void PIKE_CONCAT(opcode_,O)(INT32 arg1,INT32 arg2) { \    DEF_PROG_COUNTER; \ - DO_IF_DEBUG(if(t_flag > 3) fprintf(stderr,"- (%p,%ld): %s(%d,%d)\n",PROG_COUNTER,DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)),N,arg1,arg2)); \ +  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1); DEBUG_LOG_ARG2 (arg2)); \   C }      #ifdef OPCODE_INLINE_BRANCH
851:   int PIKE_CONCAT(test_opcode_,O)(void) { \    int branch_taken = 0; \    DEF_PROG_COUNTER; \ -  DO_IF_DEBUG(if(t_flag > 3) \ -  fprintf(stderr, "- (%p,%ld): %s()\n", PROG_COUNTER, \ -  DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)), \ -  N));\ +  DEBUG_PROLOGUE (O, ;); \    C; \    return branch_taken; \    }
863:   int PIKE_CONCAT(test_opcode_,O)(INT32 arg1) {\    int branch_taken = 0; \    DEF_PROG_COUNTER; \ -  DO_IF_DEBUG(if(t_flag > 3) \ -  fprintf(stderr, "- (%p,%ld): %s(%d)\n", PROG_COUNTER, \ -  DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)), \ -  N, arg1)); \ +  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1)); \    C; \    return branch_taken; \    }
876:   int PIKE_CONCAT(test_opcode_,O)(INT32 arg1, INT32 arg2) { \    int branch_taken = 0; \    DEF_PROG_COUNTER; \ -  DO_IF_DEBUG(if(t_flag > 3) \ -  fprintf(stderr, "- (%p,%ld): %s(%d,%d)\n", PROG_COUNTER, \ -  DO_NOT_WARN((long)(Pike_sp-Pike_interpreter.evaluator_stack)), \ -  N, arg1, arg2)); \ +  DEBUG_PROLOGUE (O, DEBUG_LOG_ARG (arg1); DEBUG_LOG_ARG2 (arg2)); \    C; \    return branch_taken; \    }