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/SystemInitializerCommon.h" 11 #include "lldb/Initialization/SystemLifetimeManager.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> 21 g_debugger_lifetime; 22 23 static void display_usage(const char *progname) { 24 fprintf(stderr, "Usage:\n" 25 " %s v[ersion]\n" 26 " %s g[dbserver] [options]\n" 27 " %s p[latform] [options]\n" 28 "Invoke subcommand for additional help\n", 29 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 initialize() { 38 g_debugger_lifetime->Initialize( 39 llvm::make_unique<lldb_private::SystemInitializerCommon>(), nullptr); 40 } 41 42 static void terminate() { g_debugger_lifetime->Terminate(); } 43 44 //---------------------------------------------------------------------- 45 // main 46 //---------------------------------------------------------------------- 47 int main(int argc, char *argv[]) { 48 int option_error = 0; 49 const char *progname = argv[0]; 50 if (argc < 2) { 51 display_usage(progname); 52 exit(option_error); 53 } 54 55 switch (argv[1][0]) { 56 case 'g': 57 initialize(); 58 main_gdbserver(argc, argv); 59 terminate(); 60 break; 61 case 'p': 62 initialize(); 63 main_platform(argc, argv); 64 terminate(); 65 break; 66 case 'v': 67 fprintf(stderr, "%s\n", lldb_private::GetVersion()); 68 break; 69 default: 70 display_usage(progname); 71 exit(option_error); 72 } 73 } 74