[seed] add backtrace stack to the exception string
- From: Alan Knowles <alank src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seed] add backtrace stack to the exception string
- Date: Fri, 10 Aug 2012 10:56:14 +0000 (UTC)
commit 9f1c31e475e5b782edca239023eaf0d64ddc37fc
Author: Alan Knowles <alan roojs com>
Date: Fri Aug 10 18:55:52 2012 +0800
add backtrace stack to the exception string
libseed/seed-exceptions.c | 27 +++++++++++++++++++++++++--
libseed/seed-exceptions.h | 1 +
2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/libseed/seed-exceptions.c b/libseed/seed-exceptions.c
index 2025e77..abaa210 100644
--- a/libseed/seed-exceptions.c
+++ b/libseed/seed-exceptions.c
@@ -208,6 +208,28 @@ seed_exception_get_file (JSContextRef ctx, JSValueRef e)
line = seed_object_get_property (ctx, (JSObjectRef) e, "sourceURL");
return seed_value_to_string (ctx, line, 0);
}
+/**
+ * seed_exception_get_stack:
+ * @ctx: A #SeedContext.
+ * @exception: A reference to a #SeedException.
+ *
+ * Retrieves the backtrace stack (if available..
+ *
+ * Return value: A #gchar* representing the name of the file from which
+ * @exception was thrown.
+ *
+ */
+gchar *
+seed_exception_get_stack (JSContextRef ctx, JSValueRef e)
+{
+ JSValueRef stack ;
+ g_assert ((e));
+ if (!JSValueIsObject (ctx, e))
+ return 0;
+ stack = seed_object_get_property (ctx, (JSObjectRef) e, "stack");
+ return seed_value_to_string (ctx, stack , 0);
+}
+
/**
* seed_exception_to_string:
@@ -226,14 +248,15 @@ gchar *
seed_exception_to_string (JSContextRef ctx, JSValueRef e)
{
guint line;
- gchar *mes, *name, *file, *ret;
+ gchar *mes, *name, *file, *ret, *stack;
line = seed_exception_get_line (ctx, e);
mes = seed_exception_get_message (ctx, e);
file = seed_exception_get_file (ctx, e);
name = seed_exception_get_name (ctx, e);
+ stack = seed_exception_get_stack (ctx, e);
- ret = g_strdup_printf ("Line %d in %s: %s %s", line, file, name, mes);
+ ret = g_strdup_printf ("Line %d in %s: %s %s\n\nStack:\n%s", line, file, name, mes, stack);
g_free (mes);
g_free (file);
diff --git a/libseed/seed-exceptions.h b/libseed/seed-exceptions.h
index cefdf70..cc1a261 100644
--- a/libseed/seed-exceptions.h
+++ b/libseed/seed-exceptions.h
@@ -35,6 +35,7 @@ G_GNUC_PRINTF (4, 5);
gchar *seed_exception_get_message (JSContextRef ctx, JSValueRef e);
guint seed_exception_get_line (JSContextRef ctx, JSValueRef e);
gchar *seed_exception_get_file (JSContextRef ctx, JSValueRef e);
+ gchar *seed_exception_get_stack (JSContextRef ctx, JSValueRef e);
gchar *seed_exception_to_string (JSContextRef ctx, JSValueRef e);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]