Update pdump patch
Kevin Tew wrote:
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/key.h
==================================================================
--- include/parrot/key.h (revision 136)
+++ include/parrot/key.h (local)
@@ -61,6 +61,8 @@
PARROT_API void key_mark(Interp *interpreter, PMC *key);
+PARROT_API STRING *key_set_to_string(Interp *interpreter, PMC *key);
+
#endif /* PARROT_KEY_H_GUARD */
/*
=== include/parrot/packfile.h
==================================================================
--- include/parrot/packfile.h (revision 136)
+++ 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/key.c
==================================================================
--- src/key.c (revision 136)
+++ src/key.c (local)
@@ -474,6 +474,60 @@
/*
+=item C<STRING *
+key_set_to_string(Interp *interpreter, PMC *key)>
+
+=cut
+
+*/
+
+STRING *
+key_set_to_string(Interp *interpreter, PMC *key)
+{
+ PMC *reg;
+ STRING *semicolon = string_from_cstring(interpreter, " ; ", 3);
+ STRING *quote = string_from_cstring(interpreter, "'", 1);
+ STRING *value = string_from_cstring(interpreter, "[ ", 2);
+
+ for (; key; key = PMC_data(key)) {
+ switch (PObj_get_FLAGS(key) & KEY_type_FLAGS) {
+ case KEY_integer_FLAG:
+ string_append(interpreter, value, string_from_int(interpreter,
PMC_int_val(key)), 0);
+ break;
+ case KEY_string_FLAG:
+ string_append(interpreter, value, quote, 0);
+ string_append(interpreter, value, PMC_str_val(key), 0);
+ string_append(interpreter, value, quote, 0);
+ break;
+ case KEY_pmc_FLAG:
+ string_append(interpreter, value,
VTABLE_get_string(interpreter, key), 0);
+ break;
+ case KEY_integer_FLAG | KEY_register_FLAG:
+ string_append(interpreter, value, string_from_int(interpreter,
REG_INT(PMC_int_val(key))), 0);
+ break;
+ case KEY_string_FLAG | KEY_register_FLAG:
+ string_append(interpreter, value, quote, 0);
+ string_append(interpreter, value, REG_STR(PMC_int_val(key)),
0);
+ string_append(interpreter, value, quote, 0);
+ break;
+ case KEY_pmc_FLAG | KEY_register_FLAG:
+ reg = REG_PMC(PMC_int_val(key));
+ string_append(interpreter, value,
VTABLE_get_string(interpreter, reg), 0);
+ break;
+ default:
+ string_append(interpreter, value,
string_from_cstring(interpreter, "Key type unknown", 0),0);
+ break;
+ }
+
+ if (PMC_data(key))
+ string_append(interpreter, value, semicolon, 0);
+ }
+ string_append(interpreter, value, string_from_cstring(interpreter, " ]",
2), 0);
+ return value;
+}
+
+/*
+
=back
=head1 SEE ALSO
=== src/packdump.c
==================================================================
--- src/packdump.c (revision 136)
+++ 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");
@@ -108,31 +189,46 @@
parrot_sub_t sub;
STRING *a_key = const_string(interpreter, "(keyed)");
STRING *null = const_string(interpreter, "(null)");
+ STRING *namespace_description;
opcode_t *code_start =
interpreter->code->base.data;
switch (pmc->vtable->base_type) {
case enum_class_Sub:
case enum_class_Coroutine:
sub = PMC_sub(pmc);
+ if (sub->namespace) {
+ switch (sub->namespace->vtable->base_type) {
+ case enum_class_String:
+ namespace_description =
string_from_cstring(interpreter, "'", 1);
+ namespace_description =
string_append(interpreter, namespace_description, PMC_str_val(sub->namespace),
0);
+ namespace_description =
string_append(interpreter, namespace_description,
string_from_cstring(interpreter, "'", 1), 0);
+ break;
+ case enum_class_Key:
+ namespace_description =
key_set_to_string(interpreter, sub->namespace);
+ break;
+ default:
+ namespace_description =
sub->namespace->vtable->whoami;
+ }
+ } else {
+ namespace_description = null;
+ }
PIO_printf(interpreter,
"\tclass => %Ss,\n"
"\tstart_offs => %d,\n"
"\tend_offs => %d,\n"
"\tname => '%Ss',\n"
- "\tnamespace => '%Ss'\n",
+ "\tnamespace => %Ss\n"
+ "\tHLL_id => %d,\n",
pmc->vtable->whoami,
sub->start_offs,
sub->end_offs,
sub->name,
- sub->namespace ?
- (sub->namespace->vtable->base_type ==
- enum_class_String ?
- PMC_str_val(sub->namespace) : a_key) :
- null
+ namespace_description,
+ sub->HLL_id
);
break;
default:
- PIO_printf(interpreter, "\tunknown PMC\n");
+ PIO_printf(interpreter, "\tno dump info for PMC %ld
%Ss\n", pmc->vtable->base_type, pmc->vtable->whoami);
}
}
PIO_printf(interpreter, " } ],\n");
=== src/packout.c
==================================================================
--- src/packout.c (revision 136)
+++ 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: