Changeset 439 for EcnlProtoTool/trunk/mruby-2.1.1/src/debug.c
- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-2.1.1
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-2.1.1/src/debug.c
r331 r439 4 4 #include <mruby/debug.h> 5 5 6 static mrb_irep_debug_info_file 6 static mrb_irep_debug_info_file* 7 7 get_file(mrb_irep_debug_info *info, uint32_t pc) 8 8 { … … 52 52 53 53 MRB_API char const* 54 mrb_debug_get_filename(mrb_ irep *irep, uint32_t pc)55 { 56 if (irep && pc < irep->ilen) {54 mrb_debug_get_filename(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc) 55 { 56 if (irep && pc >= 0 && pc < irep->ilen) { 57 57 mrb_irep_debug_info_file* f = NULL; 58 if (!irep->debug_info) { return irep->filename; }59 else if ((f = get_file(irep->debug_info, pc))) {60 return f->filename;58 if (!irep->debug_info) return NULL; 59 else if ((f = get_file(irep->debug_info, (uint32_t)pc))) { 60 return mrb_sym_name_len(mrb, f->filename_sym, NULL); 61 61 } 62 62 } … … 65 65 66 66 MRB_API int32_t 67 mrb_debug_get_line(mrb_ irep *irep, uint32_t pc)68 { 69 if (irep && pc < irep->ilen) {67 mrb_debug_get_line(mrb_state *mrb, mrb_irep *irep, ptrdiff_t pc) 68 { 69 if (irep && pc >= 0 && pc < irep->ilen) { 70 70 mrb_irep_debug_info_file* f = NULL; 71 71 if (!irep->debug_info) { 72 return irep->lines? irep->lines[pc] :-1;73 } 74 else if ((f = get_file(irep->debug_info, pc))) {72 return -1; 73 } 74 else if ((f = get_file(irep->debug_info, (uint32_t)pc))) { 75 75 switch (f->line_type) { 76 76 case mrb_debug_line_ary: … … 109 109 } 110 110 111 MRB_API mrb_irep_debug_info 111 MRB_API mrb_irep_debug_info* 112 112 mrb_debug_info_alloc(mrb_state *mrb, mrb_irep *irep) 113 113 { … … 122 122 } 123 123 124 MRB_API mrb_irep_debug_info_file * 125 mrb_debug_info_append_file(mrb_state *mrb, mrb_irep *irep, 124 MRB_API mrb_irep_debug_info_file* 125 mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d, 126 const char *filename, uint16_t *lines, 126 127 uint32_t start_pos, uint32_t end_pos) 127 128 { 128 mrb_irep_debug_info *info; 129 mrb_irep_debug_info_file *ret; 129 mrb_irep_debug_info_file *f; 130 130 uint32_t file_pc_count; 131 131 size_t fn_len; 132 mrb_int len;133 132 uint32_t i; 134 133 135 if (! irep->debug_info) { return NULL; }136 137 mrb_assert(irep->filename); 138 mrb_assert( irep->lines);139 140 info = irep->debug_info; 141 142 if (info->flen > 0 && strcmp(irep->filename, info->files[info->flen - 1]->filename) == 0) {143 return NULL;144 }145 146 ret = (mrb_irep_debug_info_file *)mrb_malloc(mrb, sizeof(*ret)); 147 info->files =148 149 info->files150 ? mrb_realloc(mrb, info->files, sizeof(mrb_irep_debug_info_file*) * (info->flen + 1))134 if (!d) return NULL; 135 if (start_pos == end_pos) return NULL; 136 137 mrb_assert(filename); 138 mrb_assert(lines); 139 140 if (d->flen > 0) { 141 const char *fn = mrb_sym_name_len(mrb, d->files[d->flen - 1]->filename_sym, NULL); 142 if (strcmp(filename, fn) == 0) 143 return NULL; 144 } 145 146 f = (mrb_irep_debug_info_file*)mrb_malloc(mrb, sizeof(*f)); 147 d->files = (mrb_irep_debug_info_file**)( 148 d->files 149 ? mrb_realloc(mrb, d->files, sizeof(mrb_irep_debug_info_file*) * (d->flen + 1)) 151 150 : mrb_malloc(mrb, sizeof(mrb_irep_debug_info_file*))); 152 info->files[info->flen++] = ret;151 d->files[d->flen++] = f; 153 152 154 153 file_pc_count = end_pos - start_pos; 155 154 156 ret->start_pos = start_pos; 157 info->pc_count = end_pos; 158 159 fn_len = strlen(irep->filename); 160 ret->filename_sym = mrb_intern(mrb, irep->filename, fn_len); 161 len = 0; 162 ret->filename = mrb_sym2name_len(mrb, ret->filename_sym, &len); 163 164 ret->line_type = select_line_type(irep->lines + start_pos, end_pos - start_pos); 165 ret->lines.ptr = NULL; 166 167 switch (ret->line_type) { 155 f->start_pos = start_pos; 156 d->pc_count = end_pos; 157 158 fn_len = strlen(filename); 159 f->filename_sym = mrb_intern(mrb, filename, fn_len); 160 161 f->line_type = select_line_type(lines + start_pos, end_pos - start_pos); 162 f->lines.ptr = NULL; 163 164 switch (f->line_type) { 168 165 case mrb_debug_line_ary: 169 ret->line_entry_count = file_pc_count;170 ret->lines.ary = (uint16_t*)mrb_malloc(mrb, sizeof(uint16_t) * file_pc_count);166 f->line_entry_count = file_pc_count; 167 f->lines.ary = (uint16_t*)mrb_malloc(mrb, sizeof(uint16_t) * file_pc_count); 171 168 for (i = 0; i < file_pc_count; ++i) { 172 ret->lines.ary[i] = irep->lines[start_pos + i];169 f->lines.ary[i] = lines[start_pos + i]; 173 170 } 174 171 break; … … 177 174 uint16_t prev_line = 0; 178 175 mrb_irep_debug_info_line m; 179 ret->lines.flat_map = (mrb_irep_debug_info_line*)mrb_malloc(mrb, sizeof(mrb_irep_debug_info_line) * 1);180 ret->line_entry_count = 0;176 f->lines.flat_map = (mrb_irep_debug_info_line*)mrb_malloc(mrb, sizeof(mrb_irep_debug_info_line) * 1); 177 f->line_entry_count = 0; 181 178 for (i = 0; i < file_pc_count; ++i) { 182 if ( irep->lines[start_pos + i] == prev_line) { continue; }183 184 ret->lines.flat_map = (mrb_irep_debug_info_line*)mrb_realloc(185 mrb, ret->lines.flat_map,186 sizeof(mrb_irep_debug_info_line) * ( ret->line_entry_count + 1));179 if (lines[start_pos + i] == prev_line) { continue; } 180 181 f->lines.flat_map = (mrb_irep_debug_info_line*)mrb_realloc( 182 mrb, f->lines.flat_map, 183 sizeof(mrb_irep_debug_info_line) * (f->line_entry_count + 1)); 187 184 m.start_pos = start_pos + i; 188 m.line = irep->lines[start_pos + i];189 ret->lines.flat_map[ret->line_entry_count] = m;185 m.line = lines[start_pos + i]; 186 f->lines.flat_map[f->line_entry_count] = m; 190 187 191 188 /* update */ 192 ++ ret->line_entry_count;193 prev_line = irep->lines[start_pos + i];189 ++f->line_entry_count; 190 prev_line = lines[start_pos + i]; 194 191 } 195 192 } break; … … 198 195 } 199 196 200 return ret;197 return f; 201 198 } 202 199
Note:
See TracChangeset
for help on using the changeset viewer.