From b07968dda47f338a61993b7088c24362f76fdad0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 24 Aug 2011 12:08:12 -0700 Subject: [PATCH] rt: Print out fields of objects when logging them --- src/rt/rust_shape.cpp | 6 ++++++ src/rt/rust_shape.h | 31 +++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/rt/rust_shape.cpp b/src/rt/rust_shape.cpp index 3a83f3d4c78..3e1b64b3a2a 100644 --- a/src/rt/rust_shape.cpp +++ b/src/rt/rust_shape.cpp @@ -435,6 +435,12 @@ log::walk_vec(bool align, bool is_pod, const std::pair &data) { out << "]"; } +void +log::walk_obj(bool align) { + out << "obj"; + data::walk_obj_contents(align, dp); +} + void log::walk_variant(bool align, tag_info &tinfo, uint32_t variant_id, const std::pair diff --git a/src/rt/rust_shape.h b/src/rt/rust_shape.h index 2f1ba6c62ab..faab7c56a54 100644 --- a/src/rt/rust_shape.h +++ b/src/rt/rust_shape.h @@ -708,6 +708,7 @@ template class data : public ctxt< data > { protected: void walk_box_contents(bool align); + void walk_obj_contents(bool align, ptr &dp); void walk_variant(bool align, tag_info &tinfo, uint32_t variant); static std::pair get_evec_data_range(ptr dp); @@ -749,8 +750,9 @@ public: void walk_obj(bool align) { if (align) dp = align_to(dp, sizeof(void *)); + U next_dp = dp + sizeof(void *) * 2; static_cast(this)->walk_obj(align); - dp += sizeof(void *) * 2; + dp = next_dp; } void walk_res(bool align, const rust_fn *dtor, uint16_t n_ty_params, @@ -882,6 +884,23 @@ data::walk_tag(bool align, tag_info &tinfo) { dp = end_dp; } +template +void +data::walk_obj_contents(bool align, ptr &dp) { + dp += sizeof(void *); // Skip over the vtable. + + uint8_t *box_ptr = bump_dp(dp); + type_desc *subtydesc = + *reinterpret_cast(box_ptr + sizeof(void *)); + ptr obj_closure_dp(box_ptr + sizeof(void *)); + + arena arena; + type_param *params = type_param::make(subtydesc, arena); + T sub(*static_cast(this), subtydesc->shape, params, + subtydesc->shape_tables, obj_closure_dp); + sub.walk(true); +} + // Polymorphic logging, for convenience @@ -903,6 +922,14 @@ private: other.dp), out(other.out) {} + log(log &other, + const uint8_t *in_sp, + const type_param *in_params, + const rust_shape_tables *in_tables, + ptr in_dp) + : data(other.task, in_sp, in_params, in_tables, in_dp), + out(other.out) {} + log(log &other, ptr in_dp) : data(other.task, other.sp, other.params, other.tables, in_dp), out(other.out) {} @@ -928,7 +955,6 @@ private: } void walk_fn(bool align) { out << "fn"; } - void walk_obj(bool align) { out << "obj"; } void walk_port(bool align) { out << "port"; } void walk_chan(bool align) { out << "chan"; } void walk_task(bool align) { out << "task"; } @@ -949,6 +975,7 @@ private: void walk_struct(bool align, const uint8_t *end_sp); void walk_vec(bool align, bool is_pod, const std::pair &data); + void walk_obj(bool align); void walk_variant(bool align, tag_info &tinfo, uint32_t variant_id, const std::pair variant_ptr_and_end);