Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/tools/lldb-server/lldb-server.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- lldb-server.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 "SystemInitializerLLGS.h"
10
#include "lldb/Initialization/SystemLifetimeManager.h"
11
#include "lldb/Version/Version.h"
12
13
#include "llvm/ADT/STLExtras.h"
14
#include "llvm/ADT/StringRef.h"
15
#include "llvm/Support/InitLLVM.h"
16
#include "llvm/Support/ManagedStatic.h"
17
#include "llvm/Support/PrettyStackTrace.h"
18
#include "llvm/Support/Signals.h"
19
20
#include <cstdio>
21
#include <cstdlib>
22
23
static llvm::ManagedStatic<lldb_private::SystemLifetimeManager>
24
    g_debugger_lifetime;
25
26
0
static void display_usage(const char *progname) {
27
0
  fprintf(stderr, "Usage:\n"
28
0
                  "  %s v[ersion]\n"
29
0
                  "  %s g[dbserver] [options]\n"
30
0
                  "  %s p[latform] [options]\n"
31
0
                  "Invoke subcommand for additional help\n",
32
0
          progname, progname, progname);
33
0
  exit(0);
34
0
}
35
36
// Forward declarations of subcommand main methods.
37
int main_gdbserver(int argc, char *argv[]);
38
int main_platform(int argc, char *argv[]);
39
40
namespace llgs {
41
5
static void initialize() {
42
5
  if (auto e = g_debugger_lifetime->Initialize(
43
5
          std::make_unique<SystemInitializerLLGS>(), nullptr))
44
0
    llvm::consumeError(std::move(e));
45
5
}
46
47
4
static void terminate_debugger() { g_debugger_lifetime->Terminate(); }
48
} // namespace llgs
49
50
// main
51
5
int main(int argc, char *argv[]) {
52
5
  llvm::InitLLVM IL(argc, argv, /*InstallPipeSignalExitHandler=*/false);
53
5
  llvm::PrettyStackTraceProgram X(argc, argv);
54
55
5
  int option_error = 0;
56
5
  const char *progname = argv[0];
57
5
  if (argc < 2) {
58
0
    display_usage(progname);
59
0
    exit(option_error);
60
0
  }
61
62
5
  switch (argv[1][0]) {
63
4
  case 'g':
64
4
    llgs::initialize();
65
4
    main_gdbserver(argc, argv);
66
4
    llgs::terminate_debugger();
67
4
    break;
68
1
  case 'p':
69
1
    llgs::initialize();
70
1
    main_platform(argc, argv);
71
1
    llgs::terminate_debugger();
72
1
    break;
73
0
  case 'v':
74
0
    fprintf(stderr, "%s\n", lldb_private::GetVersion());
75
0
    break;
76
0
  default:
77
0
    display_usage(progname);
78
0
    exit(option_error);
79
5
  }
80
5
}