[svn:parrot] r38068 - in trunk: include/parrot src
tene at svn.parrot.org
tene at svn.parrot.org
Sun Apr 12 00:19:01 UTC 2009
Author: tene
Date: Sun Apr 12 00:18:59 2009
New Revision: 38068
URL: https://trac.parrot.org/parrot/changeset/38068
Log:
[exceptions]: Add the HLL line number to the message printed for uncaught exceptions.
Modified:
trunk/include/parrot/exceptions.h
trunk/include/parrot/string_funcs.h
trunk/src/exceptions.c
Modified: trunk/include/parrot/exceptions.h
==============================================================================
--- trunk/include/parrot/exceptions.h Sat Apr 11 16:55:00 2009 (r38067)
+++ trunk/include/parrot/exceptions.h Sun Apr 12 00:18:59 2009 (r38068)
@@ -222,6 +222,10 @@
unsigned int line);
void Parrot_print_backtrace(void);
+void print_hll_info_from_exception(PARROT_INTERP, ARGIN(PMC *exception))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
#define ASSERT_ARGS_exit_fatal __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(format)
#define ASSERT_ARGS_Parrot_assert __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -263,6 +267,9 @@
|| PARROT_ASSERT_ARG(exception)
#define ASSERT_ARGS_do_panic __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_Parrot_print_backtrace __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
+#define ASSERT_ARGS_print_hll_info_from_exception __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(exception)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/exceptions.c */
Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h Sat Apr 11 16:55:00 2009 (r38067)
+++ trunk/include/parrot/string_funcs.h Sun Apr 12 00:18:59 2009 (r38068)
@@ -418,7 +418,8 @@
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
-INTVAL Parrot_str_to_int(SHIM_INTERP, ARGIN_NULLOK(const STRING *s));
+INTVAL Parrot_str_to_int(PARROT_INTERP, ARGIN_NULLOK(const STRING *s))
+ __attribute__nonnull__(1);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
@@ -678,7 +679,8 @@
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_str_to_hashval __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_str_to_int __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
+#define ASSERT_ARGS_Parrot_str_to_int __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_str_to_num __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(s)
Modified: trunk/src/exceptions.c
==============================================================================
--- trunk/src/exceptions.c Sat Apr 11 16:55:00 2009 (r38067)
+++ trunk/src/exceptions.c Sun Apr 12 00:18:59 2009 (r38068)
@@ -90,6 +90,52 @@
/*
+=item C<void print_hll_info_from_exception(PARROT_INTERP, PMC *exception)>
+
+Print hll line number for C<exception>, if present.
+
+=cut
+
+*/
+
+void
+print_hll_info_from_exception(PARROT_INTERP, ARGIN(PMC *exception))
+{
+ PMC * list;
+ PMC * line;
+ PMC * iter;
+ const STRING * const bt = CONST_STRING(interp, "backtrace");
+ STRING * message = VTABLE_get_string(interp, exception);
+ if (STRING_IS_NULL(message) || Parrot_str_equal(interp, message, CONST_STRING(interp, ""))) {
+ const INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "severity"));
+ if (severity < EXCEPT_error) {
+ message = CONST_STRING(interp, "warning");
+ }
+ else {
+ message = CONST_STRING(interp, "died");
+ }
+ }
+ Parrot_PCCINVOKE(interp, exception, bt, "->P", &list);
+ iter = VTABLE_get_iter(interp, list);
+ while (VTABLE_get_bool(interp, iter)) {
+ const PMC * const frame = VTABLE_shift_pmc(interp, iter);
+ const PMC * const annotations = VTABLE_get_pmc_keyed_str(interp, frame, CONST_STRING(interp, "annotations"));
+ line = VTABLE_get_pmc_keyed_str(interp, annotations, CONST_STRING(interp, "line"));
+ if (!PMC_IS_NULL(line)) {
+ break;
+ }
+ }
+ Parrot_io_eprintf(interp, "%Ss", message);
+ fflush(stderr);
+ if (!PMC_IS_NULL(line)) {
+ Parrot_io_eprintf(interp, " at line %d", VTABLE_get_integer(interp, line));
+ }
+ Parrot_io_eprintf(interp, "\n");
+ return;
+}
+
+/*
+
=item C<void die_from_exception(PARROT_INTERP, PMC *exception)>
Print a stack trace for C<exception>, a message if there is one, and then exit.
@@ -120,8 +166,7 @@
}
if (Parrot_str_not_equal(interp, message, CONST_STRING(interp, ""))) {
- Parrot_io_eprintf(interp, "%S\n", message);
-
+ print_hll_info_from_exception(interp, exception);
/* caution against output swap (with PDB_backtrace) */
fflush(stderr);
PDB_backtrace(interp);
@@ -131,7 +176,7 @@
exit_status = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "exit_code"));
}
else {
- Parrot_io_eprintf(interp, "No exception handler and no message\n");
+ print_hll_info_from_exception(interp, exception);
/* caution against output swap (with PDB_backtrace) */
fflush(stderr);
PDB_backtrace(interp);
@@ -203,16 +248,10 @@
opcode_t *address;
PMC * const handler = Parrot_cx_find_handler_local(interp, exception);
if (PMC_IS_NULL(handler)) {
- STRING * const message = VTABLE_get_string(interp, exception);
const INTVAL severity = VTABLE_get_integer_keyed_str(interp, exception, CONST_STRING(interp, "severity"));
if (severity < EXCEPT_error) {
+ print_hll_info_from_exception(interp, exception);
PMC * const resume = VTABLE_get_attr_str(interp, exception, CONST_STRING(interp, "resume"));
- if (Parrot_str_not_equal(interp, message, CONST_STRING(interp, ""))) {
- Parrot_io_eprintf(interp, "%S\n", message);
- }
- else {
- Parrot_io_eprintf(interp, "%S\n", CONST_STRING(interp, "Warning"));
- }
/* caution against output swap (with PDB_backtrace) */
fflush(stderr);
More information about the parrot-commits
mailing list