23static VALUE sym_output, sym_stdout, sym_string, sym_file;
40dump_append(
struct dump_config *dc,
const char *format, ...)
61 dump_append(dc,
"\"");
63 switch ((c = value[
i])) {
66 dump_append(dc,
"\\%c", c);
69 dump_append(dc,
"\\u0000");
72 dump_append(dc,
"\\b");
75 dump_append(dc,
"\\t");
78 dump_append(dc,
"\\f");
81 dump_append(dc,
"\\n");
84 dump_append(dc,
"\\r");
88 dump_append(dc,
"\\u%04d", c);
90 dump_append(dc,
"%c", c);
93 dump_append(dc,
"\"");
99 dump_append(dc,
"{\"type\":\"SYMBOL\", \"value\":");
101 dump_append(dc,
"}");
104static inline const char *
108#define CASE_TYPE(type) case T_##type: return #type
143 if (value ==
Qtrue) {
144 dump_append(dc,
"true");
146 else if (value ==
Qfalse) {
147 dump_append(dc,
"false");
149 else if (value ==
Qnil) {
150 dump_append(dc,
"null");
153 dump_append(dc,
"%ld",
FIX2LONG(value));
159 dump_append_symbol_value(dc, value);
162 dump_append(dc,
"{}");
167reachable_object_i(
VALUE ref,
void *data)
175 dump_append(dc,
", \"references\":[\"%#"PRIxVALUE"\"", ref);
177 dump_append(dc,
", \"%#"PRIxVALUE"\"", ref);
190 dump_append(dc,
", \"value\":");
191 dump_append_string_value(dc,
obj);
199#define TYPE_STR(t) case(imemo_##t): return #t
227 dump_append_special_const(dc,
obj);
238 dump_append(dc,
"{\"address\":\"%#"PRIxVALUE"\", \"type\":\"%s\"",
obj, obj_type(
obj));
243 dump_append(dc,
", \"frozen\":true");
247 dump_append(dc,
"}\n");
251 dump_append(dc,
", \"imemo_type\":\"%s\"", imemo_name(
imemo_type(
obj)));
260 dump_append(dc,
", \"embedded\":true");
262 dump_append(dc,
", \"broken\":true");
264 dump_append(dc,
", \"fstring\":true");
266 dump_append(dc,
", \"shared\":true");
268 dump_append_string_content(dc,
obj);
283 dump_append(dc,
", \"shared\":true");
285 dump_append(dc,
", \"embedded\":true");
310 dump_append(dc,
", \"fd\":%d", fptr->
fd);
314 dump_append(dc,
"}\n");
320 dump_append(dc,
"]");
323 dump_append(dc,
", \"file\":\"%s\", \"line\":%lu", ainfo->
path, ainfo->
line);
326 dump_append(dc,
", \"method\":\"%s\"",
RSTRING_PTR(m));
332 dump_append(dc,
", \"memsize\":%"PRIuSIZE, memsize);
335 dump_append(dc,
", \"flags\":{");
336 for (
i=0;
i<
n;
i++) {
338 if (
i !=
n-1) dump_append(dc,
", ");
340 dump_append(dc,
"}");
343 dump_append(dc,
"}\n");
347heap_i(
void *vstart,
void *vend,
size_t stride,
void *data)
351 for (;
v != (
VALUE)vend;
v += stride) {
359root_obj_i(
const char *category,
VALUE obj,
void *data)
364 dump_append(dc,
"]}\n");
366 dump_append(dc,
"{\"type\":\"ROOT\", \"root\":\"%s\", \"references\":[\"%#"PRIxVALUE"\"", category,
obj);
388 if (output == sym_stdout) {
392 else if (output == sym_file) {
403 else if (output == sym_string) {
419 if (output == sym_string) {
422 else if (output == sym_file) {
448 static const char filename[] =
"rubyobj";
454 output = dump_output(&dc, opts, sym_string, filename);
456 dump_object(
obj, &dc);
458 return dump_result(&dc, output);
480 static const char filename[] =
"rubyheap";
486 output = dump_output(&dc, opts, sym_file, filename);
490 if (dc.
roots) dump_append(&dc,
"]}\n");
495 return dump_result(&dc, output);
rb_encoding * rb_enc_from_index(int index)
#define ENCODING_GET(obj)
#define ENCODING_IS_ASCII8BIT(obj)
VALUE rb_define_module(const char *)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_obj_frozen_p(VALUE obj)
Determines if the object is frozen.
FILE * rb_io_stdio_file(rb_io_t *fptr)
#define GetOpenFile(obj, fp)
VALUE rb_io_check_io(VALUE io)
VALUE rb_io_get_write_io(VALUE io)
struct allocation_info * objspace_lookup_allocation_info(VALUE obj)
PRINTF_ARGS(static void dump_append(struct dump_config *, const char *,...), 2, 3)
void Init_objspace_dump(VALUE rb_mObjSpace)
size_t rb_str_capacity(VALUE str)
size_t cur_obj_references
const char * root_category