fix rp(obj) for any object

Now `rp(obj)` doesn't work if the `obj` is out-of-heap because
of `asan_unpoisoning_object()`, so this patch solves it.

Also add pointer information and type information to show.
This commit is contained in:
Koichi Sasada 2025-06-06 06:46:14 +09:00
parent ead14b19aa
commit 1baa396e21
Notes: git 2025-06-06 04:44:29 +00:00

33
gc.c
View file

@ -4770,6 +4770,7 @@ rb_raw_obj_info_common(char *const buff, const size_t buff_size, const VALUE obj
// const int age = RVALUE_AGE_GET(obj); // const int age = RVALUE_AGE_GET(obj);
if (rb_gc_impl_pointer_to_heap_p(rb_gc_get_objspace(), (void *)obj)) { if (rb_gc_impl_pointer_to_heap_p(rb_gc_get_objspace(), (void *)obj)) {
APPEND_F("%p %s/", (void *)obj, obj_type_name(obj));
// TODO: fixme // TODO: fixme
// APPEND_F("%p [%d%s%s%s%s%s%s] %s ", // APPEND_F("%p [%d%s%s%s%s%s%s] %s ",
// (void *)obj, age, // (void *)obj, age,
@ -4797,7 +4798,7 @@ rb_raw_obj_info_common(char *const buff, const size_t buff_size, const VALUE obj
else if (RTEST(RBASIC(obj)->klass)) { else if (RTEST(RBASIC(obj)->klass)) {
VALUE class_path = rb_class_path_cached(RBASIC(obj)->klass); VALUE class_path = rb_class_path_cached(RBASIC(obj)->klass);
if (!NIL_P(class_path)) { if (!NIL_P(class_path)) {
APPEND_F("(%s)", RSTRING_PTR(class_path)); APPEND_F("%s ", RSTRING_PTR(class_path));
} }
} }
} }
@ -5032,15 +5033,35 @@ rb_asan_poisoned_object_p(VALUE obj)
return __asan_region_is_poisoned(ptr, rb_gc_obj_slot_size(obj)); return __asan_region_is_poisoned(ptr, rb_gc_obj_slot_size(obj));
} }
static void
raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
{
size_t pos = rb_raw_obj_info_common(buff, buff_size, obj);
pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos);
if (pos >= buff_size) {} // truncated
}
const char * const char *
rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj) rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
{ {
asan_unpoisoning_object(obj) { void *objspace = rb_gc_get_objspace();
size_t pos = rb_raw_obj_info_common(buff, buff_size, obj);
pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos);
if (pos >= buff_size) {} // truncated
}
if (SPECIAL_CONST_P(obj)) {
raw_obj_info(buff, buff_size, obj);
}
else if (!rb_gc_impl_pointer_to_heap_p(objspace, (const void *)obj)) {
snprintf(buff, buff_size, "out-of-heap:%p", (void *)obj);
}
#if 0 // maybe no need to check it?
else if (0 && rb_gc_impl_garbage_object_p(objspace, obj)) {
snprintf(buff, buff_size, "garbage:%p", (void *)obj);
}
#endif
else {
asan_unpoisoning_object(obj) {
raw_obj_info(buff, buff_size, obj);
}
}
return buff; return buff;
} }