blob: f36a3c07b96d0009fccd3a8c0825646eb9c84042 [file] [log] [blame]
Ben Tyner0205f3b2020-02-24 10:24:47 -06001#include <libpdbg.h>
2
3#include <analyzer/analyzer_main.hpp>
4#include <attn/attn_main.hpp>
5
6#include <algorithm>
Ben Tyner9ae5ca42020-02-28 13:13:50 -06007#include <string>
Ben Tyner0205f3b2020-02-24 10:24:47 -06008
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 */
18bool 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 */
32char* 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 */
58int 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}