Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (72 loc) · 2.26 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (72 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-License-Identifier: Apache-2.0
#include "App/Config.hpp"
#include "App/Runner.hpp"
#include "App/ShippedDefaults.hpp"
#include "Process/Interrupt.hpp"
#include <coretrace/logger.hpp>
#include <cstdlib>
#include <exception>
#include <filesystem>
#include <iostream>
namespace
{
int run(const ctrace::ProgramConfig& config, const std::filesystem::path& executable)
{
coretrace::enable_logging();
coretrace::set_prefix("== CoreTrace ==");
coretrace::set_min_level((config.output.verbose) ? coretrace::Level::Debug
: coretrace::Level::Info);
coretrace::set_source_location(false);
coretrace::set_thread_safe(false);
using ctrace::interrupt::OnInterrupt;
if (config.runtime.ipc == "serve")
{
ctrace::interrupt::install(OnInterrupt::LetToolsFinish);
return ctrace::run_server(config, executable);
}
ctrace::interrupt::install(OnInterrupt::StopTools);
return ctrace::run_cli_analysis(config);
}
} // namespace
int main(int argc, char* argv[])
{
const ctrace::ConfigResult loaded = ctrace::buildConfig(argc, argv);
if (!loaded.output.empty())
{
std::cout << loaded.output;
}
for (const std::string& warning : loaded.warnings)
{
std::cerr << "Warning: " << warning << '\n';
}
if (!loaded.error.empty())
{
std::cerr << loaded.error;
}
if (!loaded.config.has_value())
{
return loaded.exitCode;
}
// Before any thread starts: it sets CT_CLANG for the compiler library.
ctrace::useShippedClangHeaders(loaded.executable);
// Last resort: a failure nobody handled is reported, not a process abort.
try
{
const int exitCode = run(*loaded.config, loaded.executable);
if (const int signal = ctrace::interrupt::received(); signal != 0)
{
ctrace::interrupt::exitBy(signal);
}
return exitCode;
}
catch (const std::exception& error)
{
coretrace::log(coretrace::Level::Error, "{}\n", error.what());
return EXIT_FAILURE;
}
catch (...)
{
coretrace::log(coretrace::Level::Error, "Unknown fatal error.\n");
return EXIT_FAILURE;
}
}