How To Debug js code in the board?

Posted on
of 2
/ 2
  • Thanks! I actually had call to use it in something this afternoon (debugging a temperature calculation) and it's already saved me a few minutes. Should have done it ages ago!

    Calling foo(a,b) is treated as one step, is there a way to step into functions ?

    Use step/s? That's the difference between step and next (next goes over functions)

    What is difference between i l and i s ?

    i l prints just the stuff local to that function

    i s prints the whole scope chain (which could end up being big - hence you might not always want to do it)

  • That's amazing!

    Can't wait to give it a try. Just gotta write some bugs, but as everyone here knows, I'm real good at that ;-)

    Actually, what's most amazing is that this was requested just two days ago!

  • Hi, I faced some "random" out of memory errors after hours of no memory leakage running program. So if would suggest, humbly, some watch point based on free memory. This could allow for tricky unfreed memory after garbage collection. I mean local objects not really freed as beeing still referenced either recursively / undirectlyor through anonymous functions still accessible in some cases...
    I know I am asking quite a lot, but it could help a lot with such a language such as javascript.

    And yes, @Gordon is doing a tremendous demonstration of his capabilities to answer to his customers's problems.... I am really impressed by your reactivity!

  • I just gave a try and found it simple and efficient. Thank you @Gordon

  • Great! To be fair there was a bug filed for it 2 years ago, so it has taken a while. I just found a reasonable way to do it.

    Memory debugging is difficult though. I can't think of a nice way of doing that at the moment, but will think on it.

  • Nice addition.

  • I was just dreaming it could be linked to the garbage collector, like a kind of post-mortem debugging with the help of the ide....
    Just dreaming!

  • Well, the garbage collector doesn't really know very much about what's going on. I'm not quite sure I understand your problem - you actually have a leak in your code (rather than Espruino itself?).

    You can run the debugger when memory usage gets too high: if (process.memory().free<500) debugger;

    And you can also see how many variables each object is using with: E.getSizeOf(myobject)

    For instance you could dump all your global variables and their sizes with: for (var i in global) print(i+" : "+E.getSizeOf(global[i])) (I actually just fixed a bug that can make this crash in some cases though)

    Then you could keep track of those and see if any of them rise up (of course it could be a variable in a closure that's causing you problems).

    If you've got specific problems debugging it I'd post up in another thread though - I think the answers would be helpful to a lot of people.

  • Ok, I'll open a specific thread for my problem: it could be either a variable in closure although I don't see how and also a serial buffer overflow.
    Actually, your answer will be usefull to me as usual.
    Thank's again!

  • old topic...
    I'm trying to put debugger; into code. but emulator does not stop there.

    var myMenu = {
        "" : { 
          "title" : "Title"
        "< Back" : () => back(),
        "Test": {
          format : function (v) {
            var options=myMenu[""];
            var fh = options.fontHeight;
            return v;
  • No - debugging doesn't work in the emulator I'm afraid.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

How To Debug js code in the board?

Posted by Avatar for LifangXia @LifangXia