Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: [duplicate] Arduino Debug via Serial

  1. #1

    [duplicate] Arduino Debug via Serial

    We have a created a Debugging tool compatible with the Teensyduino platform, for all Teensy boards, running over the Serial port. This is part of the Visual Studio development extension Visual Micro.

    This allows you to:
    • Step by Step execution using breakpoints
    • Performance Monitoring for execution time between breakpoints
    • Conditional breakpoints (based on data or hit count)
    • Variable monitoring with automatic min/max tracking
    • Change variables at runtime
    • Automatic Visual Pin monitoring
    • Easy to use Charting (for any data)


    Code Example (all features use standard breakpoints):


    Example of Charting Running, with data tracking and Min/Max data visible:


    Example of Performance Output:


    Video of Teensy Install + Basic Serial Debugging in Action


    Video of @Plot Charts with Serial Debugger (works the same on Teensy)


    @Plot Charting Further Info

    Visual Micro VS Extension Website
    Last edited by visual_micro; 01-09-2020 at 03:43 PM.

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,919
    Technically, how does this work? There seems to be additional code on the Teensy - what exactly does it?
    Or, better, do you have a link where the sourcecode is available? I'd like to see it.

  3. #3
    It's a good question. We support both the injected serial (or software serial) debugger described in this post and also hardware debuggers.

    Both types of debuggers have advantages and disadvantages. Without hardware debug users either add their own serial debug statements throughout their code and/or they can use the Visual Micro break/trace points. The number of break/trace points is limited only by mcu memory and do not change the real code.

    Manually adding serial statements to track min/max values, monitor the millis() between code points, update variable values at runtime can be tedious, therefore Visual Micro adds the same (or similar) serial statements, based on the configuration of each breakpoint. Debug message strings remain on the pc which can often end up consuming less memory than large serial.print diagnostics messages in the code.

    Injecting code into the temporary build files prior to compile works quite well for Arduino projects because, as you will know, the the build always happens in a hidden temp folder. This is because the .ino code needs to be merged into .cpp. The use of the temp folder gives perfect opportunity to inject code when in debug mode.

    To ensure this solution works with all Arduino board types, Visual Micro injects standard Arduino code such as Serial.read(), Serial.print() based on the user configured debug settings. All of the code produced by Visual Micro can be seen in the temp build folder after compliation. tip: The temp build folder is displayed in the build output when "vMicro>Compiler>Show build folder" or "Compile>Verbose" is enabled.

    Breakpoint properties such as {@plot} simply add the value (or expression result) to a delimited serial.print() prefixed by a breakpoint id (such as #1) The pc knows what to do with the data in terms of displaying messages, watches, plots or pin maps.

    Hopefully the following links explain a little more?

    https://www.visualmicro.com/page/Use...Explained.html

    https://www.visualmicro.com/page/Use...Debugging.html

    https://www.visualmicro.com/page/User-Guide.aspx


    Main Restrictions: It is not currently possible to single step code lines, it is only possible to step from one point to another. Variables and/or expressions to be watched and/or updated during runtime must be added to the breakpoint before upload. Breakpoint positions must be set prior to upload. Not possible to use in ISR. Not possible to use inside code parts that have mission critical timings but that applies to most debuggers.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,919
    Ah.. got it. This means, for Teensy, the sourcecode has to be rebuilt if you change a breakpoint or a variable-watch.
    Some code I wrote takes a minute to compile.. of course not all But it gets interesting on large projects. So If I enable or disable a breakpoint I have to wait...
    Well, I have to wait now - without your debugger - too.

    (I wonder if something similar can be done by inserting a (more or less complex) macro.)

    Nevertheless - it seems easy to use.

  5. #5
    Yes we are currently looking at giving some more flexibility to serial debug without need to recompile. It's looking quite exciting so will update this post with more info when/if it works.

    One gotcha of dynamic breakpoints will be optimization settings. By identifying variables and expressions before upload ( and injecting references) we won't have to worry about the compiler optimization settings in the same way that we do for hardware debug. For hardware debug, changing the optimization is easy via our menus but some platforms have been designed not to work well or become too large with less optimization. Therefore dynamic breakpoints might not be as great as they sound.

    BTW: Teensy used to be a very fast build as did all the old avr tools. If I recall pjrc have been waiting for the Arduino IDE to move to newer toolchains, which I think they have just done. Hopefully we will shortly see super fast Teensy builds again. A couple of minutes will likely be reduced to sub 20 secs (going on past experience). Fingers crossed

  6. #6
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    I just found this project and wanted to mention a similar project I've been working on that does allow dynamic breakpoints and code stepping: https://forum.pjrc.com/threads/61373...823#post243823

  7. #7
    Thanks for the update on the GDBStub you have produced, it really is brilliant! We have added the options into Visual Micro so your GDBStub can be used easily (once installed) in our latest update (posted here).

    We still feel the Serial debugger is a separate offering due to its universal operation (on all models of board) as well as additional visualisation features and performance tracking which are built in.

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,153
    This sounds great.

    I thought I would give some of this a try again.

    Most of the time I have been using sublimetext for editing, of anything other than simple sketches. Using @FrankB/@defragster build scripts which work great most of the time.

    There are some interesting issues of error messages showing up against the copy of the files in the temporary directory instead of the sources, where I have fixed the error there and then compiled and had the same error...

    So It great to see that you properly get to a sketches included header or cpp file instead of the copy that Arduino makes.


    But a lot of the time I spend most of my energy fixing or extending library code, and often times the sketches are just simple test cases.
    With Sublime text I can create projects and add those library directories to the project and then search through the project files and the like.

    Is there something equivalent in the VisualMicro setup. Note: when I am done with things, I want everything built using the Arduino IDE tools, such that anyone else can run the examples by justing using the Arduino IDE. Hope that makes sense.

    Suggestions on how to work on Arduino libraries would be great.

    Thanks
    Kurt

  9. #9
    Visual Micro does have equivalent functionality to achieve what you need.

    Libraries can be added to your sketch, with the "Add Libraries" > "Clone for Project when Including Libraries" option checked. Ensure the "Use Library Version in Clones" is unchecked.
    When adding them to your sketch they will be automatically cloned to the \Libraries\ folder within the project, and the relevant #include <header.h> references.
    Just update these references to be surrounded by double quotes instead of chevrons to ensure they are seen as relative references.

    These same sketches can also be compiled in the Arduino IDE.

    The options listed above are shown in this You Tube video, and in our Documentation
    Last edited by visual_micro; 06-25-2020 at 04:50 PM.

  10. #10
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,153
    Quick update here: - Maybe should post on Visual_Micro forum... But thought I would mention more here in case anyone else tries it here.

    Took me a couple of attempts to get some of this stuff to work. Still trying to figure some stuff out.

    I brought up Visual Studio and it said there was an update for VisualMicro stuff, so thought it was THIS update... Turns out it is not... You need to go to the version of their post, to get this support.

    Quote Originally Posted by visual_micro View Post
    Visual Micro does have equivalent functionality to achieve what you need.

    Libraries can be added to your sketch, with the "Add Libraries" > "Clone for Project when Including Libraries" option checked. Ensure the "Use Library Version in Clones" is unchecked.
    When adding them to your sketch they will be automatically cloned to the \Libraries\ folder within the project, and the relevant #include <header.h> references.
    Just update these references to be surrounded by double quotes instead of chevrons to ensure they are seen as relative references.

    These same sketches can also be compiled in the Arduino IDE.

    The options listed above are shown in this You Tube video, and in our Documentation
    Looks like I need to look more at this as I am not sure which of these settings make sense for what I want to do.

    For example currently I brought in a sketch, where it uses several system libraries, example USBHost_t36, Lynxmotion Smart Servo, ...
    (https://github.com/KurtE/LSS_Test_sk...nixUSBJoystick)

    My hope is to debug my code here. However some of my code is also within these libraries, example USB Host code, as I am trying to debug and extend Bluetooth support for some of the joysticks.

    Any fixes I make for this sketch, I wish for those to be made to the actual library such that I then can test with other sketches and to do commits to Github and depending on if I am owner of the library or using a clone either to simply push up to github or to create a Pull Request.

    So I am trying to understand best approach for this.

    Note: I just started fresh again and deleted all of the Visual studio files. from this project and then went to Open Existing Arduino project... I did this as I deleted a source file external from Visual Studio and when I tried to build again, the build failed as it could not find that file... I know there are easier ways to recover but used the sledgehammer approach

    So it loaded up the files. I went into configuration manager and changed to debug. I have the options for Dual Serial, 600mh (T4.1) Faster...
    Set to Debug Hardware, GDBStub Default optimization and then I tried the Debug Start command...

    It started building... Link failed:
    Code:
    LSS_Phoenix_Input_USB_Joystick.cpp.o: In function USBDriver::USBDriver()
    
    Error linking for board Teensy 4.1
    USBHost_t36.h:429: undefined reference to vtable for USBDriver
    Build failed for project 'LSS_PhoenixUSBJoystick'
     
    LSS_Phoenix_Input_USB_Joystick.cpp.o: In function USBHIDInput::USBHIDInput()
    USBHost_t36.h:505: undefined reference to vtable for USBHIDInput
    I ran into this earlier when I compiled an example with #pragma O0
    like command. So wondering if there is anywhere that some of this data persists external to this build, that the current build options do not effect?

    For getting farther along, I may try the clone the library option, but my understanding, is that this will simply put the changed files as subdirectories of my sketch and not update the official versions of these files... Of course I know I can always than try to remember to copy these updated files back to github project...

    Now back to experimenting!

  11. #11
    Yes probably better in the Visual Micro forum. You can either leave the libraries where they are and click "vMicro>Show Hidden Files". That adds short cuts for the real sources into the project explorer which makes the originals easier to edit and explore. Alternatively the clone library function allow you to make a copy of a library (optionally with version number) to either a local solution folder or a folder below the sketch/project. You can then edit the copy but at anytime right click and have the library copied/published back over the top of the version in the "Sketch Book\Libraries" folder. Any questions please open a thread in our forum and we will assist.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •