Ticket #384: tt384-pbc_utils.patch
File tt384-pbc_utils.patch, 14.1 KB (added by rurban, 13 years ago) |
---|
-
src/pbc_info.c
old new 4 4 5 5 =head1 NAME 6 6 7 pbc_info - Pac File demo7 pbc_info - PackFile demo 8 8 9 9 =head1 SYNOPSIS 10 10 … … 70 70 71 71 interp = Parrot_new(NULL); 72 72 73 pf = Parrot_pbc_read(interp, argv[1], 0);73 pf = Parrot_pbc_read(interp, argv[1], PFOPT_UTILS); 74 74 75 75 /* 76 76 * add some more segments -
src/pbc_disassemble.c
old new 53 53 printf(" -b\t\t ... bare .pasm without header and left column\n"); 54 54 printf(" -h\t\t ... dump Constant-table header only\n"); 55 55 #if TRACE_PACKFILE 56 printf(" -d\t\t ... debug\n"); 56 printf("\t-D<1-7> --debug debug output\n"); 57 printf("\t 1 general info\n"); 58 printf("\t 2 alignment\n"); 59 printf("\t 4 values\n"); 57 60 #endif 58 61 printf(" -o filename\t ... output to filename\n"); 59 62 exit(EXIT_SUCCESS); … … 63 66 { 'h', 'h', OPTION_optional_FLAG, { "--header-only" } }, 64 67 { '?', '?', OPTION_optional_FLAG, { "--help" } }, 65 68 { 'b', 'b', OPTION_optional_FLAG, { "--bare" } }, 66 { 'd', 'd', OPTION_optional_FLAG, { "--debug" } }, 69 #if TRACE_PACKFILE 70 { 'D', 'D', OPTION_required_FLAG, { "--debug" } }, 71 #endif 67 72 { 'o', 'o', OPTION_required_FLAG, { "--output" } } 68 73 }; 69 74 … … 85 90 Parrot_Interp interp; 86 91 const char *outfile = NULL; 87 92 int option = 0; 88 int debug = 0;93 int debug = PFOPT_UTILS; 89 94 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 90 95 int status; 91 96 … … 107 112 case 'o': 108 113 outfile = opt.opt_arg; 109 114 break; 110 case 'd': 111 debug = 1; 115 #if TRACE_PACKFILE 116 case 'D': 117 debug += atoi(opt.opt_arg) << 2; 112 118 break; 119 #endif 113 120 case '?': 114 121 default: 115 122 help(); … … 171 178 172 179 Reini Urban: Renamed from disassemble to pbc_disassemble (2008-07-03). 173 180 Add options: help, -h, -o, --debug, --bare (2009-01-29) 181 Force option 1 for passing version check (2009-03-07) 174 182 175 183 =cut 176 184 -
src/pbc_dump.c
old new 32 32 33 33 Terse output. 34 34 35 =item C<- e> C--debug>35 =item C<-D> C--debug> 1-7 36 36 37 37 Display detailed packfile reader debugging information if 38 F<include/parrot/packfile.h> enables TRACE_PACKFILE 38 F<include/parrot/packfile.h> enables TRACE_PACKFILE. 39 40 1 print general debug info 41 2 print alignment info 42 4 print values 39 43 40 44 =item C<-o converted.pbc> 41 45 … … 156 160 Parrot_io_printf(interp, "\tparrot-version %d.%d.%d, bytecode-version %d.%d\n", 157 161 pf->header->major, pf->header->minor, pf->header->patch, 158 162 pf->header->bc_major, pf->header->bc_minor); 159 Parrot_io_printf(interp, "\tUUID type = %d, UUID size = %d\n",163 Parrot_io_printf(interp, "\tUUID: type = %d, size = %d", 160 164 pf->header->uuid_type, pf->header->uuid_size); 165 if (pf->header->uuid_size) 166 Parrot_io_printf(interp, ", '%s'\n", pf->header->uuid_data); 167 else 168 Parrot_io_printf(interp, "\n"); 161 169 Parrot_io_printf(interp, "\t%s endianize, %s opcode, %s numval transform\n", 162 170 pf->need_endianize ? "**need**" : "no", 163 171 pf->need_wordsize ? "**need**" : "no", … … 186 194 printf("\t-h ... dump header only\n"); 187 195 printf("\t-t ... terse output\n"); 188 196 #if TRACE_PACKFILE 189 printf("\t--debug debug output\n"); 197 printf("\t-D<1-7> --debug debug output\n"); 198 printf("\t 1 general info\n"); 199 printf("\t 2 alignment\n"); 200 printf("\t 4 values\n"); 190 201 #endif 191 printf("\ n\t-o converted.pbcrepacks a PBC file into "202 printf("\t-o converted.pbc ... repacks a PBC file into " 192 203 "the platform's native\n"); 193 204 printf("\t binary format for better efficiency on reading " 194 205 "non native PBCs\n"); 195 206 exit(EXIT_SUCCESS); 196 207 } 197 208 198 static struct longopt_opt_decl opt ions[] = {209 static struct longopt_opt_decl opt_options[] = { 199 210 { 'h', 'h', OPTION_optional_FLAG, { "--header-only" } }, 200 211 { '?', '?', OPTION_optional_FLAG, { "--help" } }, 201 212 { 't', 't', OPTION_optional_FLAG, { "--terse" } }, 202 213 { 'd', 'd', OPTION_optional_FLAG, { "--disassemble" } }, 203 { 'e', 'e', OPTION_optional_FLAG, { "--debug" } }, 214 #if TRACE_PACKFILE 215 { 'D', 'D', OPTION_required_FLAG, { "--debug" } }, 216 #endif 204 217 { 'o', 'o', OPTION_required_FLAG, { "--output" } } 205 218 }; 206 219 … … 223 236 int terse = 0; 224 237 int disas = 0; 225 238 int convert = 0; 226 int header = 0; 227 int debug = 0; 239 int options = PFOPT_UTILS; 228 240 const char *file = NULL; 229 241 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 230 242 int status; … … 236 248 /* init and set top of stack */ 237 249 Parrot_init_stacktop(interp, &status); 238 250 while ((status = longopt_get(interp, 239 argc, argv, opt ions, &opt)) > 0) {251 argc, argv, opt_options, &opt)) > 0) { 240 252 switch (opt.opt_id) { 241 253 case 'h': 242 header = 1;254 options += PFOPT_HEADERONLY; 243 255 break; 244 256 case 't': 245 257 terse = 1; … … 247 259 case 'd': 248 260 disas = 1; 249 261 break; 250 case 'e': 251 debug = 1; 262 #if TRACE_PACKFILE 263 case 'D': 264 options += atoi(opt.opt_arg) << 2; 252 265 break; 266 #endif 253 267 case 'o': 254 268 file = opt.opt_arg; 255 269 convert = 1; … … 267 281 argv += opt.opt_index; 268 282 269 283 270 pf = Parrot_pbc_read(interp, *argv, debug);284 pf = Parrot_pbc_read(interp, *argv, options); 271 285 272 286 if (!pf) { 273 287 printf("Can't read PBC\n"); … … 304 318 } 305 319 306 320 PackFile_header_dump(interp, pf); 307 if ( header) {321 if (options & PFOPT_HEADERONLY) { 308 322 Parrot_exit(interp, 0); 309 323 } 310 324 /* install a dumper function */ -
src/packfile/pf_items.c
old new 231 231 /* 232 232 * offset not in ptr diff, but in byte 233 233 */ 234 #define OFFS(cursor) (( const char *)(cursor) - (const char *)(pf->src))234 #define OFFS(cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 235 235 236 236 /* 237 237 * low level FLOATVAL fetch and convert functions … … 1307 1307 charset_name = Parrot_charset_c_name(interp, charset_nr); 1308 1308 s = string_make(interp, (const char *)*cursor, size, charset_name, flags); 1309 1309 1310 #if TRACE_PACKFILE == 2 1311 if (pf->options & 3) { 1312 /* print only printable characters */ 1313 Parrot_io_eprintf(NULL, "PF_fetch_string(): string is '%s' at 0x%x\n", 1314 s->strstart, OFFS(*cursor)); 1315 } 1316 #endif 1310 /* print only printable characters */ 1311 TRACE_PRINTF_VAL((NULL, "PF_fetch_string(): string is '%s' at 0x%x\n", 1312 s->strstart, OFFS(*cursor))); 1317 1313 1318 1314 /* s = string_make(interp, *cursor, size, 1319 1315 encoding_lookup_index(encoding), -
src/packfile.c
old new 457 457 #define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0) 458 458 #define ALIGN_16(st, cursor) \ 459 459 (cursor) += ROUND_16((const char *)(cursor) - (const char *)(st))/sizeof (opcode_t) 460 /* offset not in ptr diff, but in byte */ 461 #define OFFS(cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 460 462 461 463 #if TRACE_PACKFILE 462 464 void … … 910 912 valid and that Parrot can read this bytecode version, Parrot, and performing 911 913 any required endian and word size transforms. 912 914 913 Returns size of unpacked if everything is okay, else zero (0).915 Returns size of unpacked opcodes if everything is okay, else zero (0). 914 916 915 917 =cut 916 918 … … 954 956 Parrot_io_eprintf(NULL, "PackFile_unpack: This Parrot cannot read " 955 957 "bytecode files with version %d.%d.\n", 956 958 header->bc_major, header->bc_minor); 957 return 0; 959 if (!(self->options & PFOPT_UTILS)) 960 return 0; 958 961 } 959 962 960 963 /* Check wordsize, byte order and floating point number type are valid. */ … … 1037 1040 1038 1041 TRACE_PRINTF(("PackFile_unpack: Directory read, offset %d.\n", 1039 1042 (INTVAL)cursor - (INTVAL)packed)); 1040 1041 1043 self->directory.base.file_offset = (INTVAL)cursor - (INTVAL)self->src; 1044 if (self->options & PFOPT_HEADERONLY) 1045 return cursor - packed; 1042 1046 1043 1047 /* now unpack dir, which unpacks its contents ... */ 1044 1048 Parrot_block_GC_mark(interp); … … 1245 1249 header->floattype = FLOATTYPE_16; 1246 1250 # else 1247 1251 exit_fatal(1, "PackFile_set_header: Unsupported floattype NUMVAL_SIZE=%d," 1248 " PARROT_BIGENDIAN=% d\n", NUMVAL_SIZE,1252 " PARROT_BIGENDIAN=%s\n", NUMVAL_SIZE, 1249 1253 PARROT_BIGENDIAN ? "big-endian" : "little-endian"); 1250 1254 # endif 1251 1255 # endif … … 1311 1315 PackFile * const pf = mem_allocate_zeroed_typed(PackFile); 1312 1316 pf->header = mem_allocate_zeroed_typed(PackFile_Header); 1313 1317 pf->is_mmap_ped = is_mapped; 1314 pf->options = 0;1318 pf->options = PFOPT_NONE; 1315 1319 1316 1320 /* fill header with system specific data */ 1317 1321 PackFile_set_header(pf->header); … … 1833 1837 TRACE_PRINTF(("PackFile_Segment_unpack: special\n")); 1834 1838 1835 1839 cursor = (f)(interp, self, cursor); 1836 TRACE_PRINTF_VAL((" PackFile_Segment_unpack: offset=0x%x\n",1837 pf->src - cursor));1838 1839 1840 if (!cursor) 1840 1841 return NULL; 1841 1842 } 1842 1843 1843 TRACE_PRINTF_VAL(("pre-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1844 pf->src - cursor, pf->src, cursor)); 1845 1844 TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1845 OFFS(cursor), pf->src, cursor)); 1846 1846 /* FIXME on 64bit reading 32bit */ 1847 1847 ALIGN_16(self->pf->src, cursor); 1848 TRACE_PRINTF_ VAL(("ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",1849 pf->src - cursor, pf->src, cursor));1848 TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1849 OFFS(cursor), pf->src, cursor)); 1850 1850 return cursor; 1851 1851 } 1852 1852 … … 2030 2030 seg->dir = dir; 2031 2031 } 2032 2032 2033 TRACE_PRINTF_VAL(("pre-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 2034 pf->src - cursor, pf->src, cursor)); 2035 2033 TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 2034 OFFS(cursor), pf->src, cursor)); 2036 2035 /* FIXME on 64bit reading 32bit */ 2037 2036 ALIGN_16(pf->src, cursor); 2038 TRACE_PRINTF_ VAL(("ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n",2039 pf->src - cursor, pf->src, cursor));2037 TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 2038 OFFS(cursor), pf->src, cursor)); 2040 2039 2041 2040 /* and now unpack contents of dir */ 2042 2041 for (i = 0; cursor && i < dir->num_segments; i++) { … … 2061 2060 TRACE_PRINTF_VAL(("PackFile_Segment_unpack ok. pos=0x%x\n", pos)); 2062 2061 } 2063 2062 2064 /* BUG: on 64bit reading 32bit lurking here!*/2063 /* FIXME bug on 64bit reading 32bit lurking here! TT #254 */ 2065 2064 if (pf->need_wordsize) { 2066 2065 #if OPCODE_T_SIZE == 8 2067 2066 if (pf->header->wordsize == 4) -
include/parrot/packfile.h
old new 43 43 #define FLOATTYPE_4 5 44 44 #define FLOATTYPE_4_NAME "4-byte float" 45 45 46 /* 47 ** Debug printf packfile reading: 48 ** 0 to disable 49 ** 1 to print basic info 50 ** 2 to print also values 51 ** Use also ./pbc_dump -D<1-7> to finetune. See F<src/pbc_dump.c> 52 */ 46 53 #define TRACE_PACKFILE 0 47 54 55 /* 56 ** Parrot_pbc_read() options: 57 ** parrot, pbc_merge, parrot_debugger use 0 58 ** pbc_dump, pbc_disassemble, pbc_info use 1 to skip the version check 59 ** pbc_dump -h requires 2 60 ** The rest is for TRACE_PACKFILE debugging with switch -D in pbc_dump 61 */ 62 #define PFOPT_NONE 0 63 #define PFOPT_UTILS 1 64 #define PFOPT_HEADERONLY 2 65 #if TRACE_PACKFILE 66 # define PFOPT_DEBUG 4 67 # define PFOPT_ALIGN 8 68 # define PFOPT_VALUE 16 69 #endif 70 48 71 #if TRACE_PACKFILE 49 72 /* Here we pass multipe args to a macro so the args may not be bracketed here! */ 50 # define TRACE_PRINTF(args) if (pf->options & 1) Parrot_trace_eprintf args 51 # define TRACE_PRINTF_ALIGN(args) if (pf->options & 4) Parrot_trace_eprintf args 73 # define TRACE_PRINTF(args) if (pf->options & PFOPT_DEBUG) \ 74 Parrot_trace_eprintf args 75 # define TRACE_PRINTF_ALIGN(args) if (pf->options & PFOPT_ALIGN) \ 76 Parrot_trace_eprintf args 52 77 # if TRACE_PACKFILE == 2 53 # define TRACE_PRINTF_VAL(args) if (pf->options & 2) Parrot_trace_eprintf args 78 # define TRACE_PRINTF_VAL(args) if (pf->options & PFOPT_VALUE) \ 79 Parrot_trace_eprintf args 54 80 # define TRACE_PRINTF_2(args) Parrot_trace_eprintf args 55 81 # else 56 82 # define TRACE_PRINTF_VAL(args) -
src/embed.c
old new 541 541 return NULL; 542 542 } 543 543 544 /* Set :main routine */ 545 do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL); 544 if (!(pf->options & PFOPT_HEADERONLY)) 545 /* Set :main routine */ 546 do_sub_pragmas(interp, pf->cur_cs, PBC_PBC, NULL); 546 547 547 548 /* JITting and/or prederefing the sub/the bytecode is done 548 549 * in switch_to_cs before actual usage of the segment */