Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Pages: 1 2 
Send Topic Print
Breakpoints hitting in main sketch, but not in user library (Read 2224 times)
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Breakpoints hitting in main sketch, but not in user library
Nov 8th, 2018 at 8:01pm
 
Hello,

As the title says my breakpoints are hitting in the main sketch, but not in the (user)library (cpp).
I have added a reference to the library and it's showing in the Solution Explorer
The sketch compiles without errors and runs like it should. The sketch uses routines from the library.
The library contains a class definition.
I've set breakpoints in some of the class-routines, but they're not activated.
The class-library files are NOT in the same directory as the main sketch
The library is in a shared directory to be used by multiple people, so it cannot be created using the "Add code"-feature.


I read in the release notes that since april 2017 (version 1704.30) it is supported to debug cpp-files if they're outside the ino-directory?

I have a fresh install (2 days ago) of Visual Studio 2017 community.
I have a REGISTERED license status

Back to top
« Last Edit: Nov 8th, 2018 at 10:06pm by gj »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #1 - Nov 9th, 2018 at 1:06pm
 
Hi,

The REGISTERED status does not affect what features are active

The "Add Code" feature does not have any relation to anything other than be a quick way to add code into a normal arduino project for novice users. In all cases using the standard "Add" features work.

The location of a class lib has no effect on anything.

Can you confirm that the library is a shared library project. That it exists in the solution explorer along with the main arduino project. That the main arduino project has a "shared reference" to the lib project? You might have said this but I want to be clear about what needs to be tested.
Back to top
 
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #2 - Nov 9th, 2018 at 8:27pm
 
Does the attached screenshot give the confirmation you need?

So, breakpoints DO work in the INO but not in the CPP.
Back to top
« Last Edit: Nov 9th, 2018 at 8:36pm by gj »  

Reference.png (14 KB | )
Reference.png
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #3 - Nov 10th, 2018 at 12:18pm
 
Yes thanks I will have a look over the next few days.

Back to top
 
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #4 - Nov 11th, 2018 at 11:07am
 
I checked the code in the output-directory.
I found the file tcs3200_x.cpp and it contains this code:

Code (C++):
for (unsigned int i = 0; i < _samples; i++) {
  Serial.print(F("val:")); Serial.println(val);
  val = val + (pulseIn(_out, HIGH) / _samples);
  MicroDebug.OnBreakPointBegin(500);
  if (MicroDebug.outPacketStart(false)) {
    MicroDebug.OnBreakPointPrintBegin(1);
    MicroDebug.transport->print("|");
    MicroDebug.transport->print(val);
    MicroDebug.OnBreakPointPrintEnd();
    MicroDebug.outPacketEnd();
  }
  MicroDebug.DBG_YieldAndWait(5);
  MicroDebug.OnBreakPointEnd();
} 



In the Serial monitor I see the Serial-prints coming through so I'm certain this piece of software is run, but appararently the breakpoint is not activated.
Back to top
« Last Edit: Nov 11th, 2018 at 11:12am by gj »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #5 - Nov 11th, 2018 at 12:13pm
 
Thanks

Please open another vs ide instance but do NOT open a project. Then open the serial monitor on the port and let's see what we are actually getting.



Back to top
 
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #6 - Nov 11th, 2018 at 12:24pm
 
Is this what you want to see?

Opened Vs17 (no project), activated Serial-monitor and connected the Arduino using USB.
After a few seconds the monitor starts showing something (comparable with previous output).
Back to top
 

COM4-port.png (12 KB | )
COM4-port.png
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #7 - Nov 11th, 2018 at 12:39pm
 
if you also add a breakpoint to the main sketch code do you see that in the serial output of the clean ide instance.

In a clean ide instance you will clearly see the raw visual micro debugger serial output when it exists

+ please move you serial print to after val has been got
Back to top
« Last Edit: Nov 11th, 2018 at 12:46pm by Visual Micro »  
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #8 - Nov 11th, 2018 at 1:54pm
 
As requested, I moved the Serial.print after the val-calculation.

I put a break in the main sketch. See attachments. And they show up nicely in the expression window.
Generated code for this:
Code (C++):
Serial.print(F("Calibrating BLACK. Press a key... "));
MicroDebug.OnBreakPointBegin(500);
if (MicroDebug.outPacketStart(false)) {
  MicroDebug.OnBreakPointPrintBegin(2);
  MicroDebug.transport->print("|");
  MicroDebug.transport->print(state);
  MicroDebug.OnBreakPointPrintEnd();
  MicroDebug.outPacketEnd();
}
MicroDebug.DBG_YieldAndWait(5);MicroDebug.OnBreakPointEnd();
waitForKey();  



At this point the monitor-windows (in a clean IDE) shows this: Code:
Calibrating BLACK. Press a key... VMDPE_2:2:60826:0:7565|0_VMDPE 



So, it DOES hit at the main sketch but not the library, and does know the right value '0'.
Back to top
« Last Edit: Nov 11th, 2018 at 2:43pm by gj »  
 
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #9 - Nov 15th, 2018 at 7:49pm
 
In the meanwhile I created a new project and copy pasted the code from old to the new.
With no effect unfortunately  Sad.

Any news from your end?
@
Visual Micro

Back to top
« Last Edit: Nov 15th, 2018 at 7:49pm by gj »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #10 - Nov 15th, 2018 at 7:52pm
 
Sorry for the delay I have been tied up with life. I will do some experimenting over the next week or two.

Is the code you have shown below in a method called from the .ino code. IE, not in some c++ static class initialization that happens before the setup() in the .ino code runs?
Back to top
 
WWW  
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #11 - Nov 15th, 2018 at 7:55pm
 
Another point is that the following suggests that your print statement is not adding \r\n after Press a key... or the \r\n is being lost.

Try a delay(1) after the "Press a key...\r\n" message.

If you see this then the debugger will not know about the break point. This is breakpoint #2

Visual Micro needs the VMDPE_ to start on a new line which can then be treated as a debugger packet. This is why your own serial must be terminated by a \r\n prior to a breakpoint being hit.

Code:
Calibrating BLACK. Press a key... VMDPE_2:2:60826:0:7565|0_VMDPE 



This issue would be avoided if you use the software serial option OR use alternative serial ports where available. This would allow the debugger to unaffected by your own serial making it less important you ensure \r\n and doubles the outbound serial buffer on your hardware.
Back to top
« Last Edit: Nov 15th, 2018 at 7:58pm by Visual Micro »  
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #12 - Nov 15th, 2018 at 8:03pm
 
No problem. Having a life is important. Hope you are fine.

This is the fist part of the ino:
Code (C++):
#include <tcs3200_x.h>
typedef enum State { cal_black, cal_white, sampling };

unsigned long val;
State state;

tcs3200_x sensor(3, 4, 5, 6, 7, 8);

void setup()
{
	Serial.begin(115200);
	sensor.setFrequency(TCS_FREQ_20);

	state = cal_black;
	Serial.println(F("Setup finished."));
}

void loop()
{
	int dummy = 0;

	switch (state) {

 



I have a working(!) breakpoint at the line "int dummy = 0;"
The library-routine that is NOT hitting the breakpoint is called from loop() a few lines after this dummy-line.

The problematic routine is in tcs_3200_x.cpp (snippets shown earlier).
I know the right(?) code is generated in the output directory (that is the MicroDebug-stuff) and I know the routine is being run because I do get the Serial-print-output in that same routine.
Back to top
« Last Edit: Nov 15th, 2018 at 8:09pm by gj »  
 
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #13 - Nov 15th, 2018 at 8:17pm
 
I deliberately used a print in stead of println, because after calibration (that usually produces no output) it shows a "Done".

See snippet.
Code (C++):
		Serial.println(F("Calibrating BLACK. Press a key... "));
		delay(1);
		waitForKey();
		sensor.setCalibration(calibrateBlack);   <-- this is where the problematic routine is called
 		  Serial.println(F("Done."));
		state = cal_white;
		break;
 



Unfortunately, even with the additional \r\n (using println in stead of print) and the delay(1) there is still no putpuin the Expression window (except for the breakpoint from the main sketch).
Back to top
« Last Edit: Nov 15th, 2018 at 8:19pm by gj »  
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #14 - Nov 15th, 2018 at 8:23pm
 
I see, ignore the discussion about please wait.. it sounds like the breakpoint serial is not being sent.

But for clarity you should have put the delay after sensor.setCalibration(calibrateBlack); before your println("Done").

Which board do you have?

Back to top
 
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #15 - Nov 15th, 2018 at 8:40pm
 
Arduino Uno.
Moving the delay(1) right before printing "Done" doesn't solve the issue.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #16 - Nov 15th, 2018 at 10:52pm
 
Can you confirm the auto generated visual micro code you have posted earlier relates to the breakpoint that is not working? (Code from the .cpp file in the temp build folder)
Back to top
« Last Edit: Nov 15th, 2018 at 10:52pm by Visual Micro »  
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #17 - Nov 17th, 2018 at 10:45am
 
Yes, I can confirm that.

This code is in de temp Debug-folder in the file tcs3200_x.cpp:
Code (C++):
for (unsigned int i = 0; i < _samples; i++) {
val = val + (pulseIn(_out, HIGH) / _samples);MicroDebug.OnBreakPointBegin(500);if (MicroDebug.outPacketStart(false)) {MicroDebug.OnBreakPointPrintBegin(2);MicroDebug.transport->print("|");MicroDebug.transport->print(val);MicroDebug.OnBreakPointPrintEnd();MicroDebug.outPacketEnd();}MicroDebug.DBG_YieldAndWait(5);MicroDebug.OnBreakPointEnd();
} 



See also the attached screenshot for my own code and the breakpoint.
Back to top
« Last Edit: Nov 17th, 2018 at 10:47am by gj »  

snippet.png (11 KB | )
snippet.png
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10146
United Kingdom
Re: Breakpoints hitting in main sketch, but not in user library
Reply #18 - Nov 17th, 2018 at 4:15pm
 
Thanks, you can ignore all the tests with delay() etc. I found the problem.

The build folder has the correct .cpp code but the compiler was still using the original library source code.

Some users rely on a relative includes to folders (above/outside of) the library folder) which is not good practice in arduino terms. Therefore, a previous fix for that breaks the ability to compile a copy of the library source in a totally different location.

The workaround is a new vMicro>Debugger menu item that enables users to optionally debug in libraries. When the "allow library debugging" is enabled the cloned library sources with debug statements are compiled instead of the original. This also temporarily alters any compiler -I includes paths for the libraries.

An interim release should be published in the next few days.

Thanks for the report.
Back to top
« Last Edit: Nov 17th, 2018 at 4:54pm by Visual Micro »  
WWW  
IP Logged
 
gj
Junior Member
**
Offline


Assumption is the mother
of all f*ckups

Posts: 29
Re: Breakpoints hitting in main sketch, but not in user library
Reply #19 - Nov 17th, 2018 at 8:02pm
 
OK. Great that you found the issue.
I'm assuming the screenshot you're showing is one of an upcoming release, since I don't have that option below the vMicro menu?
Back to top
« Last Edit: Nov 17th, 2018 at 8:08pm by gj »  
 
IP Logged
 
Pages: 1 2 
Send Topic Print