1 //===-- main.cpp ------------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include <cstdlib> 10 #include <string> 11 #include <fstream> 12 #include <iostream> 13 14 int numberfn() 15 { 16 return 0x5a; 17 } 18 19 int 20 main(int argc, char const *argv[]) 21 { 22 // The program writes its output to the following file: 23 // 24 // o "output1.txt" for test_pass_host_env_vars() test case 25 // o "output2.txt" for test_run_args_and_env_vars_with_dsym() test case 26 // o "output2.txt" for test_run_args_and_env_vars_with_dwarf() test case 27 std::ofstream outfile; 28 if (argc == 1) 29 outfile.open("output1.txt"); 30 else 31 outfile.open("output2.txt"); 32 33 for (unsigned i = 0; i < argc; ++i) { 34 std::string theArg(argv[i]); 35 if (i == 1 && "A" == theArg) 36 outfile << "argv[1] matches\n"; 37 38 if (i == 2 && "B" == theArg) 39 outfile << "argv[2] matches\n"; 40 41 if (i == 3 && "C" == theArg) 42 outfile << "argv[3] matches\n"; 43 } 44 45 // For passing environment vars from the debugger to the launched process. 46 if (::getenv("MY_ENV_VAR")) { 47 std::string MY_ENV_VAR(getenv("MY_ENV_VAR")); 48 if ("YES" == MY_ENV_VAR) { 49 outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n"; 50 } 51 } 52 53 54 // For passing host environment vars to the launched process. 55 if (::getenv("MY_HOST_ENV_VAR1")) { 56 std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1")); 57 if ("VAR1" == MY_HOST_ENV_VAR1) { 58 outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n"; 59 } 60 } 61 62 if (::getenv("MY_HOST_ENV_VAR2")) { 63 std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2")); 64 if ("VAR2" == MY_HOST_ENV_VAR2) { 65 outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n"; 66 } 67 } 68 69 std::cerr << "This message should go to standard error.\n"; 70 std::cout << "This message should go to standard out.\n"; 71 72 outfile.close(); 73 return numberfn(); 74 } 75