Permalink
Browse files

Finally add in the rudiments of my error reporting mechanism. There i…

…s now a final_error STRING on the interp that is reserved for printing error messages of last resort. Several other fixes. parrot_nci_thunk_gen still fails with segfault, after the main runcore terminates from unhandled exception. I suspect calling Parrot_exit at that point breaks things irrepairably and later operations fail in bad ways. I may need to remove Parrot_exit from die_from_exception to prevent things from dieing and being unable to resurrect.
  • Loading branch information...
1 parent 590f387 commit 36fca15bcfbb2a734913e4d506b9f742ba1cc9b9 @Whiteknight Whiteknight committed Nov 25, 2010
Showing with 28 additions and 16 deletions.
  1. +1 −0 include/parrot/interpreter.h
  2. +2 −1 src/embed/api.c
  3. +4 −4 src/embed/embed_private.h
  4. +1 −1 src/embed/strings.c
  5. +5 −4 src/exceptions.c
  6. +4 −3 src/main.c
  7. +11 −3 tools/dev/pbc_to_exe.pir
@@ -268,6 +268,7 @@ struct parrot_interp_t {
* inside the invoke these get moved to the context structure */
PMC *current_cont; /* the return continuation PMC */
jmp_buf api_jmp_buf; /* jmp point out of Parrot */
+ STRING * final_error; /* string to hold the final error message */
};
/* typedef struct parrot_interp_t Interp; done in parrot.h so that
View
@@ -10,7 +10,8 @@ Parrot_Int
Parrot_api_get_last_error(ARGMOD(PMC * interp_pmc), ARGOUT(Parrot_String * errmsg))
{
EMBED_API_CALLIN(interp_pmc, interp);
- *errmsg = Parrot_str_new(interp, "Generic Error Message", 0);
+ *errmsg = interp->final_error;
+ interp->final_error = NULL;
EMBED_API_CALLOUT(interp_pmc, interp);
}
@@ -6,10 +6,11 @@
#define GET_RAW_INTERP(p) ((Parrot_ParrotInterpreter_attributes*)(p)->data)->interp;
#define EMBED_API_CALLIN(p, i) \
- void * _oldtop; \
Parrot_Interp (i) = PMC_IS_NULL(p) ? NULL : GET_RAW_INTERP(p); \
- _oldtop = (i)->lo_var_ptr; \
- if (_oldtop) {} else (i)->lo_var_ptr = &_oldtop; \
+ void * const _oldtop = (i)->lo_var_ptr; \
+ if (_oldtop == NULL) \
+ (i)->lo_var_ptr = &_oldtop; \
+ (i)->final_error = NULL; \
if (setjmp((i)->api_jmp_buf)) { \
return 0; \
} else { \
@@ -23,5 +24,4 @@
return 1; \
}
-
#endif /* PARROT_EMBED_PRIVATE_H */
View
@@ -10,7 +10,7 @@ Parrot_api_string_export_ascii(Parrot_PMC interp_pmc, ARGIN(Parrot_String string
{
//ASSERT_ARGS(Parrot_api_string_export)
EMBED_API_CALLIN(interp_pmc, interp);
- *strout = Parrot_str_to_cstring(interp_pmc,string);
+ *strout = Parrot_str_to_cstring(interp, string);
EMBED_API_CALLOUT(interp_pmc, interp);
}
View
@@ -103,11 +103,11 @@ die_from_exception(PARROT_INTERP, ARGIN(PMC *exception))
const INTVAL severity = already_dying ? EXCEPT_fatal :
VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "severity"));
-
+ interp->final_error = message;
if (already_dying) {
- fflush(stderr);
- fprintf(stderr, "\n***FATAL ERROR: "
- "Exception thrown while dying from previous unhandled Exception\n");
+ //fflush(stderr);
+ //fprintf(stderr, "\n***FATAL ERROR: Exception thrown while dying from previous unhandled Exception\n");
+ Parrot_exit(interp, EXCEPT_fatal);
}
else {
/* In some cases we have a fatal exception before the IO system
@@ -172,6 +172,7 @@ die_from_exception(PARROT_INTERP, ARGIN(PMC *exception))
* only main should run the destroy functions - exit handler chain
* is freed during Parrot_exit
*/
+ interp->final_error = message;
Parrot_exit(interp, exit_status);
}
View
@@ -169,9 +169,10 @@ static void
get_last_error(Parrot_PMC interp)
{
Parrot_String errmsg;
- char * errmsg_raw;
- if (Parrot_api_get_last_error(interp, &errmsg) &&
- Parrot_api_string_export_ascii(interp, errmsg, &errmsg_raw)) {
+ char * errmsg_raw = "This is a test";
+ if (Parrot_api_get_last_error(interp, &errmsg)
+ //Parrot_api_string_export_ascii(interp, errmsg, &errmsg_raw)
+ ) {
fprintf(stderr, "PARROT VM: Catastrophic error. Cannot recover\n");
Parrot_api_string_free_exported_ascii(interp, errmsg_raw);
}
View
@@ -100,9 +100,17 @@ HEADER
//Parrot_set_flag(interp, PARROT_DESTROY_FLAG);
- if (!(Parrot_api_load_bytecode_bytes(interp, program_code_addr, bytecode_size, &pbc) &&
- Parrot_api_build_argv_array(interp, argc, argv, &argsarray) &&
- Parrot_api_run_bytecode(interp, pbc, argsarray))) {
+ if (!Parrot_api_load_bytecode_bytes(interp, program_code_addr, bytecode_size, &pbc)) {
+ fprintf(stderr, "PARROT VM: Could not load bytecode");
+ get_last_error(interp);
+ exit(EXIT_FAILURE);
+ }
+ if (!Parrot_api_build_argv_array(interp, argc, argv, &argsarray)) {
+ fprintf(stderr, "PARROT VM: Could not build args array");
+ get_last_error(interp);
+ exit(EXIT_FAILURE);
+ }
+ if (!Parrot_api_run_bytecode(interp, pbc, argsarray)) {
fprintf(stderr, "PARROT VM: Execution failed");
get_last_error(interp);
exit(EXIT_FAILURE);

0 comments on commit 36fca15

Please sign in to comment.