1 //===-- lldb-server.cpp -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Initialization/SystemLifetimeManager.h"
11 #include "lldb/Initialization/SystemInitializerCommon.h"
12 #include "lldb/lldb-private.h"
13 
14 #include "llvm/ADT/STLExtras.h"
15 #include "llvm/Support/ManagedStatic.h"
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 
20 static llvm::ManagedStatic<lldb_private::SystemLifetimeManager> g_debugger_lifetime;
21 
22 static void
23 display_usage (const char *progname)
24 {
25     fprintf(stderr, "Usage:\n"
26             "  %s v[ersion]\n"
27             "  %s g[dbserver] [options]\n"
28             "  %s p[latform] [options]\n"
29             "Invoke subcommand for additional help\n", progname, progname, progname);
30     exit(0);
31 }
32 
33 // Forward declarations of subcommand main methods.
34 int main_gdbserver (int argc, char *argv[]);
35 int main_platform (int argc, char *argv[]);
36 
37 static void
38 initialize ()
39 {
40     g_debugger_lifetime->Initialize(llvm::make_unique<lldb_private::SystemInitializerCommon>(), nullptr);
41 }
42 
43 static void
44 terminate ()
45 {
46     g_debugger_lifetime->Terminate();
47 }
48 
49 //----------------------------------------------------------------------
50 // main
51 //----------------------------------------------------------------------
52 int
53 main (int argc, char *argv[])
54 {
55     int option_error = 0;
56     const char *progname = argv[0];
57     if (argc < 2)
58     {
59         display_usage(progname);
60         exit(option_error);
61     }
62 
63     switch (argv[1][0])
64     {
65         case 'g':
66             initialize();
67             main_gdbserver(argc, argv);
68             terminate();
69             break;
70         case 'p':
71             initialize();
72             main_platform(argc, argv);
73             terminate();
74             break;
75         case 'v':
76             fprintf(stderr, "%s\n", lldb_private::GetVersion());
77             break;
78         default:
79             display_usage(progname);
80             exit(option_error);
81     }
82 }
83