6 void factor_vm::print_chars(string* str)
9 for(i = 0; i < string_capacity(str); i++)
10 putchar(string_nth(str,i));
13 void factor_vm::print_word(word* word, cell nesting)
15 if(tagged<object>(word->vocabulary).type_p(STRING_TYPE))
17 print_chars(untag<string>(word->vocabulary));
21 if(tagged<object>(word->name).type_p(STRING_TYPE))
22 print_chars(untag<string>(word->name));
25 print_string("#<not a string: ");
26 print_nested_obj(word->name,nesting);
31 void factor_vm::print_factor_string(string* str)
38 void factor_vm::print_array(array* array, cell nesting)
40 cell length = array_capacity(array);
44 if(length > 10 && !full_output)
52 for(i = 0; i < length; i++)
55 print_nested_obj(array_nth(array,i),nesting);
62 void factor_vm::print_tuple(tuple *tuple, cell nesting)
64 tuple_layout *layout = untag<tuple_layout>(tuple->layout);
65 cell length = to_fixnum(layout->size);
68 print_nested_obj(layout->klass,nesting);
73 if(length > 10 && !full_output)
81 for(i = 0; i < length; i++)
84 print_nested_obj(tuple->data()[i],nesting);
91 void factor_vm::print_nested_obj(cell obj, fixnum nesting)
93 if(nesting <= 0 && !full_output)
95 print_string(" ... ");
101 switch(tagged<object>(obj).type())
104 print_fixnum(untag_fixnum(obj));
107 print_word(untag<word>(obj),nesting - 1);
110 print_factor_string(untag<string>(obj));
117 print_tuple(untag<tuple>(obj),nesting - 1);
122 print_array(untag<array>(obj),nesting - 1);
127 quot = untag<quotation>(obj);
128 print_array(untag<array>(quot->array),nesting - 1);
132 print_string("#<type ");
133 print_cell(tagged<object>(obj).type());
141 void factor_vm::print_obj(cell obj)
143 print_nested_obj(obj,10);
146 void factor_vm::print_objects(cell *start, cell *end)
148 for(; start <= end; start++)
155 void factor_vm::print_datastack()
157 print_string("==== DATA STACK:\n");
158 print_objects((cell *)ds_bot,(cell *)ds);
161 void factor_vm::print_retainstack()
163 print_string("==== RETAIN STACK:\n");
164 print_objects((cell *)rs_bot,(cell *)rs);
167 void factor_vm::print_stack_frame(stack_frame *frame)
169 print_obj(frame_executing(frame));
171 print_obj(frame_scan(frame));
173 print_string("word/quot addr: ");
174 print_cell_hex((cell)frame_executing(frame));
176 print_string("word/quot xt: ");
177 print_cell_hex((cell)frame->xt);
179 print_string("return address: ");
180 print_cell_hex((cell)FRAME_RETURN_ADDRESS(frame));
184 void print_stack_frame(stack_frame *frame, factor_vm *myvm)
186 return myvm->print_stack_frame(frame);
189 void factor_vm::print_callstack()
191 print_string("==== CALL STACK:\n");
192 cell bottom = (cell)stack_chain->callstack_bottom;
193 cell top = (cell)stack_chain->callstack_top;
194 iterate_callstack(top,bottom,factor::print_stack_frame);
197 void factor_vm::dump_cell(cell x)
199 print_cell_hex_pad(x); print_string(": ");
201 print_cell_hex_pad(x); print_string(" tag "); print_cell(TAG(x));
205 void factor_vm::dump_memory(cell from, cell to)
209 for(; from <= to; from += sizeof(cell))
213 void factor_vm::dump_zone(zone *z)
215 print_string("Start="); print_cell(z->start);
216 print_string(", size="); print_cell(z->size);
217 print_string(", here="); print_cell(z->here - z->start); nl();
220 void factor_vm::dump_generations()
224 print_string("Nursery: ");
227 for(i = 1; i < data->gen_count; i++)
229 print_string("Generation "); print_cell(i); print_string(": ");
230 dump_zone(&data->generations[i]);
233 for(i = 0; i < data->gen_count; i++)
235 print_string("Semispace "); print_cell(i); print_string(": ");
236 dump_zone(&data->semispaces[i]);
239 print_string("Cards: base=");
240 print_cell((cell)data->cards);
241 print_string(", size=");
242 print_cell((cell)(data->cards_end - data->cards));
246 void factor_vm::dump_objects(cell type)
252 while((obj = next_object()) != F)
254 if(type == TYPE_COUNT || tagged<object>(obj).type_p(type))
256 print_cell_hex_pad(obj);
258 print_nested_obj(obj,2);
266 void factor_vm::find_data_references_step(cell *scan)
268 if(look_for == *scan)
270 print_cell_hex_pad(obj);
272 print_nested_obj(obj,2);
277 void find_data_references_step(cell *scan,factor_vm *myvm)
279 return myvm->find_data_references_step(scan);
282 void factor_vm::find_data_references(cell look_for_)
284 look_for = look_for_;
288 while((obj = next_object()) != F)
289 do_slots(UNTAG(obj),factor::find_data_references_step);
294 /* Dump all code blocks for debugging */
295 void factor_vm::dump_code_heap()
297 cell reloc_size = 0, literal_size = 0;
299 heap_block *scan = code->first_block();
310 reloc_size += object_size(((code_block *)scan)->relocation);
311 literal_size += object_size(((code_block *)scan)->literals);
312 status = "allocated";
315 reloc_size += object_size(((code_block *)scan)->relocation);
316 literal_size += object_size(((code_block *)scan)->literals);
324 print_cell_hex((cell)scan); print_string(" ");
325 print_cell_hex(scan->size); print_string(" ");
326 print_string(status); print_string("\n");
328 scan = code->next_block(scan);
331 print_cell(reloc_size); print_string(" bytes of relocation data\n");
332 print_cell(literal_size); print_string(" bytes of literal data\n");
335 void factor_vm::factorbug()
339 print_string("Low level debugger disabled\n");
343 /* open_console(); */
345 print_string("Starting low level debugger...\n");
346 print_string(" Basic commands:\n");
347 print_string("q -- continue executing Factor - NOT SAFE\n");
348 print_string("im -- save image to fep.image\n");
349 print_string("x -- exit Factor\n");
350 print_string(" Advanced commands:\n");
351 print_string("d <addr> <count> -- dump memory\n");
352 print_string("u <addr> -- dump object at tagged <addr>\n");
353 print_string(". <addr> -- print object at tagged <addr>\n");
354 print_string("t -- toggle output trimming\n");
355 print_string("s r -- dump data, retain stacks\n");
356 print_string(".s .r .c -- print data, retain, call stacks\n");
357 print_string("e -- dump environment\n");
358 print_string("g -- dump generations\n");
359 print_string("card <addr> -- print card containing address\n");
360 print_string("addr <card> -- print address containing card\n");
361 print_string("data -- data heap dump\n");
362 print_string("words -- words dump\n");
363 print_string("tuples -- tuples dump\n");
364 print_string("refs <addr> -- find data heap references to object\n");
365 print_string("push <addr> -- push object on data stack - NOT SAFE\n");
366 print_string("code -- code heap dump\n");
368 bool seen_command = false;
374 print_string("READY\n");
377 if(scanf("%1000s",cmd) <= 0)
381 /* If we exit with an EOF immediately, then
382 dump stacks. This is useful for builder and
383 other cases where Factor is run with stdin
384 redirected to /dev/null */
397 if(strcmp(cmd,"d") == 0)
399 cell addr = read_cell_hex();
400 if(scanf(" ") < 0) break;
401 cell count = read_cell_hex();
402 dump_memory(addr,addr+count);
404 else if(strcmp(cmd,"u") == 0)
406 cell addr = read_cell_hex();
407 cell count = object_size(addr);
408 dump_memory(addr,addr+count);
410 else if(strcmp(cmd,".") == 0)
412 cell addr = read_cell_hex();
416 else if(strcmp(cmd,"t") == 0)
417 full_output = !full_output;
418 else if(strcmp(cmd,"s") == 0)
419 dump_memory(ds_bot,ds);
420 else if(strcmp(cmd,"r") == 0)
421 dump_memory(rs_bot,rs);
422 else if(strcmp(cmd,".s") == 0)
424 else if(strcmp(cmd,".r") == 0)
426 else if(strcmp(cmd,".c") == 0)
428 else if(strcmp(cmd,"e") == 0)
431 for(i = 0; i < USER_ENV; i++)
432 dump_cell((cell)&userenv[i]);
434 else if(strcmp(cmd,"g") == 0)
436 else if(strcmp(cmd,"card") == 0)
438 cell addr = read_cell_hex();
439 print_cell_hex((cell)addr_to_card(addr));
442 else if(strcmp(cmd,"addr") == 0)
444 card *ptr = (card *)read_cell_hex();
445 print_cell_hex(card_to_addr(ptr));
448 else if(strcmp(cmd,"q") == 0)
450 else if(strcmp(cmd,"x") == 0)
452 else if(strcmp(cmd,"im") == 0)
453 save_image(STRING_LITERAL("fep.image"));
454 else if(strcmp(cmd,"data") == 0)
455 dump_objects(TYPE_COUNT);
456 else if(strcmp(cmd,"refs") == 0)
458 cell addr = read_cell_hex();
459 print_string("Data heap references:\n");
460 find_data_references(addr);
463 else if(strcmp(cmd,"words") == 0)
464 dump_objects(WORD_TYPE);
465 else if(strcmp(cmd,"tuples") == 0)
466 dump_objects(TUPLE_TYPE);
467 else if(strcmp(cmd,"push") == 0)
469 cell addr = read_cell_hex();
472 else if(strcmp(cmd,"code") == 0)
475 print_string("unknown command\n");
479 void factor_vm::primitive_die()
481 print_string("The die word was called by the library. Unless you called it yourself,\n");
482 print_string("you have triggered a bug in Factor. Please report.\n");