Ticket #2134: tt2134.patch
File tt2134.patch, 16.2 KB (added by soh_cah_toa, 11 years ago) |
---|
-
MANIFEST
diff --git a/MANIFEST b/MANIFEST index ea2a093..da7e37d 100644
a b 869 869 ext/winxed/driver.pir [] 870 870 frontend/parrot/main.c [] 871 871 frontend/parrot_debugger/main.c [] 872 frontend/pbc_disassemble/main.c [] 872 873 frontend/pbc_dump/main.c [] 873 874 frontend/pbc_dump/packdump.c [] 874 875 frontend/pbc_merge/main.c [] … … 1286 1287 src/packfile/object_serialization.c [] 1287 1288 src/packfile/output.c [] 1288 1289 src/packfile/pf_items.c [] 1289 src/pbc_disassemble.c []1290 1290 src/platform/aix/asm.s [] 1291 1291 src/platform/ansi/dl.c [] 1292 1292 src/platform/ansi/exec.c [] -
config/gen/makefiles/root.in
diff --git a/config/gen/makefiles/root.in b/config/gen/makefiles/root.in index 947f3a9..fdd0a29 100644
a b 1073 1073 # Parrot Disassembler 1074 1074 # 1075 1075 1076 src/pbc_disassemble$(O) : \1076 frontend/pbc_disassemble/main$(O) : \ 1077 1077 $(PARROT_H_HEADERS) \ 1078 1078 $(INC_DIR)/api.h \ 1079 1079 $(INC_DIR)/longopt.h \ 1080 src/pbc_disassemble.c \1080 frontend/pbc_disassemble/main.c 1081 1081 1082 $(DIS) : src/pbc_disassemble$(O) $(LIBPARROT)1082 $(DIS) : frontend/pbc_disassemble/main$(O) $(LIBPARROT) 1083 1083 $(LINK) @ld_out@$@ \ 1084 src/pbc_disassemble$(O) \1084 frontend/pbc_disassemble/main$(O) \ 1085 1085 src/longopt$(O) \ 1086 1086 $(RPATH_BLIB) $(ALL_PARROT_LIBS) $(LINKFLAGS) 1087 1087 #IF(win32): if exist $@.manifest mt.exe -nologo -manifest $@.manifest -outputresource:$@;1 1088 1088 1089 $(INSTALLABLEDIS) : src/pbc_disassemble$(O) \1089 $(INSTALLABLEDIS) : frontend/pbc_disassemble/main$(O) \ 1090 1090 src/install_config$(O) $(LIBPARROT) 1091 1091 $(LINK) @ld_out@$@ \ 1092 src/pbc_disassemble$(O) \1092 frontend/pbc_disassemble/main$(O) \ 1093 1093 src/longopt$(O) \ 1094 1094 @rpath_lib@ $(ALL_PARROT_LIBS) $(LINKFLAGS) 1095 1095 #IF(win32): if exist $@.manifest mt.exe -nologo -manifest $@.manifest -outputresource:$@;1 … … 2286 2286 $(PDUMP) frontend/pbc_dump/main$(O) frontend/pbc_dump/packdump$(O) \ 2287 2287 $(PDB) frontend/parrot_debugger/main$(O) \ 2288 2288 $(PBC_MERGE) frontend/pbc_merge/main$(O) \ 2289 $(DIS) src/pbc_disassemble$(O)2289 $(DIS) frontend/pbc_disassemble/main$(O) 2290 2290 $(RM_F) \ 2291 2291 frontend/parrot/main$(O) \ 2292 2292 src/null_config$(O) \ … … 2323 2323 $(PDUMP) frontend/pbc_dump/main$(O) frontend/pbc_dump/packdump$(O) \ 2324 2324 $(PDB) frontend/parrot_debugger/main$(O) \ 2325 2325 $(PBC_MERGE) frontend/pbc_merge/main$(O) \ 2326 $(DIS) src/pbc_disassemble$(O) \2326 $(DIS) frontend/pbc_disassemble/main$(O) \ 2327 2327 $(PARROT_CONFIG) parrot_config$(O) parrot_config.c \ 2328 2328 src/parrot_config$(O) parrot_config.pbc \ 2329 2329 pbc_to_exe$(EXE) pbc_to_exe$(O) pbc_to_exe.pbc \ -
(a) /dev/null vs. (b) b/frontend/pbc_disassemble/main.c
diff --git a/frontend/pbc_disassemble/main.c b/frontend/pbc_disassemble/main.c new file mode 100644 index 0000000..a213ccc
a b 1 /* Copyright (C) 2001-2009, Parrot Foundation. */ 2 3 /* 4 5 =head1 NAME 6 7 pbc_disassemble - parrot bytecode disassembler 8 9 =head1 SYNOPSIS 10 11 pbc_disassemble [-bh?] [--bare|--header-only] [-o outfile] [file.pbc] 12 13 =head1 DESCRIPTION 14 15 C<pbc_disassemble> translates Parrot bytecode (C<PBC>) into Parrot assembly 16 language (C<PASM>). 17 18 C<file.pbc> is the bytecode file to disassemble. If a file is not specified, the 19 bytecode will be read from C<stdin>. Additionally, if the C<-o> switch is not 20 given, the output is displayed to C<stdout>. 21 22 =head1 OPTIONS 23 24 =over 4 25 26 =item B<-?>, B<--help> 27 28 Displays usage and help information. 29 30 =item B<-b>, B<--bare> 31 32 Displays bare PASM without the header and left column. 33 34 =item B<-h>, B<--header-only> 35 36 Displays only the constants table header. 37 38 =item B<-o> filename, B<--output> filename 39 40 Writes output to C<filename>. 41 42 =back 43 44 =head1 STATIC FUNCTIONS 45 46 =over 4 47 48 =cut 49 50 */ 51 52 #include <stdio.h> 53 #include <stdlib.h> 54 #include <ctype.h> 55 56 #include "parrot/parrot.h" 57 #include "parrot/api.h" 58 #include "parrot/longopt.h" 59 60 #define PFOPT_UTILS 1 61 62 /* NOTE: 63 * C<pbc_disassemble> uses the C<Parrot_disassemble()> function from F<src/embed.c>, 64 * which in turn uses the C<PDB_disassemble()> function from F<src/debug.c>. 65 */ 66 67 /* Flags indicating the presence of the -b and -h command-line switches */ 68 typedef enum { 69 enum_DIS_BARE = 1, /* -b switch */ 70 enum_DIS_HEADER = 2 /* -h switch */ 71 } Parrot_disassemble_options; 72 73 /* Longopts option table */ 74 static struct longopt_opt_decl options[] = { 75 { '?', '?', OPTION_optional_FLAG, { "--help" } }, 76 { 'b', 'b', OPTION_optional_FLAG, { "--bare" } }, 77 { 'h', 'h', OPTION_optional_FLAG, { "--header-only" } }, 78 { 'o', 'o', OPTION_required_FLAG, { "--output" } }, 79 { 0 , 0, OPTION_optional_FLAG, { NULL } } 80 }; 81 82 static void help(void); 83 static void show_last_error_and_exit(Parrot_PMC interp); 84 85 /* 86 87 =item C<int main(int argc, const char *argv[])> 88 89 Execution entry point. Starts up an interpreter, loads the bytecode from the 90 command-line, and disassembles it. 91 92 =cut 93 94 */ 95 96 int 97 main(int argc, const char *argv[]) 98 { 99 const char *outfile = NULL; 100 int option = 0, 101 status = 0, 102 debug = PFOPT_UTILS; 103 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 104 105 Parrot_PMC interp = NULL, 106 pbc = NULL; 107 Parrot_String filename = NULL; 108 Parrot_Init_Args *initargs = NULL; 109 110 /* Parse command-line arguments */ 111 while ((status = longopt_get(argc, argv, options, &opt)) > 0) { 112 switch (opt.opt_id) { 113 case 'h': 114 option += enum_DIS_HEADER; 115 break; 116 case 'b': 117 option += enum_DIS_BARE; 118 break; 119 case 'o': 120 outfile = opt.opt_arg; 121 break; 122 case '?': 123 /* Fall through */ 124 default: 125 help(); 126 break; 127 } 128 } 129 130 /* Check for parse errors */ 131 if (status == -1) { 132 help(); 133 } 134 135 /* Set initialization parameters */ 136 GET_INIT_STRUCT(initargs); 137 138 /* Create new interpreter and set executable name */ 139 if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) 140 && Parrot_api_set_executable_name(interp, argv[0]))) { 141 142 fprintf(stderr, "PARROT VM: Could not initialize new interpreter\n"); 143 show_last_error_and_exit(interp); 144 } 145 146 argc -= opt.opt_index; 147 argv += opt.opt_index; 148 149 /* What to do about this debug flag? */ 150 /* pf = Parrot_pbc_read(interp, argc ? *argv : "-", debug); */ 151 152 /* Convert native char * to Parrot_String */ 153 if (!Parrot_api_string_import(interp, argc ? *argv : "-", &filename)) { 154 fprintf(stderr, "String transformation failed\n"); 155 show_last_error_and_exit(interp); 156 } 157 158 /* Disassemble bytecode and destroy interpreter */ 159 if (!(Parrot_api_load_bytecode_file(interp, filename, &pbc) 160 && Parrot_api_disassemble_bytecode(interp, pbc, outfile, option) 161 && Parrot_api_destroy_interpreter(interp))) { 162 163 fprintf(stderr, "Error during disassembly\n"); 164 show_last_error_and_exit(interp); 165 } 166 167 return 0; 168 } 169 170 /* 171 172 =item C<static void help(void)> 173 174 Prints out the user help information and exits. 175 176 =cut 177 178 */ 179 180 static void 181 help(void) 182 { 183 puts("pbc_disassemble - parrot bytecode disassembler\n"); 184 185 puts("Usage:"); 186 puts("pbc_disassemble [-bh] [file.pbc]"); 187 puts("pbc_disassemble -o file.pasm file.pbc\n"); 188 189 puts(" -?, --help Displays help information"); 190 puts(" -b, --bare Displays bare PASM without header and left column"); 191 puts(" -h, --header-only Dumps only the constants table header"); 192 puts(" -o, --output \"filename\" Writes output to \"filename\""); 193 194 exit(EXIT_SUCCESS); 195 } 196 197 /* 198 199 =item C<static void show_last_error_and_exit(Parrot_PMC interp)> 200 201 Prints out the C<interp>'s last error and exits. 202 203 =cut 204 205 */ 206 207 static void 208 show_last_error_and_exit(Parrot_PMC interp) 209 { 210 Parrot_Int is_error, 211 exit_code; 212 Parrot_String errmsg, 213 backtrace; 214 Parrot_PMC exception; 215 216 /* Get result of last API function call and exception backtrace */ 217 if (!(Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg) 218 && Parrot_api_get_exception_backtrace(interp, exception, &backtrace))) { 219 220 fprintf(stderr, "PARROT VM: Cannot recover\n"); 221 exit(EXIT_FAILURE); 222 } 223 224 /* Check for unhandled exceptions */ 225 if (is_error) { 226 char *msg; 227 228 /* Display error message */ 229 Parrot_api_string_export_ascii(interp, errmsg, &msg); 230 fprintf(stderr, "%s\n", msg); 231 Parrot_api_string_free_exported_ascii(interp, msg); 232 233 /* Display exception backtrace */ 234 Parrot_api_string_export_ascii(interp, backtrace, &msg); 235 fprintf(stderr, "%s\n", msg); 236 Parrot_api_string_free_exported_ascii(interp, msg); 237 } 238 239 exit(exit_code); 240 } 241 242 /* 243 244 =back 245 246 =head1 SEE ALSO 247 248 F<src/embed.c> and F<src/debug.c>. 249 250 =head1 HISTORY 251 252 Initial version by Daniel Grunblatt on 2002.5.26. 253 254 Florian Ragwitz: Moved POD documentation that's not necessary to know how to 255 actually run the disassembler to normal C comments (Wed, 16 Nov 2005). 256 257 Reini Urban: Renamed from disassemble to pbc_disassemble (2008-07-03). 258 Add options: help, -h, -o, --debug, --bare (2009-01-29) 259 Force option 1 for passing version check (2009-03-07) 260 261 Kevin Polulak (soh_cah_toa): Updated to use embedding API, moved source file 262 to frontend/pbc_disassemble, and cleaned up 263 source code and perldoc. (2011-06-19) 264 265 =cut 266 267 */ 268 269 /* 270 * Local variables: 271 * c-file-style: "parrot" 272 * End: 273 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : 274 */ 275 -
(a) a/src/pbc_disassemble.c vs. (b) /dev/null
diff --git a/src/pbc_disassemble.c b/src/pbc_disassemble.c deleted file mode 100644 index 8f59938..0000000
a b 1 /*2 Copyright (C) 2001-2009, Parrot Foundation.3 4 =head1 NAME5 6 pbc_disassemble - Parrot disassembler7 8 =head1 SYNOPSIS9 10 pbc_disassemble [-bdh?] [-o outfile] [file.pbc]11 12 =head1 DESCRIPTION13 14 This uses the C<Parrot_disassemble()> function from F<src/embed.c>,15 which in turn uses the C<PDB_disassemble()> function from16 F<src/debug.c>.17 18 Without non-option arguments it reads the pbc from STDIN.19 20 =head2 Functions21 22 =over 423 24 =cut25 26 */27 28 #include <stdio.h>29 #include <stdlib.h>30 #include <ctype.h>31 #include "parrot/parrot.h"32 #include "parrot/longopt.h"33 34 #define PFOPT_UTILS 135 36 typedef enum {37 enum_DIS_BARE = 1,38 enum_DIS_HEADER = 239 } Parrot_disassemble_options;40 41 static void show_last_error_and_exit(Parrot_PMC interp);42 43 /*44 45 =item C<static void help(void)>46 47 Print out the user help info.48 49 =cut50 51 */52 53 static void help(void)54 {55 printf("pbc_disassemble - dump or convert parrot bytecode (PBC) files\n");56 printf("usage:\n");57 printf("pbc_disassemble [-bh] [--bare|--header-only] [file.pbc]\n");58 printf("pbc_disassemble -o converted.pasm file.pbc\n\n");59 printf(" -b\t\t ... bare .pasm without header and left column\n");60 printf(" -h\t\t ... dump Constant-table header only\n");61 printf(" -o filename\t ... output to filename\n");62 exit(EXIT_SUCCESS);63 }64 65 static struct longopt_opt_decl options[] = {66 { 'h', 'h', OPTION_optional_FLAG, { "--header-only" } },67 { '?', '?', OPTION_optional_FLAG, { "--help" } },68 { 'b', 'b', OPTION_optional_FLAG, { "--bare" } },69 { 'o', 'o', OPTION_required_FLAG, { "--output" } },70 { 0 , 0, OPTION_optional_FLAG, { NULL } }71 };72 73 /*74 75 =item C<int main(int argc, const char *argv[])>76 77 The run-loop. Starts up an interpreter, loads the bytecode from the78 command-line and disassembles it.79 80 =cut81 82 */83 84 int85 main(int argc, const char *argv[])86 {87 Parrot_PMC interp;88 Parrot_PMC pbc;89 Parrot_String filename;90 const char *outfile = NULL;91 int option = 0;92 int debug = PFOPT_UTILS;93 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;94 int status;95 Parrot_Init_Args *initargs;96 GET_INIT_STRUCT(initargs);97 98 if (!(Parrot_api_make_interpreter(NULL, 0, initargs, &interp) &&99 Parrot_api_set_executable_name(interp, argv[0]))) {100 fprintf(stderr, "PARROT VM: Could not initialize new interpreter");101 show_last_error_and_exit(interp);102 }103 104 while ((status = longopt_get(argc, argv, options, &opt)) > 0) {105 switch (opt.opt_id) {106 case 'h':107 option += enum_DIS_HEADER;108 break;109 case 'b':110 option += enum_DIS_BARE;111 break;112 case 'o':113 outfile = opt.opt_arg;114 break;115 case '?':116 default:117 help();118 break;119 }120 }121 if (status == -1) {122 help();123 }124 argc -= opt.opt_index;125 argv += opt.opt_index;126 127 /* What to do about this debug flag? */128 /* pf = Parrot_pbc_read(interp, argc ? *argv : "-", debug); */129 130 Parrot_api_string_import(interp, argc ? *argv : "-", &filename);131 if (!(Parrot_api_load_bytecode_file(interp, filename, &pbc) &&132 Parrot_api_disassemble_bytecode(interp, pbc, outfile, option) &&133 Parrot_api_destroy_interpreter(interp))) {134 fprintf(stderr, "Error during disassembly\n");135 show_last_error_and_exit(interp);136 }137 exit(EXIT_SUCCESS);138 }139 140 /*141 142 =item C<static void show_last_error_and_exit(Parrot_PMC interp)>143 144 Prints out the C<interp>'s last error and exits.145 146 =cut147 148 */149 150 static void151 show_last_error_and_exit(Parrot_PMC interp)152 {153 Parrot_String errmsg, backtrace;154 Parrot_Int exit_code, is_error;155 Parrot_PMC exception;156 157 if (!(Parrot_api_get_result(interp, &is_error, &exception, &exit_code, &errmsg) &&158 Parrot_api_get_exception_backtrace(interp, exception, &backtrace))) {159 fprintf(stderr, "PARROT VM: Cannot recover\n");160 exit(EXIT_FAILURE);161 }162 163 if (errmsg) {164 char * errmsg_raw;165 Parrot_api_string_export_ascii(interp, errmsg, &errmsg_raw);166 fprintf(stderr, "%s\n", errmsg_raw);167 Parrot_api_string_free_exported_ascii(interp, errmsg_raw);168 169 Parrot_api_string_export_ascii(interp, backtrace, &errmsg_raw);170 fprintf(stderr, "%s\n", errmsg_raw);171 Parrot_api_string_free_exported_ascii(interp, errmsg_raw);172 }173 exit(exit_code);174 }175 176 /*177 178 =back179 180 =head1 SEE ALSO181 182 F<src/embed.c> and F<src/debug.c>.183 184 =head1 HISTORY185 186 Initial version by Daniel Grunblatt on 2002.5.26.187 188 Florian Ragwitz: Moved POD documentation that's not necessary to know how to189 actually run the disassembler to normal C comments (Wed, 16 Nov 2005).190 191 Reini Urban: Renamed from disassemble to pbc_disassemble (2008-07-03).192 Add options: help, -h, -o, --debug, --bare (2009-01-29)193 Force option 1 for passing version check (2009-03-07)194 195 =cut196 197 */198 199 200 /*201 * Local variables:202 * c-file-style: "parrot"203 * End:204 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :205 */ -
t/tools/pbc_disassemble.t
diff --git a/t/tools/pbc_disassemble.t b/t/tools/pbc_disassemble.t index b383c3f..2246506 100644
a b 48 48 } 49 49 50 50 my $helpregex = <<OUTPUT; 51 /pbc_disassemble - dump or convert parrot bytecode [(]PBC[)] files 52 usage: 51 /pbc_disassemble - parrot bytecode disassembler 52 53 Usage: 53 54 pbc_disassemble .* [[]file.pbc[]] 54 pbc_disassemble -o converted[.]pasm file[.]pbc 55 \\s+(-.*\\s+[.]{3}\\s+.* 55 pbc_disassemble -o file[.]pasm file[.]pbc 56 57 \\s+(-.{1},\\s+--.*(["]\\w+["])?\\s+.* 56 58 )+/m 57 59 OUTPUT 58 60