Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)

Local debugger environment problem

Alexander_M_2
Beginner
688 Views

I am trying to run Amplifier from MSVS with included Inheritance of the project properties.

My sample is quite easy:

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
  // Variable 1.
  string anEnv1 = getenv("ENV1");
  if (anEnv1.size() != 0)
    cout << anEnv1 << endl;
  else
    cout << "ENV1 read problem" << endl;

  // Variable 2.
  string anEnv2 = getenv("ENV2");
  if (anEnv2.size() != 0)
    cout << anEnv2 << endl;
  else
    cout << "ENV2 read problem" << endl;
}

I set these variables in "Project->properties->debugging->Environment" via visual studio. So this example works in standalone mode. When I try to use Amplifier behaviour is incorrect.

Physically this variables are stored in vcproj.user file which can be obtained after cmake execution. Here are this lines:

    <LocalDebuggerEnvironment>ENV1=D:/ENV1DIR
ENV2=D:/ENV2DIR
$(LocalDebuggerEnvironment)</LocalDebuggerEnvironment>

I can provide full sample in case of necessity.

0 Kudos
6 Replies
David_A_Intel1
Employee
688 Views

Hi Alexander:

I can't even get it to work without VTune Amplifier!  When I attempt to run your sample under the debugger, I receive a debug assertion because getenv() returns a null pointer.

envAssert.PNG

I've set my debugger environment as follows:

envStrings.PNG

I've tried with and without semi-colons - no difference in behavior.  If I replace "ENV1" with "TEMP", then I am able to retrieve the system variable.  What am I missing? :\

0 Kudos
Alexander_M_2
Beginner
688 Views

Hello MrAnderson!

 

Why there are 4 variables?

On my original case inheritance lead to situation when one of the variables became unavailable and application profiling crash.

0 Kudos
Alexander_M_2
Beginner
688 Views

FYI:

Original problem is observed on MSVS2010+Amplifier XE 2013 (Update 16). Attached screenshots are obtained on MSVS2013+Amplifier XE 2013 (Update 16)
 

0 Kudos
David_A_Intel1
Employee
688 Views

Okay, thank you.  I am seeing some strange behavior, as well, and have reported this to the development team.

The workaround for you would be to define these variables in the environment that you start Visual Studio from.  For example, if you open a command prompt, set the variables, start devenv, then VTune Amplifier as well as your app will inherit those variables from the command prompt.

0 Kudos
Alexander_M_2
Beginner
688 Views

Hi MrAnderson,

I've used this workaround and confirm that it is work.

0 Kudos
David_A_Intel1
Employee
688 Views

Hi Alexander:

I have an update.  This is something peculiar about the Visual Studio* project settings.  When you open the project settings, you need to make sure the "Configuration" where you are defining the variables *matches* the one that you are executing:

evnvStringsSolution.PNG

Once I changed "Release" to "Active(Debug)" and set the variables, everything worked!!

This oddity of Visual Studio has bitten me before. :(  Hope that helps.

0 Kudos
Reply