Forum Rule: Always post complete source code & details to reproduce any issue!
Page 3 of 3 FirstFirst 1 2 3
Results 51 to 71 of 71

Thread: Using GDB with Teensy without hardware debugger, first Beta

  1. #51
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    Quote Originally Posted by AndyCap View Post
    Hi Guys,

    Has anyone managed to get "Take over serial" to work?

    In GDB I see:
    Code:
    [no_device]: No such file or directory.
    I cannot see the serial device available either.

    The only way to get flashing working after this is to close the teensy flashing app, next time it reloads flashing works again.

    I have Dual Serial working fine but am using the audio/midi usb and only have one serial.

    Thanks

    Andy
    Take over Serial is a bit tricky. It works by using a "#define" to redirect "Serial" to "debug" in TeensyDebug.h. The "debug" object will format data so that GDB will print it. If any of your sketches use the Serial device, they have to do this or include "TeensyDebug.h", which does this (line 66). If they don't, then they'll send extraneous data to GDB and it will fail. Are you using Mac, Linux or Windows?

  2. #52
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    Quote Originally Posted by KurtE View Post
    @ftrias - Thanks again, Just starting to play again. Also trying to get it to work with the VisualMicro.
    I will ask more on their thread or forum... Like how to setup to use with libraries (again). Although a lot of what I am debugging is in my set of Arduino sketch tabs.

    A couple of notes: Took me awhile to find again how to connect to the sketch: target remote \\.\COM32

    But am able to breakpoint in servo library which is great...

    It is also interesting if I use the: #pragma GCC optimize ("O0")
    The sketch will NOT build with USBHost code as the link will fail as not finding VTables for some of the base classes.

    Also note: I am getting several compiler warnings: (T4.1) 1.8.13 ...

    But this will be very helpful, so again THANKS
    Thanks for the heads up about the warnings. I'll fix that.

    I suppose "O0" is not really needed. I just put it in so that the compiler won't optimize away functions and lines in my trivial examples.The "Og" supplied by the compile line should suffice. Perhaps it's confusing and I should take it out?

  3. #53
    Quote Originally Posted by ftrias View Post
    Take over Serial is a bit tricky. It works by using a "#define" to redirect "Serial" to "debug" in TeensyDebug.h. The "debug" object will format data so that GDB will print it. If any of your sketches use the Serial device, they have to do this or include "TeensyDebug.h", which does this (line 66). If they don't, then they'll send extraneous data to GDB and it will fail. Are you using Mac, Linux or Windows?
    Hi, thanks for the info.

    I'm on a mac, I managed to get it going with single serial by just including your debug files and building in PlatformIO.

    Also managed to get the VSCode debugger talking to it, stepping seems a little hit and miss though.

    I'm going to get one of my USB->Serial leads set up and use that for gdb and keep the normal serial for debug output.

    Nice job though, thanks very much for this.

  4. #54
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,459
    Quote Originally Posted by ftrias View Post
    Run the install program with the -i option as in: teensy_debug -i=c:\Arduino-1.8.12
    @ftrias
    Ok since I also install via the zip file, so I ran the following from the command prompt ffter I downloaded and put all files in the Arduino Libraries folder.:
    Code:
    teensy_debug -i=f:\Arduino-1.8.13
    But I keep getting this message:
    Code:
    D:\Users\Merli\Documents\Arduino\libraries\TeensyDebug>teensy_debug -i=f:\Arduino-1.8.13
    Install GDB in Teensyduino
    Teensyduino not found in f:\Arduino-1.8.13
    Where is Arduino installed?
    ?
    Any ideas?

  5. #55
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    Quote Originally Posted by mjs513 View Post
    @ftrias
    Ok since I also install via the zip file, so I ran the following from the command prompt ffter I downloaded and put all files in the Arduino Libraries folder.:
    Code:
    teensy_debug -i=f:\Arduino-1.8.13
    But I keep getting this message:
    Code:
    D:\Users\Merli\Documents\Arduino\libraries\TeensyDebug>teensy_debug -i=f:\Arduino-1.8.13
    Install GDB in Teensyduino
    Teensyduino not found in f:\Arduino-1.8.13
    Where is Arduino installed?
    ?
    Any ideas?
    The installer is looking for a directory "hardware/teensy" inside your Arduino directory. If it's not there, it complains.

    Since you have a non-standard install, it's probably best to just set up manually. Look at the README.md file and follow the steps in "Installing overview".

  6. #56
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,459
    @ftrias
    Sorry for the delay in responding - keep getting sidetracked.

    Anyway I followed these instructions in the readme:
    1. Create a directory named TeensyDebug in your library and copy source files there.
    2. Customize IDE by copying customized `boards.local.txt` and `platform.local.txt` to `hardware/teensy/avr` directory. These files create the menu options and cause `teensy_debug` to be used to upload the program and run GDB.
    3. Copy the `teensy_debug` for your platform to the `hardware/tools` directory.
    Just for clarity the teensy_debug file I copy to 'hardware/tools' is teensy_debug.py or teensy_debug.exe. The exe seems just to be for the installer? Ok so here we go.

    I open up the IDE and the GDP menu appears, so far so good. I load up any of the example sketches and keep getting a bunch of warnings which dont seem to be an issue but I get one error that prevents the sketch from loading:
    Code:
    java.io.IOException: Cannot run program "F:\arduino-1.8.13\hardware\teensy/../tools/teensy_debug": CreateProcess error=2, The system cannot find the file specified
    So what am i messing up

  7. #57
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,931
    FYI: When I tried the installer it was older - but the adds to boards and platforms seemed to mess up TSET usage as the new menu options were not set - I assumed and didn't look for what they were to provide them.

    So only efforts to use were from TSET and SublimeTest Editor build with unchanged IDE build files - and it worked fine with the library added.

    Also when using TyCommander wondering if edits for that might cause grief?

    Not using either TSET or TyCommander just now - with fresh IDE 1.8.13 and TD 1.53b2 so I could try at some point if it would help.

  8. #58
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,931
    Quote Originally Posted by mjs513 View Post
    @ftrias
    Sorry for the delay in responding - keep getting sidetracked.

    Anyway I followed these instructions in the readme:


    Just for clarity the teensy_debug file I copy to 'hardware/tools' is teensy_debug.py or teensy_debug.exe. The exe seems just to be for the installer? Ok so here we go.

    I open up the IDE and the GDP menu appears, so far so good. I load up any of the example sketches and keep getting a bunch of warnings which dont seem to be an issue but I get one error that prevents the sketch from loading:
    Code:
    java.io.IOException: Cannot run program "F:\arduino-1.8.13\hardware\teensy/../tools/teensy_debug": CreateProcess error=2, The system cannot find the file specified
    So what am i messing up
    Staring at the 'error=2' line now - assuming Windows looking to run a known file type for "teensy_debug" and teensy_debug.py doesn't count?

    I just went to the folder CMD line and ran : T:\tCode\libraries\TeensyDebug>teensy_debug.py
    >> It opened the file in SublimeText to edit.

    So on this system Python not on path and *.py is marked 'opens with sublimetext'

  9. #59
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    Quote Originally Posted by mjs513 View Post
    Code:
    java.io.IOException: Cannot run program "F:\arduino-1.8.13\hardware\teensy/../tools/teensy_debug": CreateProcess error=2, The system cannot find the file specified
    So what am i messing up
    I presume this is Windows? Is the file teensy_debug.exe in the right location? I wonder if the mixed use of "/" and "\" might be a problem? In any case, all teensy_debug does is try to figure out what serial port to use and call up gdb in a separate window. You can do that manually as well as described in the README.md section "Running GDB manually".

  10. #60
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    5,459
    @ftrias and @defragster

    Ok got it working. Just had the wrong file in the hardware/tools. Wasn't expecting another a GDB cmd window to pop open either, probably should read the readme better.

  11. #61
    Hi, I have a few tips that may save others a few hours

    1. If using hardware serial and you want > 9600 baud you need to use begin():

    Code:
      Serial1.begin(115200);
      debug.begin(Serial1);
    and pass the baud rate to gdb:
    Code:
    /Development/Linux/gcc-arm-none-eabi-7-2017-q4-major/bin/arm-none-eabi-gdb firmware.elf -ex="target remote /dev/cu.usbserial" --baud=115200

    2. Using the VScode debugger, you can use the following launch.json to use the debugger interface in VSCode/PlatformIO:
    Code:
    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Launch",
          "type": "cppdbg",
          "request": "launch",
          "miDebuggerPath": "/Applications/Arduino.app//Contents/Java/hardware/tools/arm/bin/arm-none-eabi-gdb",
          "miDebuggerArgs": "--baud=115200",
          "MIMode": "gdb",
          "targetArchitecture": "arm",
          "program": "firmware.elf",
          "launchCompleteCommand": "None",
          "filterStderr": false,
          "filterStdout": false,
          "externalConsole": false,
          "cwd": "${workspaceRoot}",
          "setupCommands": [
            {"text": "set target-async off"},
            {"text": "target extended-remote /dev/cu.usbserial"},   
            ]
        }
      ]
    }
    You cannot set breakpoints while the code is running, also the break will not work.

    In order to break from a terminal:
    Code:
    killall -2 arm-none-eabi-gdb
    This will cause a break in the VSCode debugger interface. Target-async needs to be off for this to work.

    Edit: this is for OSX, linux users would have no problems converting, who knows about windows!

  12. #62
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    7,098
    It should also be noted (maybe by design) that if you try to allow it to Take Over Serial, the code will not compile, if your code does things like:
    Serial.read().... At least when I tried it as it said the class debug does not have a read method.

  13. #63
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    456
    For linux users who want to do things manually, this quick "gdb.sh" script works for me and is convenient:

    Code:
    #!/bin/bash
    
    # find port
    port=`ls /dev/ttyACM* | tail -1`
    
    # find latest build
    elf=`ls -tr /tmp | grep arduino_build | tail -1`
    
    gdb-multiarch /tmp/$elf/*.elf -ex "target remote $port"

  14. #64
    Junior Member
    Join Date
    Apr 2018
    Posts
    16
    @AndyCap

    thank you for the Vscode tips.

    Looks there needs to be a little bit more "packaging" to get a clean version of this debugging feature. I think this definitely makes the overall system much much better than a simple arduino, and getting Vscode/Platformio to handle all this give a much more advanced tool to work with SW.

    So far, I understood only Teensy 4s are benefiting from this, correct?

    Hobi.

  15. #65
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,931
    Working on another forum post with ADC I get one cycle through loop() then it dies? Perfect chance for using GDB - EXCEPT::
    Code:
    Reading symbols from T:\TEMP\\arduino_build_readAllPins_10Dual.ino\readAllPins_10Dual.ino.elf...done.
    (gdb) target remote \\.\COM4
    Remote debugging using \\.\COM4
    operator delete[] (ptr=<optimized out>) at T:\arduino-1.8.13\hardware\teensy\avr\cores\teensy4\new.cpp:55
    55              free(ptr);
    (gdb) l
    50              free(ptr);
    51      }
    52
    53      void operator delete[](void * ptr, size_t size)
    54      {
    55              free(ptr);
    56      }
    57
    (gdb)
    Not sure why it is staring like that? Code still dies - and not breaking into FAULT or debugger ...


    @hobi - yes - T_4.x's came first and best for support - Now looks to have added T_3.2's?

  16. #66
    I've installed this tool following all instructions, but i really don't understand how to use this. I get a menu option USB type dual, and I get a cmd window upon upload, so I guess it's installed. I've looked at the examples, but i'm stuck in figuring out how to use this.

    Compile warnings
    Warning: Board teensy:avr:teensy32 doesn't define a 'build.board' preference. Auto-set to: AVR_TEENSY32
    sketch_jun30a:44: error: no matching function for call to 'Debug::setBreakpoint(void (&)(), int)'
    debug.setBreakpoint(testme, 1);
    no matching function for call to 'Debug::setBreakpoint(void (&)(), int)'

    A few screen shots would do wonders here.

    Can the OP help me out?

  17. #67
    I'm now trying this on Win7

    and here's my compile error (witth Serial window up at compile time).

    Now able to open COM50 (Windows said this port was ready before it was actually ready...)Disconnect COM50

    If I close serial window it seems to compile w/o errors, but If I open the Serial window... Unable to open COM50

    I compile with Dual USB, GDB: Use Dual USB, get these errors.
    Unable to open COM52
    Unable to open COM52 for reboot request
    Windows Error Info: Access is denied.
    more ideas... https://forum.pjrc.com/threads/40632...l=1#post126667
    Teensy did not respond to a USB-based request to enter program mode.
    Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
    RUN: "C:\Program Files (x86)\Arduino\hardware\teensy\..\tools\arm\bin\\ar m-none-eabi-gdb" -ex "target extended-remote \\.\COM53" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_buil d_716538\breakpoint_test.ino.elf"


    When I hear "debugger" i think of the stuff in Visual Studio. Can anyone post a screenshot? I think my expectations are wrong

  18. #68
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,931
    This link into the header file on github shows a single param for setBreakPoint( func );

    If any SerMon has the COM port attached that is expected to be used to program - that will prevent upload and result in an error.

    If that is GDB window it needs to be closed first - or you'd end up with a confusing two.

    If it is IDE SerMon it should close automatically for upload - if other Serial Monitor on the port - ... normally the solution is do a 'Verify' build then press button - but that wouldn't kick of the GDB as part of the upload path ... so solution is to make sure that Com port for upload is not in use when starting the Build to Upload.

    Have not done the IDE integration here - as noted prior I have it working with TSET that fires off the IDE build with command line magic - then spawns GDB when specified.

  19. #69
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    Quote Originally Posted by KrisKasprzak View Post
    I'm now trying this on Win7

    and here's my compile error (witth Serial window up at compile time).

    Now able to open COM50 (Windows said this port was ready before it was actually ready...)Disconnect COM50

    If I close serial window it seems to compile w/o errors, but If I open the Serial window... Unable to open COM50

    I compile with Dual USB, GDB: Use Dual USB, get these errors.
    Unable to open COM52
    Unable to open COM52 for reboot request
    Windows Error Info: Access is denied.
    more ideas... https://forum.pjrc.com/threads/40632...l=1#post126667
    Teensy did not respond to a USB-based request to enter program mode.
    Please press the PROGRAM MODE BUTTON on your Teensy to upload your sketch.
    RUN: "C:\Program Files (x86)\Arduino\hardware\teensy\..\tools\arm\bin\\ar m-none-eabi-gdb" -ex "target extended-remote \\.\COM53" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_buil d_716538\breakpoint_test.ino.elf"


    When I hear "debugger" i think of the stuff in Visual Studio. Can anyone post a screenshot? I think my expectations are wrong
    I'm guessing you've got the USB Serial names reversed. Arduino thinks COM52 is the first serial port. Did you try changing the Port from the menu?

  20. #70
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    Quote Originally Posted by KrisKasprzak View Post
    I've installed this tool following all instructions, but i really don't understand how to use this. I get a menu option USB type dual, and I get a cmd window upon upload, so I guess it's installed. I've looked at the examples, but i'm stuck in figuring out how to use this.

    Compile warnings
    Warning: Board teensy:avr:teensy32 doesn't define a 'build.board' preference. Auto-set to: AVR_TEENSY32
    sketch_jun30a:44: error: no matching function for call to 'Debug::setBreakpoint(void (&)(), int)'
    debug.setBreakpoint(testme, 1);
    no matching function for call to 'Debug::setBreakpoint(void (&)(), int)'

    A few screen shots would do wonders here.

    Can the OP help me out?
    I changed the API for setBreakpoint and removed the numbrer. Just call:

    Code:
    debug.setBreakpoint(testme)
    The code was in a comment in the examples so I missed it.

    The first Warning is not a problem. I'll have to do more research to eliminate it.

  21. #71
    Senior Member
    Join Date
    Sep 2013
    Location
    Boston, MA
    Posts
    161
    Quote Originally Posted by defragster View Post
    Working on another forum post with ADC I get one cycle through loop() then it dies? Perfect chance for using GDB - EXCEPT::
    Code:
    Reading symbols from T:\TEMP\\arduino_build_readAllPins_10Dual.ino\readAllPins_10Dual.ino.elf...done.
    (gdb) target remote \\.\COM4
    Remote debugging using \\.\COM4
    operator delete[] (ptr=<optimized out>) at T:\arduino-1.8.13\hardware\teensy\avr\cores\teensy4\new.cpp:55
    55              free(ptr);
    (gdb) l
    50              free(ptr);
    51      }
    52
    53      void operator delete[](void * ptr, size_t size)
    54      {
    55              free(ptr);
    56      }
    57
    (gdb)
    Not sure why it is staring like that? Code still dies - and not breaking into FAULT or debugger ...


    @hobi - yes - T_4.x's came first and best for support - Now looks to have added T_3.2's?
    1. The library, as currently written, doesn't halt the Teensy on startup. So your "starting" point is not reliable. Right now, you have to either use "halt()" in your code or place a breakpoint and do a continue "c". Do you think maybe it should just halt on startup? I think that mirrors what gdb does with desktop apps.

    2. I did add some T3 support, but it's just trickier. Stepping is even less reliable on the T3.

Tags for this Thread

Posting Permissions

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