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