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