Skip to content

Commit 1baa396

Browse files
committed
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.
1 parent ead14b1 commit 1baa396

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

gc.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,6 +4770,7 @@ rb_raw_obj_info_common(char *const buff, const size_t buff_size, const VALUE obj
47704770
// const int age = RVALUE_AGE_GET(obj);
47714771

47724772
if (rb_gc_impl_pointer_to_heap_p(rb_gc_get_objspace(), (void *)obj)) {
4773+
APPEND_F("%p %s/", (void *)obj, obj_type_name(obj));
47734774
// TODO: fixme
47744775
// APPEND_F("%p [%d%s%s%s%s%s%s] %s ",
47754776
// (void *)obj, age,
@@ -4797,7 +4798,7 @@ rb_raw_obj_info_common(char *const buff, const size_t buff_size, const VALUE obj
47974798
else if (RTEST(RBASIC(obj)->klass)) {
47984799
VALUE class_path = rb_class_path_cached(RBASIC(obj)->klass);
47994800
if (!NIL_P(class_path)) {
4800-
APPEND_F("(%s)", RSTRING_PTR(class_path));
4801+
APPEND_F("%s ", RSTRING_PTR(class_path));
48014802
}
48024803
}
48034804
}
@@ -5032,15 +5033,35 @@ rb_asan_poisoned_object_p(VALUE obj)
50325033
return __asan_region_is_poisoned(ptr, rb_gc_obj_slot_size(obj));
50335034
}
50345035

5036+
static void
5037+
raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
5038+
{
5039+
size_t pos = rb_raw_obj_info_common(buff, buff_size, obj);
5040+
pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos);
5041+
if (pos >= buff_size) {} // truncated
5042+
}
5043+
50355044
const char *
50365045
rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
50375046
{
5038-
asan_unpoisoning_object(obj) {
5039-
size_t pos = rb_raw_obj_info_common(buff, buff_size, obj);
5040-
pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos);
5041-
if (pos >= buff_size) {} // truncated
5042-
}
5047+
void *objspace = rb_gc_get_objspace();
50435048

5049+
if (SPECIAL_CONST_P(obj)) {
5050+
raw_obj_info(buff, buff_size, obj);
5051+
}
5052+
else if (!rb_gc_impl_pointer_to_heap_p(objspace, (const void *)obj)) {
5053+
snprintf(buff, buff_size, "out-of-heap:%p", (void *)obj);
5054+
}
5055+
#if 0 // maybe no need to check it?
5056+
else if (0 && rb_gc_impl_garbage_object_p(objspace, obj)) {
5057+
snprintf(buff, buff_size, "garbage:%p", (void *)obj);
5058+
}
5059+
#endif
5060+
else {
5061+
asan_unpoisoning_object(obj) {
5062+
raw_obj_info(buff, buff_size, obj);
5063+
}
5064+
}
50445065
return buff;
50455066
}
50465067

0 commit comments

Comments
 (0)