Branch: Tag:

2019-08-02

2019-08-02 09:02:25 by Henrik Grubbström (Grubba) <grubba@grubba.org>

decode_value: Initial support for disassembly-style debug output.

This is analogous to recent changes in encode_value().

70:    data->debug_pos = end_pos; \    } \    } while(0) +  + #define DECODE_WERR_COMMENT(COMMENT, X...) do { \ +  string_builder_sprintf_disassembly(data->debug_buf, \ +  data->debug_ptr, \ +  data->data + data->debug_ptr, \ +  data->data + data->ptr, \ +  COMMENT, X); \ +  data->debug_ptr = data->ptr; \ +  } while(0) + #define DECODE_WERR(X...) DECODE_WERR_COMMENT(NULL, X) + #define DECODE_FLUSH() do { \ +  if (data->debug_ptr < data->ptr) { \ +  string_builder_append_disassembly_data(data->debug_buf, \ +  data->debug_ptr, \ +  data->data + \ +  data->debug_ptr, \ +  data->data + data->ptr, \ +  NULL); \ +  data->debug_ptr = data->ptr; \ +  } \ +  } while(0)   #ifndef PIKE_DEBUG   #error ENCODE_DEBUG requires PIKE_DEBUG   #endif
2448: Inside #if defined(ENCODE_DEBUG)
  #endif   #ifdef ENCODE_DEBUG    int debug, depth; +  ptrdiff_t debug_ptr; +  struct string_builder *debug_buf;   #endif   };   
4516:   static INT32 my_decode(struct pike_string *tmp,    struct object *codec   #ifdef ENCODE_DEBUG -  , int debug +  , int debug, struct string_builder *debug_buf   #endif    )   {    struct decode_data *data;    ONERROR err; -  + #ifdef ENCODE_DEBUG +  struct string_builder buf; + #endif    -  +  /* FIXME: Why not use CYCLIC? */    /* Attempt to avoid infinite recursion on circular structures. */    for (data = current_decode; data; data=data->next) {    if (data->raw == tmp &&
4564: Inside #if defined(ENCODE_DEBUG)
  #endif   #ifdef ENCODE_DEBUG    data->debug = debug; +  data->debug_buf = debug_buf; +  data->debug_ptr = 0; +  if (data->debug && !debug_buf) { +  debug_buf = &buf; +  init_string_builder(debug_buf, 0); +  }    data->depth = -2;   #endif   
4591:       UNSET_ONERROR(err);    +  EDB(1, { +  DECODE_FLUSH(); +  }); +  + #ifdef ENCODE_DEBUG +  if (debug_buf == &buf) { +  write_and_reset_string_builder(2, debug_buf); +  free_string_builder(debug_buf); +  } + #endif +     {    int delay;    delay = 0;
4908: Inside #if defined(ENCODE_DEBUG)
     #ifdef ENCODE_DEBUG    int debug = 0; +  struct string_builder *debug_buf = NULL;   #endif /* ENCODE_DEBUG */       check_all_args(NULL, args,
4918: Inside #if defined(ENCODE_DEBUG)
   * It's intentionally not part of the function    * prototype, to keep the argument position free for    * other uses in the future. */ -  BIT_VOID | BIT_INT, +  BIT_VOID | BIT_INT | BIT_OBJECT,   #endif    0);   
4927:    switch (args) {    default:   #ifdef ENCODE_DEBUG +  if (TYPEOF(Pike_sp[2-args]) == PIKE_T_OBJECT) { +  struct object *sb = Pike_sp[2-args].u.object; +  if ((debug_buf = string_builder_from_string_buffer(sb))) { +  debug = 1; +  } +  } else {    debug = Pike_sp[2-args].u.integer; -  +  }    /* Fall through. */    case 2:   #endif
4956:       if(!my_decode(s, codec   #ifdef ENCODE_DEBUG -  , debug +  , debug, debug_buf   #endif    ))    {