1 #include <libpdbg.h> 2 3 #include <analyzer/analyzer_main.hpp> 4 #include <attn/attn_main.hpp> 5 6 #include <algorithm> 7 #include <string> 8 9 /* 10 * @brief Search the command line arguments for an option 11 * 12 * @param i_begin command line args vector begin 13 * @param i_end command line args vector end 14 * @param i_option configuration option to look for 15 * 16 * @return true = option found on command line 17 */ 18 bool getCliOption(char** i_begin, char** i_end, const std::string& i_option) 19 { 20 return (i_end != std::find(i_begin, i_end, i_option)); 21 } 22 23 /* 24 * @brief Search the command line arguments for a setting value 25 * 26 * @param i_begin command line args vector begin 27 * @param i_end command line args vectory end 28 * @param i_setting configuration setting to look for 29 * 30 * @return value of the setting or 0 if setting not found or value not given 31 */ 32 char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting) 33 { 34 char** value = std::find(i_begin, i_end, i_setting); 35 if (value != i_end && ++value != i_end) 36 { 37 return *value; 38 } 39 return 0; // nullptr 40 } 41 42 /** 43 * @brief Attention handler application main() 44 * 45 * This is the main interface to the hardware diagnostics application. This 46 * application will either be loaded as a daemon for monitoring the attention 47 * gpio or it will be loaded as an application to analyze hardware and 48 * diagnose hadrware error conditions. 49 * 50 * Command line arguments: 51 * 52 * analyze analyze hardware 53 * --daemon load application as a daemon 54 * --breakpoints enable breakpoint special attn handling (in daemon mode) 55 * 56 * @return 0 = success 57 */ 58 int main(int argc, char* argv[]) 59 { 60 int rc = 0; // return code 61 62 // initialize pdbg targets 63 pdbg_targets_init(nullptr); 64 65 // TODO Handle target init fail 66 67 // check if we are being loaded as a daemon 68 if (true == getCliOption(argv, argv + argc, "--daemon")) 69 { 70 // Check command line args for breakpoint handling enable option 71 bool bp_enable = getCliOption(argv, argv + argc, "--breakpoints"); 72 73 // Configure and start attention monitor 74 attn::attnDaemon(bp_enable); 75 } 76 // We are being loaded as an application, so parse the command line 77 // arguments to determine what operation is being requested. 78 else 79 { 80 // Request to analyze the hardware for error conditions 81 if (true == getCliOption(argv, argv + argc, "analyze")) 82 { 83 analyzer::analyzeHardware(); 84 } 85 } 86 87 return rc; 88 } 89