From 9c9fb23f5547a723700f24e622298b1e12cc284c Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Tue, 22 Jan 2019 08:39:03 +0100 Subject: [PATCH] debug.nas add callback to breakpoint --- Nasal/debug.nas | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Nasal/debug.nas b/Nasal/debug.nas index 1fdca34ee..ce07490e5 100644 --- a/Nasal/debug.nas +++ b/Nasal/debug.nas @@ -451,8 +451,9 @@ var isnan = func { # myBP.enable(4); # allow 4 hits, then be quiet # # #at the place of interest (e.g. in some loop or class method) insert: -# myBP.hit(); # do backtrace here if tokens > 0, reduce tokens by 1 -# +# myBP.hit(); # do backtrace here if tokens > 0, reduce tokens by 1 +# myBP.hit(myFunction); # same but call myFunction instead of backtrace +# # print(myBP.getHits()); # print total number of hits # var Breakpoint = { @@ -500,13 +501,19 @@ var Breakpoint = { }, # hit the breakpoint, e.g. do backtrace if we have tokens available - hit: func() { + hit: func(callback = nil) { me.hits += 1; me._hitsN.setIntValue(me.hits); me.tokens = me._tokensN.getValue(); if (me.tokens > 0) { - debug.backtrace(me.label, me.dump_locals, 1); - me._tokensN.setValue(me.tokens - 1); + me.tokens -= 1; + if (typeof(callback) == "func") { + callback(me.hits, me.tokens); + } + else { + debug.backtrace(me.label, me.dump_locals, 1); + } + me._tokensN.setValue(me.tokens); } return me; },