The attached patch is my first step at locating bug #40438.
It adds pdump -d functionality for keys. Leopold Toetsch via RT wrote:
Thanks, I've applied a modified version of the patch, showing that it's a namespace issue caused by the .HLL line. Using .loadlib works fine and as expected. leo
=== include/parrot/packfile.h ================================================================== --- include/parrot/packfile.h (revision 133) +++ include/parrot/packfile.h (local) @@ -375,7 +375,7 @@ PARROT_API size_t PackFile_Constant_pack_size(Interp *, struct PackFile_Constant * self); -PARROT_API opcode_t * PackFile_Constant_pack(Interp *, struct PackFile_Constant *, opcode_t *); +PARROT_API opcode_t * PackFile_Constant_pack(Interp *, struct PackFile_ConstTable *ct, struct PackFile_Constant *, opcode_t *); PARROT_API void PackFile_Constant_destroy(Interp *, struct PackFile_Constant * self); @@ -388,6 +388,9 @@ PARROT_API opcode_t * PackFile_Constant_unpack_pmc(Interp *interpreter, struct PackFile_ConstTable *, struct PackFile_Constant *, opcode_t *); +PARROT_API int PackFile_find_in_const(Interp *interpreter, struct PackFile_ConstTable *ct, + PMC *key, int type); + /* * pf_items low level Parrot items fetch routines */ === src/packdump.c ================================================================== --- src/packdump.c (revision 133) +++ src/packdump.c (local) @@ -30,7 +30,7 @@ void PackFile_ConstTable_dump(Interp *, struct PackFile_ConstTable *); -static void PackFile_Constant_dump(Interp *, +static void PackFile_Constant_dump(Interp *, struct PackFile_ConstTable *ct, struct PackFile_Constant *); void PackFile_Fixup_dump(Interp *, struct PackFile_FixupTable *ft); @@ -55,14 +55,14 @@ for (i = 0; i < self->const_count; i++) { PIO_printf(interpreter, " # %ld:\n", (long)i); - PackFile_Constant_dump(interpreter, self->constants[i]); + PackFile_Constant_dump(interpreter, self, self->constants[i]); } } /* =item C<void -PackFile_Constant_dump(Interp *interpreter, +PackFile_Constant_dump(Interp *interpreter, struct PackFile_ConstTable *ct struct PackFile_Constant *self)> Dumps the constant C<self>. @@ -72,9 +72,15 @@ */ void -PackFile_Constant_dump(Interp *interpreter, +PackFile_Constant_dump(Interp *interpreter, struct PackFile_ConstTable *ct, struct PackFile_Constant *self) { + struct PMC *key; + size_t i; + size_t ct_index; + opcode_t slice_bits; + struct PackFile_Constant *detail; + switch (self->type) { case PFC_NUMBER: @@ -97,9 +103,84 @@ break; case PFC_KEY: - PIO_printf(interpreter, " [ 'PFC_KEY', {\n"); - PIO_printf(interpreter, " ??? TODO \n"); - PIO_printf(interpreter, " } ],\n"); + PIO_printf(interpreter, " [ 'PFC_KEY"); + for (i = 0, key = self->u.key; key; key = PMC_data(key), i++) + ; + /* number of key components */ + PIO_printf(interpreter, " %ld items\n", i); + /* and now type / value per component */ + for (key = self->u.key; key; key = PMC_data(key)) { + PIO_printf(interpreter, " {\n"); + opcode_t type = PObj_get_FLAGS(key); + slice_bits = 0; + if ((type & (KEY_start_slice_FLAG|KEY_inf_slice_FLAG)) == + (KEY_start_slice_FLAG|KEY_inf_slice_FLAG)) + PIO_printf(interpreter, " SLICE_BITS => PF_VT_END_INF\n"); + if ((type & (KEY_end_slice_FLAG|KEY_inf_slice_FLAG)) == + (KEY_end_slice_FLAG|KEY_inf_slice_FLAG)) + slice_bits |= PF_VT_START_ZERO; + PIO_printf(interpreter, " SLICE_BITS => PF_VT_START_ZERO\n"); + if (type & KEY_start_slice_FLAG) + slice_bits |= PF_VT_START_SLICE; + PIO_printf(interpreter, " SLICE_BITS => PF_VT_START_SLICE\n"); + if (type & KEY_end_slice_FLAG) + slice_bits |= PF_VT_END_SLICE; + PIO_printf(interpreter, " SLICE_BITS => PF_VT_END_SLICE\n"); + + type &= KEY_type_FLAGS; + PIO_printf(interpreter, " FLAGS => 0x%04lx,\n", (long)PObj_get_FLAGS(key)); + switch (type) { + case KEY_integer_FLAG: + PIO_printf(interpreter, " TYPE => INTEGER\n"); + PIO_printf(interpreter, " DATA => %ld\n", PMC_int_val(key)); + PIO_printf(interpreter, " },\n"); + break; + case KEY_number_FLAG: + PIO_printf(interpreter, " TYPE => NUMBER\n"); + ct_index = PackFile_find_in_const(interpreter, ct, key, PFC_NUMBER); + PIO_printf(interpreter, " PFC_OFFSET => %ld\n", ct_index); + detail = ct->constants[ct_index]; + PIO_printf(interpreter, " DATA => %ld\n", detail->u.number); + PIO_printf(interpreter, " },\n"); + break; + case KEY_string_FLAG: + PIO_printf(interpreter, " TYPE => STRING\n"); + ct_index = PackFile_find_in_const(interpreter, ct, key, PFC_STRING); + PIO_printf(interpreter, " PFC_OFFSET => %ld\n", ct_index); + detail = ct->constants[ct_index]; + PIO_printf(interpreter, " DATA => '%.*s'\n", + (int)detail->u.string->bufused, + (char *)detail->u.string->strstart); + PIO_printf(interpreter, " },\n"); + break; + case KEY_integer_FLAG | KEY_register_FLAG: + PIO_printf(interpreter, " TYPE => I REGISTER\n"); + PIO_printf(interpreter, " DATA => %ld\n", PMC_int_val(key)); + PIO_printf(interpreter, " },\n"); + break; + case KEY_number_FLAG | KEY_register_FLAG: + PIO_printf(interpreter, " TYPE => N REGISTER\n"); + PIO_printf(interpreter, " DATA => %ld\n", PMC_int_val(key)); + PIO_printf(interpreter, " },\n"); + break; + case KEY_string_FLAG | KEY_register_FLAG: + PIO_printf(interpreter, " TYPE => S REGISTER\n"); + PIO_printf(interpreter, " DATA => %ld\n", PMC_int_val(key)); + PIO_printf(interpreter, " },\n"); + break; + case KEY_pmc_FLAG | KEY_register_FLAG: + PIO_printf(interpreter, " TYPE => P REGISTER\n"); + PIO_printf(interpreter, " DATA => %ld\n", PMC_int_val(key)); + PIO_printf(interpreter, " },\n"); + break; + default: + PIO_eprintf(NULL, "PackFile_Constant_pack: " + "unsupported constant type\n"); + Parrot_exit(interpreter, 1); + } + } + PIO_printf(interpreter, " ],\n"); + break; case PFC_PMC: PIO_printf(interpreter, " [ 'PFC_PMC', {\n"); === src/packout.c ================================================================== --- src/packout.c (revision 133) +++ src/packout.c (local) @@ -151,8 +151,6 @@ */ -static struct PackFile_ConstTable *ct; - opcode_t * PackFile_ConstTable_pack(Interp *interpreter, struct PackFile_Segment *seg, opcode_t *cursor) @@ -160,13 +158,10 @@ struct PackFile_ConstTable * const self = (struct PackFile_ConstTable *)seg; opcode_t i; - /* remember const_table for find_in_const */ - ct = self; - *cursor++ = self->const_count; for (i = 0; i < self->const_count; i++) { - cursor = PackFile_Constant_pack(interpreter, + cursor = PackFile_Constant_pack(interpreter, self, self->constants[i], cursor); } @@ -185,8 +180,8 @@ */ -static int -find_in_const(Interp *interpreter, PMC *key, int type) +int +PackFile_find_in_const(Interp *interpreter, struct PackFile_ConstTable *ct, PMC *key, int type) { int i; for (i = 0; i < ct->const_count; i++) @@ -204,8 +199,8 @@ /* =item C<opcode_t * -PackFile_Constant_pack(Interp*, struct PackFile_Constant *self, - opcode_t *cursor)> +PackFile_Constant_pack(Interp*, struct PackFile_ConstTable * const_table, + struct PackFile_Constant *self, opcode_t *cursor)> Pack a PackFile Constant into a contiguous region of memory. @@ -223,7 +218,7 @@ */ opcode_t * -PackFile_Constant_pack(Interp* interpreter, +PackFile_Constant_pack(Interp* interpreter, struct PackFile_ConstTable * const_table, struct PackFile_Constant *self, opcode_t *cursor) { struct PMC *key; @@ -278,12 +273,12 @@ case KEY_number_FLAG: *cursor++ = PARROT_ARG_NC | slice_bits; /* Argh */ - *cursor++ = find_in_const(interpreter, key, PFC_NUMBER); + *cursor++ = PackFile_find_in_const(interpreter, const_table, key, PFC_NUMBER); break; case KEY_string_FLAG: *cursor++ = PARROT_ARG_SC | slice_bits; /* Argh */ - *cursor++ = find_in_const(interpreter, key, PFC_STRING); + *cursor++ = PackFile_find_in_const(interpreter, const_table, key, PFC_STRING); break; case KEY_integer_FLAG | KEY_register_FLAG: