2010-09-16 06:27:29 +08:00
|
|
|
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
2010-09-16 06:48:40 +08:00
|
|
|
#include <iostream>
|
2010-09-16 06:27:29 +08:00
|
|
|
|
2013-08-08 05:54:09 +08:00
|
|
|
int numberfn()
|
|
|
|
{
|
|
|
|
return 0x5a;
|
|
|
|
}
|
|
|
|
|
2010-09-16 06:27:29 +08:00
|
|
|
int
|
|
|
|
main(int argc, char const *argv[])
|
|
|
|
{
|
2010-12-15 07:43:29 +08:00
|
|
|
// The program writes its output to the following file:
|
|
|
|
//
|
|
|
|
// o "output1.txt" for test_pass_host_env_vars() test case
|
|
|
|
// o "output2.txt" for test_run_args_and_env_vars_with_dsym() test case
|
|
|
|
// o "output2.txt" for test_run_args_and_env_vars_with_dwarf() test case
|
|
|
|
std::ofstream outfile;
|
|
|
|
if (argc == 1)
|
|
|
|
outfile.open("output1.txt");
|
|
|
|
else
|
|
|
|
outfile.open("output2.txt");
|
2010-09-16 06:27:29 +08:00
|
|
|
|
2010-09-16 06:48:40 +08:00
|
|
|
for (unsigned i = 0; i < argc; ++i) {
|
|
|
|
std::string theArg(argv[i]);
|
|
|
|
if (i == 1 && "A" == theArg)
|
2010-09-16 06:27:29 +08:00
|
|
|
outfile << "argv[1] matches\n";
|
|
|
|
|
2010-09-16 06:48:40 +08:00
|
|
|
if (i == 2 && "B" == theArg)
|
2010-09-16 06:27:29 +08:00
|
|
|
outfile << "argv[2] matches\n";
|
|
|
|
|
2010-09-16 06:48:40 +08:00
|
|
|
if (i == 3 && "C" == theArg)
|
2010-09-16 06:27:29 +08:00
|
|
|
outfile << "argv[3] matches\n";
|
|
|
|
}
|
|
|
|
|
2010-12-04 08:44:56 +08:00
|
|
|
// For passing environment vars from the debugger to the launched process.
|
2010-09-16 06:27:29 +08:00
|
|
|
if (::getenv("MY_ENV_VAR")) {
|
|
|
|
std::string MY_ENV_VAR(getenv("MY_ENV_VAR"));
|
|
|
|
if ("YES" == MY_ENV_VAR) {
|
|
|
|
outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-04 08:44:56 +08:00
|
|
|
|
|
|
|
// For passing host environment vars to the launched process.
|
|
|
|
if (::getenv("MY_HOST_ENV_VAR1")) {
|
|
|
|
std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1"));
|
|
|
|
if ("VAR1" == MY_HOST_ENV_VAR1) {
|
|
|
|
outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (::getenv("MY_HOST_ENV_VAR2")) {
|
|
|
|
std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2"));
|
|
|
|
if ("VAR2" == MY_HOST_ENV_VAR2) {
|
|
|
|
outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-26 01:39:43 +08:00
|
|
|
std::cerr << "This message should go to standard error.\n";
|
2010-09-16 06:48:40 +08:00
|
|
|
std::cout << "This message should go to standard out.\n";
|
|
|
|
|
2010-12-15 07:43:29 +08:00
|
|
|
outfile.close();
|
2013-08-08 05:54:09 +08:00
|
|
|
return numberfn();
|
2010-09-16 06:27:29 +08:00
|
|
|
}
|