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);
267 void factor_vm::find_data_references_step(cell *scan)
269 if(look_for == *scan)
271 print_cell_hex_pad(obj);
273 print_nested_obj(obj,2);
278 void find_data_references_step(cell *scan,factor_vm *myvm)
280 return myvm->find_data_references_step(scan);
283 void factor_vm::find_data_references(cell look_for_)
285 look_for = look_for_;
289 while((obj = next_object()) != F)
290 do_slots(UNTAG(obj),factor::find_data_references_step);
295 /* Dump all code blocks for debugging */
296 void factor_vm::dump_code_heap()
298 cell reloc_size = 0, literal_size = 0;
300 heap_block *scan = first_block(&code);
311 reloc_size += object_size(((code_block *)scan)->relocation);
312 literal_size += object_size(((code_block *)scan)->literals);
313 status = "allocated";
316 reloc_size += object_size(((code_block *)scan)->relocation);
317 literal_size += object_size(((code_block *)scan)->literals);
325 print_cell_hex((cell)scan); print_string(" ");
326 print_cell_hex(scan->size); print_string(" ");
327 print_string(status); print_string("\n");
329 scan = next_block(&code,scan);
332 print_cell(reloc_size); print_string(" bytes of relocation data\n");
333 print_cell(literal_size); print_string(" bytes of literal data\n");
336 void factor_vm::factorbug()
340 print_string("Low level debugger disabled\n");
344 /* open_console(); */
346 print_string("Starting low level debugger...\n");
347 print_string(" Basic commands:\n");
348 print_string("q -- continue executing Factor - NOT SAFE\n");
349 print_string("im -- save image to fep.image\n");
350 print_string("x -- exit Factor\n");
351 print_string(" Advanced commands:\n");
352 print_string("d <addr> <count> -- dump memory\n");
353 print_string("u <addr> -- dump object at tagged <addr>\n");
354 print_string(". <addr> -- print object at tagged <addr>\n");
355 print_string("t -- toggle output trimming\n");
356 print_string("s r -- dump data, retain stacks\n");
357 print_string(".s .r .c -- print data, retain, call stacks\n");
358 print_string("e -- dump environment\n");
359 print_string("g -- dump generations\n");
360 print_string("card <addr> -- print card containing address\n");
361 print_string("addr <card> -- print address containing card\n");
362 print_string("data -- data heap dump\n");
363 print_string("words -- words dump\n");
364 print_string("tuples -- tuples dump\n");
365 print_string("refs <addr> -- find data heap references to object\n");
366 print_string("push <addr> -- push object on data stack - NOT SAFE\n");
367 print_string("code -- code heap dump\n");
369 bool seen_command = false;
375 print_string("READY\n");
378 if(scanf("%1000s",cmd) <= 0)
382 /* If we exit with an EOF immediately, then
383 dump stacks. This is useful for builder and
384 other cases where Factor is run with stdin
385 redirected to /dev/null */
398 if(strcmp(cmd,"d") == 0)
400 cell addr = read_cell_hex();
401 if(scanf(" ") < 0) break;
402 cell count = read_cell_hex();
403 dump_memory(addr,addr+count);
405 else if(strcmp(cmd,"u") == 0)
407 cell addr = read_cell_hex();
408 cell count = object_size(addr);
409 dump_memory(addr,addr+count);
411 else if(strcmp(cmd,".") == 0)
413 cell addr = read_cell_hex();
417 else if(strcmp(cmd,"t") == 0)
418 full_output = !full_output;
419 else if(strcmp(cmd,"s") == 0)
420 dump_memory(ds_bot,ds);
421 else if(strcmp(cmd,"r") == 0)
422 dump_memory(rs_bot,rs);
423 else if(strcmp(cmd,".s") == 0)
425 else if(strcmp(cmd,".r") == 0)
427 else if(strcmp(cmd,".c") == 0)
429 else if(strcmp(cmd,"e") == 0)
432 for(i = 0; i < USER_ENV; i++)
433 dump_cell((cell)&userenv[i]);
435 else if(strcmp(cmd,"g") == 0)
437 else if(strcmp(cmd,"card") == 0)
439 cell addr = read_cell_hex();
440 print_cell_hex((cell)addr_to_card(addr));
443 else if(strcmp(cmd,"addr") == 0)
445 card *ptr = (card *)read_cell_hex();
446 print_cell_hex(card_to_addr(ptr));
449 else if(strcmp(cmd,"q") == 0)
451 else if(strcmp(cmd,"x") == 0)
453 else if(strcmp(cmd,"im") == 0)
454 save_image(STRING_LITERAL("fep.image"));
455 else if(strcmp(cmd,"data") == 0)
456 dump_objects(TYPE_COUNT);
457 else if(strcmp(cmd,"refs") == 0)
459 cell addr = read_cell_hex();
460 print_string("Data heap references:\n");
461 find_data_references(addr);
464 else if(strcmp(cmd,"words") == 0)
465 dump_objects(WORD_TYPE);
466 else if(strcmp(cmd,"tuples") == 0)
467 dump_objects(TUPLE_TYPE);
468 else if(strcmp(cmd,"push") == 0)
470 cell addr = read_cell_hex();
473 else if(strcmp(cmd,"code") == 0)
476 print_string("unknown command\n");
480 inline void factor_vm::primitive_die()
482 print_string("The die word was called by the library. Unless you called it yourself,\n");
483 print_string("you have triggered a bug in Factor. Please report.\n");
489 PRIMITIVE_GETVM()->primitive_die();