Tamas Berghammer | c2c3d71 | 2015-02-18 15:39:41 +0000 | [diff] [blame] | 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 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 10 | #include "lldb/Initialization/SystemInitializerCommon.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 11 | #include "lldb/Initialization/SystemLifetimeManager.h" |
Tamas Berghammer | 2e912ec | 2016-02-10 10:35:48 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-private.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 13 | |
| 14 | #include "llvm/ADT/STLExtras.h" |
| 15 | #include "llvm/Support/ManagedStatic.h" |
Robert Flack | ab3269d | 2015-03-02 15:14:50 +0000 | [diff] [blame] | 16 | |
Tamas Berghammer | c2c3d71 | 2015-02-18 15:39:41 +0000 | [diff] [blame] | 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 20 | static llvm::ManagedStatic<lldb_private::SystemLifetimeManager> |
| 21 | g_debugger_lifetime; |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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); |
Tamas Berghammer | c2c3d71 | 2015-02-18 15:39:41 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | // Forward declarations of subcommand main methods. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 34 | int main_gdbserver(int argc, char *argv[]); |
| 35 | int main_platform(int argc, char *argv[]); |
Tamas Berghammer | c2c3d71 | 2015-02-18 15:39:41 +0000 | [diff] [blame] | 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 37 | static void initialize() { |
| 38 | g_debugger_lifetime->Initialize( |
| 39 | llvm::make_unique<lldb_private::SystemInitializerCommon>(), nullptr); |
Robert Flack | ab3269d | 2015-03-02 15:14:50 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 42 | static void terminate() { g_debugger_lifetime->Terminate(); } |
Robert Flack | ab3269d | 2015-03-02 15:14:50 +0000 | [diff] [blame] | 43 | |
Tamas Berghammer | c2c3d71 | 2015-02-18 15:39:41 +0000 | [diff] [blame] | 44 | //---------------------------------------------------------------------- |
| 45 | // main |
| 46 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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 | } |
Tamas Berghammer | 2e912ec | 2016-02-10 10:35:48 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame^] | 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 | } |
Tamas Berghammer | c2c3d71 | 2015-02-18 15:39:41 +0000 | [diff] [blame] | 73 | } |