Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) Breakpoints in .cpp files don't work (Read 8486 times)
Andreas E
Junior Member
**
Offline


Posts: 29
Joined: Mar 7th, 2017
Breakpoints in .cpp files don't work
Apr 29th, 2017 at 10:35am
Print Post  
Hi, 
I'm using VS17 and the Arduino 1.6/1.8 selection for ESP8266 boards. I've a solution with 3 projects. Also, there's one .ino file and several .h, .cpp, .inc used.

Setting the breakpoint in the .ino file works fine. But setting a breakpoint in a .cpp file does not. The code is executed (i put the brakpoint in the Serial.println line, in the console I see the output, but only the .ino breakpoints are shown and not the .cpp breakpoint.
Also, compiling and linking is fine without any problems.

Any idea?

Thanks
Andreas
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints in .cpp files don't work
Reply #1 - Apr 29th, 2017 at 12:37pm
Print Post  
Hi,

I just tested breakpoints in .cpp and they worked okay so I need a bit more info to understand what is happening.

Can you switch on vmicro>compiler>show build folder, then perform a debug build. The "Micro Build" output window will contain the location of the temp build folder. Please zip and email the .cpp you added the breakpoint to from the temp build folder. 

Also please explain where the .cpp is located? In project root or in a sub folder structure below?

Finally worth noting that placing breakpoints on serial print is a useful test/report but can cause some packet confusion especially if your serial.print is not a serial.println()

  
Back to top
WWW  
IP Logged
 
Andreas E
Junior Member
**
Offline


Posts: 29
Joined: Mar 7th, 2017
Re: Breakpoints in .cpp files don't work
Reply #2 - Apr 29th, 2017 at 2:49pm
Print Post  
Hi, 
I can confirm that breakpoints in general work. I set up a new solution with one project, that's fine.

But as soon as there are more than one projects in the solution, it's in my case not working anymore.

What I did:
- new Solution "sol"
- initial project "prj1" (prj1.ino, testclass.h and testclass.cpp)
- breakpoints in prj1.ino and testclass.cpp -> works fine

Add a new project "prj2" (prj2.ino) to the solution in VS17, creating a new directory for this project. Add the existing files (testclass.h and test.cpp) to this new prj2 (still we're in the same solution in VC2017).

Adding breakpoints in prj2.ino works, but the breakpoints in testclass.cpp are ignored.

With the hint you gave me ("temp build folder"), I checked the testclass.cpp file, and some statements had been added. But this information is not shown in the debug log from Visual Micro in VS17.

Maybe I did something wrong with the VS17 usage and setup of the projects?

Anyway, I prepared the files you requested from my original question, and I can add the temp VS17 solution/directory tree for testing, too. Please provide your email address that I can send it to you.

Regards
Andreas
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints in .cpp files don't work
Reply #3 - Apr 29th, 2017 at 2:55pm
Print Post  
Thanks very much. Email is info[at]visualmicro.com
  
Back to top
WWW  
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints in .cpp files don't work
Reply #4 - Apr 29th, 2017 at 3:37pm
Print Post  
Thanks for sending your project.

I think the issue is that in sketch2 you have made a short cut to the file that exists in the breakpoint project. If you open the F4 properties and click on each of the two .cpp files you will see the "relative path" property shows this clearly.

I will look into why debug doesn't work for linked/shared source code and try to fix for the next release.

Thanks
« Last Edit: Apr 29th, 2017 at 3:43pm by Tim@Visual Micro »  
Back to top
WWW  
IP Logged
 
Andreas E
Junior Member
**
Offline


Posts: 29
Joined: Mar 7th, 2017
Re: Breakpoints in .cpp files don't work
Reply #5 - Apr 29th, 2017 at 4:29pm
Print Post  
Thanks for your support.
Regards Andreas
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints in .cpp files don't work
Reply #6 - Apr 29th, 2017 at 4:57pm
Print Post  
Out of interest, did you actually mean to have the same source code files in both projects?

In your tests I think you worked with two different source files of the same name in two different projects but in your real project you have the same source code files in two different projects. 

So I am just checking that you are clear about your config?

  
Back to top
WWW  
IP Logged
 
Andreas E
Junior Member
**
Offline


Posts: 29
Joined: Mar 7th, 2017
Re: Breakpoints in .cpp files don't work
Reply #7 - Apr 30th, 2017 at 5:34am
Print Post  
I organized the files on the disk like this (in the small test solution as well as in my original code):

1st step:

solution/breakpointtest/
solution/breakpointtest/breakpointtest.ino
solution/breakpointtest/classtest.h
solution/breakpointtest/classtest.cpp

Code refactoring got difficult, so in the 2nd step I added a test program to be used with the code in classtest.*

2nd step:
solution/breakpointtest/
solution/breakpointtest/breakpointtest.ino
solution/breakpointtest/classtest.h
solution/breakpointtest/classtest.cpp
solution/example/
solution/example/sketch2/sketch2.ino

(this shows where the source files reside on the disk.)

Inside VS17 I put a solution, a project for the first step (breakpointtest.ino, classtest.cpp and .h). Then I added a second project with the new file sketch2.ino, and also i used in VS17 the function "add existing file to project" (Shift-Alt-A). Thus, the same physical files classtest.* are used in both projects. You can see in Sketch2.vcxproj, too.
Code
Select All
<ItemGroup>
    <None Include="Sketch2.ino">
      <FileType>CppCode</FileType>
    </None>
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\..\breakpointtest\classtest.h" />
    <ClInclude Include="__vm\.Sketch2.vsarduino.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="..\..\breakpointtest\classtest.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
 



I'm not sure if this is the best way to organize in VS, so I'm open for ideas. 

Regards
Andreas
« Last Edit: Apr 30th, 2017 at 6:25am by Andreas E »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints in .cpp files don't work
Reply #8 - Apr 30th, 2017 at 3:09pm
Print Post  
Thanks, yes it makes sense but here are a few tips

As you say, using shared (existing) code links does not provide debugging and might never do. 

However he is a slightly better way to work that you might find easier anyway. There is the facility to create shared project code in visual studio. File>new>c++>general>shared project. This will cteate a special/simple type of project in a location you choose. The project does not build on its own, instead you simply right click the References node in an arduino projects and then click "Add reference>shared project". That then gives you a tidy way to group shared code and also gives debug facility.

A shared project is merged into the temp build folder and compiled with the arduino project code just as if you had included the code directly in the arduino project. The folder structure of a shared project is adhered too which is not the case for linked sources which are always copied into the project root in the temporary build folder.

The latest release of Visual Micro (few hours ago) makes creating shared projects or new libraries much more obvious and easier.

You can end with something like this

solution

> Shared Project A: solution/shared_stuff
   > solution/shared_stuff/bar.h
   > solution/shared_stuff/bar.cpp
   > solution/shared_stuff/src/foo2.cpp
   > solution/shared_stuff/src/foo2.h

> Arduino Project A: solution/breakpointtest/
   > solution/breakpointtest/breakpointtest.ino

> Arduino Project B: solution/example
   > solution/example/sketch2/sketch2.ino
   > solution/example/sketch2/src/foo.h

Important notes about maintaining Arduino compatibility.

In the above example foo.h could "#include "foo2.h" and foo2.h could include foo.h. During compilation they will both be in the same folder! foo.h would have to step up one folder to access bar.h #include "../bar.h"

The Arduino IDE supports the project root and the \src sub folder and any sub folders below it.

When working with more than one arduino project in a solution that also has shared projects. The intellisense in the shared project code will be based on the "Startup Project". That's the project that shows in bold in the solution explorer. Right click an Arduino project to "set as Startup Project"

Adding a reference to a shared project from an Arduino project automatically makes all code from the shared project available to the Arduino project.

It is not recommended to add linked (existing) sources to a shared project.

NOTE: Unless using GDB debug, you can not debug a Library Project yet. You can only debug Shared Code Projects and Arduino Projects



« Last Edit: Apr 30th, 2017 at 3:29pm by Tim@Visual Micro »  

Please Register or Login to the Forum to see File Attachments
Back to top
WWW  
IP Logged
 
Andreas E
Junior Member
**
Offline


Posts: 29
Joined: Mar 7th, 2017
Re: Breakpoints in .cpp files don't work
Reply #9 - May 1st, 2017 at 11:00am
Print Post  
Tim, thanks for providing the new version. I can confirm that breakpoints now work as expected in my setup, and they stop within the new "shared code" project, too. Great!

One small "comfort feature" would be nice. For example in the following situation. There is a project in the directory from the discussion above, solution/breakpointtest/breakpointtest.ino. breakpointtest.ino includes a shared header bar.h, and bar.h itself includes bar2.h from the solution/breakpointtest directory. This could be some user configuration stuff.
Compiling is fine, no problems. But in VS17, from breakpointtest.ino open the header file with right click/open -> works. But open the header file bar2.h with right click/open will not open breakpointtest/bar2.h (as expected and as used for compilation), but the existing file in the esp core tree.
I'd expect to open the existing bar2.h from the solution.

Anyway, thanks for the solution provided,

Regards Andreas


« Last Edit: May 1st, 2017 at 11:21am by Andreas E »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints in .cpp files don't work
Reply #10 - May 1st, 2017 at 11:48am
Print Post  
Hi,

I think you need to give more info. 

You are talking about how visual studio works with shared c++ projects and not visual micro. Normally Vs works okay for accessing files and I am debugging shared projects okay.

So that two strange things and might be something missing from the docs.

Please zip your project/solution/code and email so I can see what you have.

Thanks

  
Back to top
WWW  
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12076
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Breakpoints in .cpp files don't work
Reply #11 - May 2nd, 2017 at 7:48pm
Print Post  
I think I have worked out what you are doing and why debug doesn't work for shared projects.

Apologies if this is wrong but the following is possible after reading your previous answers ...

You must not use "Add Existing Item" to add sources to any of your projects. You do not need that feature and I think you might be using it because you are missing a small point.

As I explained previously "Add Existing Item" adds a link to source code that is not deemed a real part of the project code.

I suspect you do not know about the Visual Studio command "Project>Show all files". The command is also available as a small icon on the solution explorer tool bar.

When you have "Show all files" selected you will be able to see a physical file and folder view in the solution explorer. In the view will be the source code you have placed in the respective project folder(s). Some of the source code will have colored icons and some will not. The source that does not is NOT included in the project. You can right click the sources and click "Include in Project".

Using "Include in Project" instead of "Add Existing Item" has major differences. "Include in Project" makes the sources code a part of the project. When you un-select "Show all files" you will see that the sources are included in the solution explorer view as you would have expected.

If I am right this means you need to cleanup your projects by right click source code and clicking "Remove" (not delete). After you have removed linked sources you can follow the previous guide to "Include in project" the required source code files.

If you are unsure which files have been linked instead of properly included you can click a source code in the Solution Explorer and then press F4. F4 will show you the properties of the source code, the RelativePath property might be "foo.h" or "..\something\foo.h or "..\foo.h. Only "foo.h" is a real included file, anything that starts with "../" is a linked source code file.

I hope this makes sense, it's a bit strange for people new to Visual Studio but it is how it works so important so it is important to understand clearly.



  
Back to top
WWW  
IP Logged
 
Andreas E
Junior Member
**
Offline


Posts: 29
Joined: Mar 7th, 2017
Re: Breakpoints in .cpp files don't work
Reply #12 - May 3rd, 2017 at 7:06am
Print Post  
Hi Tim, thanks for your detailed reply, very good for the understanding of VS. Actually, I did it exactly as you wrote.

I did a couple of tests and experienced that (at least during restructuring of the projects in VS/VM) it is crucial to "make clean" the solution and rebuild. After that, the strange syntax highlighting, openening other files than the files I expected, ... disappeared. Debugging is fine, too. 

I'll need some more time to further work on my solution and to better understand VS handling.

Thanks
Andreas
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint