From 5efbda88a565af316e2b4afb0cca56fed7531d84 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Thu, 20 Dec 2018 00:03:24 -0500
Subject: [PATCH] test out sending a stack trace to the GUI on error

---
 pd/nw/pdgui.js   |  6 +++++-
 pd/src/s_print.c | 17 ++++++++++++++++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 97d0fa3a0..480ce36a2 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -731,8 +731,12 @@ function pd_error_select_by_id(objectid) {
 
 exports.pd_error_select_by_id = pd_error_select_by_id;
 
-function gui_post_error(objectid, loglevel, error_msg) {
+function gui_post_error(objectid, loglevel, error_msg, trace_array) {
+    var i;
     do_post(objectid, "error", error_msg, "error", loglevel);
+    for (i = 0; i < trace_array.length; i++) {
+        post(trace_array[i][1] + ": " + trace_array[i][2]);
+    }
 }
 
 // This is used specifically by [print] so that we can receive the full
diff --git a/pd/src/s_print.c b/pd/src/s_print.c
index 19d1760cb..dde95fd64 100644
--- a/pd/src/s_print.c
+++ b/pd/src/s_print.c
@@ -3,6 +3,9 @@
 * WARRANTIES, see the file, "LICENSE.txt," in this distribution.  */
 
 #include "m_pd.h"
+// hm... we really don't want this...
+#include "m_imp.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -65,10 +68,22 @@ static void doerror(const void *object, const char *s)
         //sys_vgui("pdtk_posterror {%s} 1 {%s}\n",
         //    strnpointerid(obuf, object, MAXPDSTRING),
         //    strnescape(upbuf, s, MAXPDSTRING));
-        gui_vmess("gui_post_error", "sis",
+        gui_start_vmess("gui_post_error", "sis",
             strnpointerid(obuf, object, MAXPDSTRING),
             1,
             strnescape(upbuf, s, MAXPDSTRING));
+        int i;
+        gui_start_array();
+        for (i = pd_stackn - 1; i >= 0; i--)
+        {
+            gui_start_array();
+            gui_x((long unsigned int)pd_stack[i].self);
+            gui_s(class_getname(pd_class(pd_stack[i].self)));
+            gui_s(pd_stack[i].s->s_name);
+            gui_end_array();
+        }
+        gui_end_array();
+        gui_end_vmess();
     }
 }
 
-- 
GitLab