-
Notifications
You must be signed in to change notification settings - Fork 602
Add xop_dump field and integrate into op_dump() #22572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
As an example of it in use: The following function is added to my .xs file: static void opdump_argelems_named(pTHX_ const OP *o, void *ctx)
{
UNOP_AUX_item *aux = cUNOP_AUXo->op_aux;
UV n_params = aux[1].uv;
opdump_printf(ctx, "ARGIX = %" UVuf "\n", aux[0].uv);
opdump_printf(ctx, "PARAMS = (%" UVuf ")\n", n_params);
for(U32 parami = 0; parami < n_params; parami++) {
UNOP_AUX_item *paramdef = aux + 2 + 4 * parami;
UV flags = paramdef[NAMEDPARAMaux_FLAGS].uv;
SV *flagstr = newSVpvn("", 0);
SAVEFREESV(flagstr);
if(flags & NAMEDPARAMf_UTF8) sv_catpvf(flagstr, "%sUTF8", SvCUR(flagstr)?", ":"");
if(flags & NAMEDPARAMf_REQUIRED) sv_catpvf(flagstr, "%sREQUIRED", SvCUR(flagstr)?", ":"");
opdump_printf(ctx, " [%d] = {.name=\"%s\", .padix=%u, .flags=(%s)}\n",
parami,
paramdef[NAMEDPARAMaux_NAMEPV].pv,
(unsigned int)paramdef[NAMEDPARAMaux_PADIX].uv,
SvPV_nolen(flagstr));
}
}and added to the XOP structure by: XopENTRY_set(&xop_argelems_named, xop_dump, &opdump_argelems_named);When printed with Without this facility, only the top two lines would have been output, resulting in far less useful debug information. |
|
Several updates made:
|
ac73a61 to
6b5c2ca
Compare
6b5c2ca to
bef1b45
Compare
bef1b45 to
c5bdb26
Compare
c5bdb26 to
b46b321
Compare
perl.h
Outdated
| #include "perly.h" | ||
|
|
||
| /* opaque struct type used to communicate between xop_dump and opdump_printf */ | ||
| struct OpDumpContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a public (API) identifier without a Perl_ prefix. Do we want that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have hundreds of those - to pick a random example, typedef struct av AV in perl.h. But you're right; no need to make it worse. I'll stick a prefix on it.
b46b321 to
8284ab9
Compare
|
"decalaration" in the first commit message |
dump.c
Outdated
|
|
||
| while(msglen) { | ||
| if(ctx->indent_needed) { | ||
| PerlIO_printf(ctx->file, " "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PerlIO_puts() to avoid the overhead of PerlIO_printf().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahyes; another one I copied from the other code. I'll fix it there too
|
Looks fine otherwise |
…g with no conversions
When working with nontrivially-shaped custom ops, such as ones based on UNOP_AUX with interesting op_aux arrays, it is often useful to be able to peek into the contents of these op structures with `op_dump()`. Perl's core dumper cannot know the contents of these aux arrays, but by defining a helper function in the module that provides the custom op, help can be achieved. A helper function, `opdump_printf` is also provided that acts as a printf()-alike function for outputting lines of content. The various internal arguments to it (level, bar, file) are bundled up into an opaque structure, so as to achieve a modicum of abstraction away from the specific internals on how dump.c happens to work.
8284ab9 to
883b227
Compare
Oops, fixed too. |
which I missed in the review of Perl#22572 but found when I tried to use it.
not struct OpDumpContext *, OP *. Which I missed in the review of Perl#22572 but found when I tried to use it.
When working with nontrivially-shaped custom ops, such as ones based on UNOP_AUX with interesting op_aux arrays, it is often useful to be able to peek into the contents of these op structures with
op_dump(). Perl's core dumper cannot know the contents of these aux arrays, but by defining a helper function in the module that provides the custom op, help can be achieved.A helper function,
opdump_printfis also provided that acts as a printf()-alike function for outputting lines of content. The various internal arguments to it (level, bar, file) are bundled up into an opaque structure, so as to achieve a modicum of abstraction away from the specific internals on how dump.c happens to work.