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/Core/Debugger.h"
11 #include "lldb/Initialization/SystemLifetimeManager.h"
12 #include "lldb/Initialization/SystemInitializerCommon.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 g[dbserver] [options]\n"
27             "  %s p[latform] [options]\n"
28             "Invoke subcommand for additional help\n", progname, progname);
29     exit(0);
30 }
31 
32 // Forward declarations of subcommand main methods.
33 int main_gdbserver (int argc, char *argv[]);
34 int main_platform (int argc, char *argv[]);
35 
36 static void
37 initialize ()
38 {
39     g_debugger_lifetime->Initialize(llvm::make_unique<lldb_private::SystemInitializerCommon>(), nullptr);
40 }
41 
42 static void
43 terminate ()
44 {
45     g_debugger_lifetime->Terminate();
46 }
47 
48 //----------------------------------------------------------------------
49 // main
50 //----------------------------------------------------------------------
51 int
52 main (int argc, char *argv[])
53 {
54     int option_error = 0;
55     const char *progname = argv[0];
56     if (argc < 2)
57     {
58         display_usage(progname);
59         exit(option_error);
60     }
61     else if (argv[1][0] == 'g')
62     {
63         initialize();
64         main_gdbserver(argc, argv);
65         terminate();
66     }
67     else if (argv[1][0] == 'p')
68     {
69         initialize();
70         main_platform(argc, argv);
71         terminate();
72     }
73     else {
74         display_usage(progname);
75         exit(option_error);
76     }
77 }
78