[svn:parrot] r37212 - in trunk: include/parrot src src/packfile
rurban at svn.parrot.org
rurban at svn.parrot.org
Sun Mar 8 23:02:23 UTC 2009
Author: rurban
Date: Sun Mar 8 23:02:22 2009
New Revision: 37212
URL: https://trac.parrot.org/parrot/changeset/37212
Log:
[core] pbc utils
- TT #384 pbc utils will skip version check and
- pbc_dump -h outputs only the header
- on TRACE_PACKFILE:
- unify --debug args to -D for pbc_dump, pbc_disassemble
- -D|--debug takes an argument 1,2,4
- fix OFFS and use it in packfile.c
- fix "Unsupported floattype error" fatal
- print UUID data
Modified:
trunk/include/parrot/packfile.h
trunk/src/embed.c
trunk/src/packfile.c
trunk/src/packfile/pf_items.c
trunk/src/pbc_disassemble.c
trunk/src/pbc_dump.c
trunk/src/pbc_info.c
Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h Sun Mar 8 22:23:16 2009 (r37211)
+++ trunk/include/parrot/packfile.h Sun Mar 8 23:02:22 2009 (r37212)
@@ -43,14 +43,40 @@
#define FLOATTYPE_4 5
#define FLOATTYPE_4_NAME "4-byte float"
+/*
+** Debug printf packfile reading:
+** 0 to disable
+** 1 to print basic info
+** 2 to print also values
+** Use also ./pbc_dump -D<1-7> to finetune. See F<src/pbc_dump.c>
+*/
#define TRACE_PACKFILE 0
+/*
+** Parrot_pbc_read() options:
+** parrot, pbc_merge, parrot_debugger use 0
+** pbc_dump, pbc_disassemble, pbc_info use 1 to skip the version check
+** pbc_dump -h requires 2
+** The rest is for TRACE_PACKFILE debugging with switch -D in pbc_dump
+*/
+#define PFOPT_NONE 0
+#define PFOPT_UTILS 1
+#define PFOPT_HEADERONLY 2
+#if TRACE_PACKFILE
+# define PFOPT_DEBUG 4
+# define PFOPT_ALIGN 8
+# define PFOPT_VALUE 16
+#endif
+
#if TRACE_PACKFILE
/* Here we pass multipe args to a macro so the args may not be bracketed here! */
-# define TRACE_PRINTF(args) if (pf->options & 1) Parrot_trace_eprintf args
-# define TRACE_PRINTF_ALIGN(args) if (pf->options & 4) Parrot_trace_eprintf args
+# define TRACE_PRINTF(args) if (pf->options & PFOPT_DEBUG) \
+ Parrot_trace_eprintf args
+# define TRACE_PRINTF_ALIGN(args) if (pf->options & PFOPT_ALIGN) \
+ Parrot_trace_eprintf args
# if TRACE_PACKFILE == 2
-# define TRACE_PRINTF_VAL(args) if (pf->options & 2) Parrot_trace_eprintf args
+# define TRACE_PRINTF_VAL(args) if (pf->options & PFOPT_VALUE) \
+ Parrot_trace_eprintf args
# define TRACE_PRINTF_2(args) Parrot_trace_eprintf args
# else
# define TRACE_PRINTF_VAL(args)
Modified: trunk/src/embed.c
==============================================================================
--- trunk/src/embed.c Sun Mar 8 22:23:16 2009 (r37211)
+++ trunk/src/embed.c Sun Mar 8 23:02:22 2009 (r37212)
@@ -541,8 +541,9 @@
return NULL;
}
- /* Set :main routine */
- do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL);
+ if (!(pf->options & PFOPT_HEADERONLY))
+ /* Set :main routine */
+ do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL);
/* JITting and/or prederefing the sub/the bytecode is done
* in switch_to_cs before actual usage of the segment */
Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c Sun Mar 8 22:23:16 2009 (r37211)
+++ trunk/src/packfile.c Sun Mar 8 23:02:22 2009 (r37212)
@@ -457,6 +457,8 @@
#define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0)
#define ALIGN_16(st, cursor) \
(cursor) += ROUND_16((const char *)(cursor) - (const char *)(st))/sizeof (opcode_t)
+/* offset not in ptr diff, but in byte */
+#define OFFS(cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0)
#if TRACE_PACKFILE
void
@@ -910,7 +912,7 @@
valid and that Parrot can read this bytecode version, Parrot, and performing
any required endian and word size transforms.
-Returns size of unpacked if everything is okay, else zero (0).
+Returns size of unpacked opcodes if everything is okay, else zero (0).
=cut
@@ -954,7 +956,8 @@
Parrot_io_eprintf(NULL, "PackFile_unpack: This Parrot cannot read "
"bytecode files with version %d.%d.\n",
header->bc_major, header->bc_minor);
- return 0;
+ if (!(self->options & PFOPT_UTILS))
+ return 0;
}
/* Check wordsize, byte order and floating point number type are valid. */
@@ -1037,8 +1040,9 @@
TRACE_PRINTF(("PackFile_unpack: Directory read, offset %d.\n",
(INTVAL)cursor - (INTVAL)packed));
-
self->directory.base.file_offset = (INTVAL)cursor - (INTVAL)self->src;
+ if (self->options & PFOPT_HEADERONLY)
+ return cursor - packed;
/* now unpack dir, which unpacks its contents ... */
Parrot_block_GC_mark(interp);
@@ -1245,7 +1249,7 @@
header->floattype = FLOATTYPE_16;
# else
exit_fatal(1, "PackFile_set_header: Unsupported floattype NUMVAL_SIZE=%d,"
- " PARROT_BIGENDIAN=%d\n", NUMVAL_SIZE,
+ " PARROT_BIGENDIAN=%s\n", NUMVAL_SIZE,
PARROT_BIGENDIAN ? "big-endian" : "little-endian");
# endif
# endif
@@ -1311,7 +1315,7 @@
PackFile * const pf = mem_allocate_zeroed_typed(PackFile);
pf->header = mem_allocate_zeroed_typed(PackFile_Header);
pf->is_mmap_ped = is_mapped;
- pf->options = 0;
+ pf->options = PFOPT_NONE;
/* fill header with system specific data */
PackFile_set_header(pf->header);
@@ -1833,20 +1837,16 @@
TRACE_PRINTF(("PackFile_Segment_unpack: special\n"));
cursor = (f)(interp, self, cursor);
- TRACE_PRINTF_VAL((" PackFile_Segment_unpack: offset=0x%x\n",
- pf->src - cursor));
-
if (!cursor)
return NULL;
}
- TRACE_PRINTF_VAL(("pre-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
- pf->src - cursor, pf->src, cursor));
-
+ TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
+ OFFS(cursor), pf->src, cursor));
/* FIXME on 64bit reading 32bit */
ALIGN_16(self->pf->src, cursor);
- TRACE_PRINTF_VAL(("ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
- pf->src - cursor, pf->src, cursor));
+ TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
+ OFFS(cursor), pf->src, cursor));
return cursor;
}
@@ -2030,13 +2030,12 @@
seg->dir = dir;
}
- TRACE_PRINTF_VAL(("pre-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
- pf->src - cursor, pf->src, cursor));
-
+ TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
+ OFFS(cursor), pf->src, cursor));
/* FIXME on 64bit reading 32bit */
ALIGN_16(pf->src, cursor);
- TRACE_PRINTF_VAL(("ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
- pf->src - cursor, pf->src, cursor));
+ TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",
+ OFFS(cursor), pf->src, cursor));
/* and now unpack contents of dir */
for (i = 0; cursor && i < dir->num_segments; i++) {
@@ -2061,7 +2060,7 @@
TRACE_PRINTF_VAL(("PackFile_Segment_unpack ok. pos=0x%x\n", pos));
}
- /* BUG: on 64bit reading 32bit lurking here! */
+ /* FIXME bug on 64bit reading 32bit lurking here! TT #254 */
if (pf->need_wordsize) {
#if OPCODE_T_SIZE == 8
if (pf->header->wordsize == 4)
Modified: trunk/src/packfile/pf_items.c
==============================================================================
--- trunk/src/packfile/pf_items.c Sun Mar 8 22:23:16 2009 (r37211)
+++ trunk/src/packfile/pf_items.c Sun Mar 8 23:02:22 2009 (r37212)
@@ -231,7 +231,7 @@
/*
* offset not in ptr diff, but in byte
*/
-#define OFFS(cursor) ((const char *)(cursor) - (const char *)(pf->src))
+#define OFFS(cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0)
/*
* low level FLOATVAL fetch and convert functions
@@ -1307,13 +1307,9 @@
charset_name = Parrot_charset_c_name(interp, charset_nr);
s = string_make(interp, (const char *)*cursor, size, charset_name, flags);
-#if TRACE_PACKFILE == 2
- if (pf->options & 3) {
- /* print only printable characters */
- Parrot_io_eprintf(NULL, "PF_fetch_string(): string is '%s' at 0x%x\n",
- s->strstart, OFFS(*cursor));
- }
-#endif
+ /* print only printable characters */
+ TRACE_PRINTF_VAL((NULL, "PF_fetch_string(): string is '%s' at 0x%x\n",
+ s->strstart, OFFS(*cursor)));
/* s = string_make(interp, *cursor, size,
encoding_lookup_index(encoding),
Modified: trunk/src/pbc_disassemble.c
==============================================================================
--- trunk/src/pbc_disassemble.c Sun Mar 8 22:23:16 2009 (r37211)
+++ trunk/src/pbc_disassemble.c Sun Mar 8 23:02:22 2009 (r37212)
@@ -53,7 +53,10 @@
printf(" -b\t\t ... bare .pasm without header and left column\n");
printf(" -h\t\t ... dump Constant-table header only\n");
#if TRACE_PACKFILE
- printf(" -d\t\t ... debug\n");
+ printf("\t-D<1-7> --debug debug output\n");
+ printf("\t 1 general info\n");
+ printf("\t 2 alignment\n");
+ printf("\t 4 values\n");
#endif
printf(" -o filename\t ... output to filename\n");
exit(EXIT_SUCCESS);
@@ -63,7 +66,9 @@
{ 'h', 'h', OPTION_optional_FLAG, { "--header-only" } },
{ '?', '?', OPTION_optional_FLAG, { "--help" } },
{ 'b', 'b', OPTION_optional_FLAG, { "--bare" } },
- { 'd', 'd', OPTION_optional_FLAG, { "--debug" } },
+#if TRACE_PACKFILE
+ { 'D', 'D', OPTION_required_FLAG, { "--debug" } },
+#endif
{ 'o', 'o', OPTION_required_FLAG, { "--output" } }
};
@@ -85,7 +90,7 @@
Parrot_Interp interp;
const char *outfile = NULL;
int option = 0;
- int debug = 0;
+ int debug = PFOPT_UTILS;
struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
int status;
@@ -107,9 +112,11 @@
case 'o':
outfile = opt.opt_arg;
break;
- case 'd':
- debug = 1;
+#if TRACE_PACKFILE
+ case 'D':
+ debug += atoi(opt.opt_arg) << 2;
break;
+#endif
case '?':
default:
help();
@@ -171,6 +178,7 @@
Reini Urban: Renamed from disassemble to pbc_disassemble (2008-07-03).
Add options: help, -h, -o, --debug, --bare (2009-01-29)
+ Force option 1 for passing version check (2009-03-07)
=cut
Modified: trunk/src/pbc_dump.c
==============================================================================
--- trunk/src/pbc_dump.c Sun Mar 8 22:23:16 2009 (r37211)
+++ trunk/src/pbc_dump.c Sun Mar 8 23:02:22 2009 (r37212)
@@ -32,10 +32,14 @@
Terse output.
-=item C<-e> C--debug>
+=item C<-D> C--debug> 1-7
Display detailed packfile reader debugging information if
-F<include/parrot/packfile.h> enables TRACE_PACKFILE
+F<include/parrot/packfile.h> enables TRACE_PACKFILE.
+
+ 1 print general debug info
+ 2 print alignment info
+ 4 print values
=item C<-o converted.pbc>
@@ -156,8 +160,12 @@
Parrot_io_printf(interp, "\tparrot-version %d.%d.%d, bytecode-version %d.%d\n",
pf->header->major, pf->header->minor, pf->header->patch,
pf->header->bc_major, pf->header->bc_minor);
- Parrot_io_printf(interp, "\tUUID type = %d, UUID size = %d\n",
+ Parrot_io_printf(interp, "\tUUID: type = %d, size = %d",
pf->header->uuid_type, pf->header->uuid_size);
+ if (pf->header->uuid_size)
+ Parrot_io_printf(interp, ", '%s'\n", pf->header->uuid_data);
+ else
+ Parrot_io_printf(interp, "\n");
Parrot_io_printf(interp, "\t%s endianize, %s opcode, %s numval transform\n",
pf->need_endianize ? "**need**" : "no",
pf->need_wordsize ? "**need**" : "no",
@@ -186,21 +194,26 @@
printf("\t-h ... dump header only\n");
printf("\t-t ... terse output\n");
#if TRACE_PACKFILE
- printf("\t--debug debug output\n");
+ printf("\t-D<1-7> --debug debug output\n");
+ printf("\t 1 general info\n");
+ printf("\t 2 alignment\n");
+ printf("\t 4 values\n");
#endif
- printf("\n\t-o converted.pbc repacks a PBC file into "
+ printf("\t-o converted.pbc ... repacks a PBC file into "
"the platform's native\n");
printf("\t binary format for better efficiency on reading "
"non native PBCs\n");
exit(EXIT_SUCCESS);
}
-static struct longopt_opt_decl options[] = {
+static struct longopt_opt_decl opt_options[] = {
{ 'h', 'h', OPTION_optional_FLAG, { "--header-only" } },
{ '?', '?', OPTION_optional_FLAG, { "--help" } },
{ 't', 't', OPTION_optional_FLAG, { "--terse" } },
{ 'd', 'd', OPTION_optional_FLAG, { "--disassemble" } },
- { 'e', 'e', OPTION_optional_FLAG, { "--debug" } },
+#if TRACE_PACKFILE
+ { 'D', 'D', OPTION_required_FLAG, { "--debug" } },
+#endif
{ 'o', 'o', OPTION_required_FLAG, { "--output" } }
};
@@ -223,8 +236,7 @@
int terse = 0;
int disas = 0;
int convert = 0;
- int header = 0;
- int debug = 0;
+ int options = PFOPT_UTILS;
const char *file = NULL;
struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
int status;
@@ -236,10 +248,10 @@
/* init and set top of stack */
Parrot_init_stacktop(interp, &status);
while ((status = longopt_get(interp,
- argc, argv, options, &opt)) > 0) {
+ argc, argv, opt_options, &opt)) > 0) {
switch (opt.opt_id) {
case 'h':
- header = 1;
+ options += PFOPT_HEADERONLY;
break;
case 't':
terse = 1;
@@ -247,9 +259,11 @@
case 'd':
disas = 1;
break;
- case 'e':
- debug = 1;
+#if TRACE_PACKFILE
+ case 'D':
+ options += atoi(opt.opt_arg) << 2;
break;
+#endif
case 'o':
file = opt.opt_arg;
convert = 1;
@@ -267,7 +281,7 @@
argv += opt.opt_index;
- pf = Parrot_pbc_read(interp, *argv, debug);
+ pf = Parrot_pbc_read(interp, *argv, options);
if (!pf) {
printf("Can't read PBC\n");
@@ -304,7 +318,7 @@
}
PackFile_header_dump(interp, pf);
- if (header) {
+ if (options & PFOPT_HEADERONLY) {
Parrot_exit(interp, 0);
}
/* install a dumper function */
Modified: trunk/src/pbc_info.c
==============================================================================
--- trunk/src/pbc_info.c Sun Mar 8 22:23:16 2009 (r37211)
+++ trunk/src/pbc_info.c Sun Mar 8 23:02:22 2009 (r37212)
@@ -4,7 +4,7 @@
=head1 NAME
-pbc_info - PacFile demo
+pbc_info - PackFile demo
=head1 SYNOPSIS
@@ -70,7 +70,7 @@
interp = Parrot_new(NULL);
- pf = Parrot_pbc_read(interp, argv[1], 0);
+ pf = Parrot_pbc_read(interp, argv[1], PFOPT_UTILS);
/*
* add some more segments
More information about the parrot-commits
mailing list