Using GDB with Teensy without hardware debugger, first Beta

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?
 
@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?
 
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.
 
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?
 
@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".
 
@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 :)
 
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.
 
@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'
 
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".
 
@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.
 
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!
 
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.
 
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"
 
@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.
 
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?
 
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'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?p=126667&viewfull=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\\arm-none-eabi-gdb" -ex "target extended-remote \\.\COM53" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_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 :)
 
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.
 
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?p=126667&viewfull=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\\arm-none-eabi-gdb" -ex "target extended-remote \\.\COM53" "C:\Users\ADMINI~1\AppData\Local\Temp\arduino_build_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?
 
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.
 
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.
 
Coming late to the TeensyDebug party, it looks like it'll be a big help.

Unfortunately, I'm trying it out on a Teensy 3.6 first, which doesn't seem to be supported. (RAM_START and RAM_END aren't defined...)

Is this expected? Is there an easy fix?
 
@ftrias Thanks for the great work!

I have implemented it so far within Arduino 1.8.13, PlatformIO 2.1.3 and Teensy Platform 4.11.0 with a Teensy 4.1 Board with a slightliy adapted example script:

Code:
#include <Arduino.h>
#include "TeensyDebug.h"

#pragma GCC optimize ("O0")

volatile int mark = 0;

void break_me() {
  Serial1.print("BREAK at 0x");
  Serial1.println(debug.getRegister("pc"), HEX);
}

//
// Either set debugging to O0 or mark the function
// as DEBUGRUN. If you don't do this, the optimizer will
// inline the function and you won't be able to set a
// breakpoint.
//

DEBUGRUN
void test_function() {
  mark++;
}

void setup() {
  delay(3000);
  Serial1.begin(115200);
  Serial.begin(115200);
  debug.begin();
  debug.setCallback(break_me);
  //debug.setBreakpoint(test_function);
  

}

void loop() {
  test_function();
  Serial1.print("mark=");Serial1.println(mark);
 
}

The connection via GDB is possible, I`m also able to execute commands like p mark or monitor restart and so on. These parts work just fine.

The Challenge is, if I set a Breakpoint like:
Code:
(gdb) p mark
$1 = 5
(gdb) b test_function
Breakpoint 1 at 0xb0: file /Users/ftrias/Documents/Source/TeensyDebug/examples/breakpoint_test/breakpoint_test.ino, line 15.
(gdb) c
Continuing.

I got a serial print "BREAK at 0x28" via the Callback function break_me() over the Serial1 Port, but GDB is not recognizing any event and is continuing without any message.

If I want to interrupt via GDB (Ctrl C) the following message appears:

Code:
Remote debugging using COM4
0x00000000 in _stext ()
(gdb) b test_function
Breakpoint 1 at 0x28
(gdb) c
Continuing.
The target is not responding to interrupt requests.
Stop debugging it? (y or n)

Any ideas how to solve this?

Thanks in advance
 
This looks good but I can't get it working.

Using Windows 10 and a Teensy 4.1 and the "take over serial" option, I get the error "COM14: No such file or directory."

If I start GDB manually and connect instead to "//./COM14", it gets past the first stage but then says:
"Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response"

I tried breakpoint_test.ino on a Teensy 4.0 using both "dual serial" and "take over serial" and it looks like it does something as it says "0x00000000 in _stext ()" but I still get the "Ignoring packet error, continuing..." when I try to send any commands.

When compiling, I also get this warning: "Warning: Board teensy:avr:teensy32 doesn't define a 'build.board' preference. Auto-set to: AVR_TEENSY32"

Does anyone have any ideas? Thanks.
 
Just seeing this as unanswered ... not that I have one ... Did you get it working?

Not looked at this in some months, but saw it working when I did on Windows 10.

What version of TeensyDuino is in use?

Is the build being done from Arduino IDE?
 
Back
Top