1
|
1 /* Ddbg - Win32 Debugger for the D programming language
|
|
2 * Copyright (c) 2007 Jascha Wetzel
|
|
3 * All rights reserved. See LICENSE.TXT for details.
|
|
4 */
|
|
5
|
|
6 import cli.userinterface;
|
|
7 import cli.ddbgcli;
|
|
8 import cli.gdbcli;
|
|
9 import cli.gdbmicli;
|
|
10 import debugger;
|
|
11
|
|
12 import std.string;
|
|
13 import std.stdio;
|
|
14
|
|
15 import util;
|
|
16
|
|
17 /**************************************************************************************************
|
|
18
|
|
19 **************************************************************************************************/
|
|
20 int main(string[] args)
|
|
21 {
|
|
22 debug domain(args);
|
|
23 else
|
|
24 {
|
|
25 try domain(args);
|
|
26 catch ( DebuggerException e )
|
|
27 {
|
|
28 writefln("%s", e.msg);
|
|
29 return 1;
|
|
30 }
|
|
31 catch ( Object o )
|
|
32 {
|
|
33 writefln("\n\n----------------------------------------\nUnhandled exception in %s:\n"~
|
|
34 "%s\n\nPlease report this problem!\nSee the http://ddbg.mainia.de/releases.html for details.\nThank you!",
|
|
35 VERSION_STRING, o
|
|
36 );
|
|
37 return 1;
|
|
38 }
|
|
39 }
|
|
40 return 0;
|
|
41 }
|
|
42
|
|
43 void domain(string[] args)
|
|
44 {
|
|
45 string[string] options = parseArgs(args);
|
|
46
|
|
47 UserInterface cli;
|
|
48 if ( ("cli" in options) !is null )
|
|
49 {
|
|
50 if ( options["cli"] == "gdb" )
|
|
51 cli = new GDBCLI;
|
|
52 else if ( options["cli"] == "gdbmi" )
|
|
53 cli = new GDBMICLI;
|
|
54 else {
|
|
55 DbgIO.println("Unknown CLI mode \"%s\"", options["cli"]);
|
|
56 return;
|
|
57 }
|
|
58 }
|
|
59 else
|
|
60 cli = new DdbgCLI;
|
|
61 cli.init(args);
|
|
62
|
|
63 if ( "cmd" in options )
|
|
64 {
|
|
65 string cmd_string = strip(options["cmd"]);
|
|
66 if ( cmd_string[0] == '"' && cmd_string[$-1] == '"' )
|
|
67 cmd_string = cmd_string[1..$-1];
|
|
68 cli.runCommands(cmd_string);
|
|
69 }
|
|
70
|
|
71 cli.start();
|
|
72 }
|
|
73
|
|
74 string[string] parseArgs(inout string[] args)
|
|
75 {
|
|
76 string[string] options;
|
|
77
|
|
78 for ( int i=1; i < args.length; )
|
|
79 {
|
|
80 string arg = args[i];
|
|
81
|
|
82 uint optend;
|
|
83 for ( optend = 1; optend < arg.length; ++optend )
|
|
84 {
|
|
85 if ( !inPattern(arg[optend], "a-zA-Z0-9") )
|
|
86 break;
|
|
87 }
|
|
88 string option = arg[0..optend];
|
|
89 switch ( option )
|
|
90 {
|
|
91 case "-cli":
|
|
92 case "-cmd":
|
|
93 string value;
|
|
94 if ( optend >= arg.length ) {
|
|
95 args = args[0..i]~args[i+1..$];
|
|
96 value = args[i];
|
|
97 }
|
|
98 else
|
|
99 value = arg[optend..$];
|
|
100 if ( value.length <= 0 ) {
|
|
101 DbgIO.println("ERROR: -%s=<value> or -%s <value> expected", option, option);
|
|
102 break;
|
|
103 }
|
|
104 if ( value[0] == '=' )
|
|
105 value = value[1..$];
|
|
106 options[option[1..$]] = value;
|
|
107 args = args[0..i]~args[i+1..$];
|
|
108 break;
|
|
109 default:
|
|
110 ++i;
|
|
111 if ( option[0] != '-' )
|
|
112 return options;
|
|
113 break;
|
|
114 }
|
|
115 }
|
|
116 return options;
|
|
117 }
|