mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
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:
parent
ead14b19aa
commit
1baa396e21
Notes:
git
2025-06-06 04:44:29 +00:00
1 changed files with 27 additions and 6 deletions
31
gc.c
31
gc.c
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
static void
|
||||||
rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
|
raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
|
||||||
{
|
{
|
||||||
asan_unpoisoning_object(obj) {
|
|
||||||
size_t pos = rb_raw_obj_info_common(buff, buff_size, 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);
|
pos = rb_raw_obj_info_buitin_type(buff, buff_size, obj, pos);
|
||||||
if (pos >= buff_size) {} // truncated
|
if (pos >= buff_size) {} // truncated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
rb_raw_obj_info(char *const buff, const size_t buff_size, VALUE obj)
|
||||||
|
{
|
||||||
|
void *objspace = rb_gc_get_objspace();
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue