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  
 
Page Index Toggle Pages: 1
Send Topic Print
Detecting null pointers (Read 295 times)
davidbrok4
Newbies
*
Offline



Posts: 5
Detecting null pointers
Feb 3rd, 2020 at 3:13am
 
My program keeps restarting at the point where I am making a fall to a function in an object. The call looks like:

vehicle->motor->diagnostic();

The code in diagnostic never gets reached. From this I am assuming that the motor pointer is not being initialized correctly. I tested to see if (vehicle->motor == NULL) and it is not NULL. What I need is a run-time ability to step to the next line of code (single step) and inspect complex variables. Right now, I can display simple values like int, but cannot find a way to display a class or struct.

Is it possible to display a complex variable? Is it possible to single step the code into a pointer-based function call?
Back to top
« Last Edit: Feb 3rd, 2020 at 12:11pm by Visual Micro »  
 
IP Logged
 
Simon Hopkinson
Administrator
*****
Offline



Posts: 235
Re: Detecting null pointers
Reply #1 - Feb 3rd, 2020 at 11:36am
 
Option 1: Serial Debugger
This requires no additional hardware, and is built into Visual Micro.

Using the Serial Debugger with a little additional code this can also be achieved, by adding a function which will output your class information as a single string (no newlines), e.g. "myClass;var=1;Name=Simon"

This can then be called from a breakpoint to run when it is hit, and you can also add conditions to the break point so it only runs in the specific error scenario.

Option 2: Hardware Debugger
It is possible to inspect complex variables and step through your code on demand using the Hardware Debugging solutions available, along with an External Hardware Debugger (there may be one on board depending on the model of board in use).

All pre-configured debugging options are listed on the Hardware Debugger Listing page.

Below is a simple example of a struct and class being inspected on an ESP32 WROVER board at runtime, to show how it allows expansion of the class instance being inspected:
...


Back to top
« Last Edit: Feb 3rd, 2020 at 12:40pm by Simon Hopkinson »  
 
IP Logged
 
Bambo
Junior Member
**
Offline



Posts: 94
Liverpool, UK
Re: Detecting null pointers
Reply #2 - Feb 6th, 2020 at 9:00pm
 
It could be a lot of different things, how have you implemented vehicle and motor? as classes? virtual classes or?

Back to top
 

Richard Bamford
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print