- add gdb pipe support to native win32 (--pipe option)
[openocd.git] / src / helper / options.c
1 /***************************************************************************
2 * Copyright (C) 2004, 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "replacements.h"
28
29 #include "types.h"
30 #include "command.h"
31 #include "configuration.h"
32 #include "log.h"
33 #include "server.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <getopt.h>
38 #include <string.h>
39
40 static int help_flag, version_flag;
41
42 static struct option long_options[] =
43 {
44 {"help", no_argument, &help_flag, 1},
45 {"version", no_argument, &version_flag, 1},
46 {"debug", optional_argument, 0, 'd'},
47 {"file", required_argument, 0, 'f'},
48 {"search", required_argument, 0, 's'},
49 {"log_output", required_argument, 0, 'l'},
50 {"command", required_argument, 0, 'c'},
51 {"pipe", no_argument, 0, 'p'},
52 {0, 0, 0, 0}
53 };
54
55 int configuration_output_handler(struct command_context_s *context, const char* line)
56 {
57 LOG_USER_N(line);
58
59 return ERROR_OK;
60 }
61
62 int add_default_dirs(void)
63 {
64 #ifdef _WIN32
65 /* Add the parent of the directory where openocd.exe resides to the
66 * config script search path.
67 * Directory layout:
68 * bin\openocd.exe
69 * lib\openocd
70 * event\at91eb40a_reset.cfg
71 * target\at91eb40a.cfg
72 */
73 {
74 char strExePath [MAX_PATH];
75 GetModuleFileName (NULL, strExePath, MAX_PATH);
76 /* Either this code will *always* work or it will SEGFAULT giving
77 * excellent information on the culprit.
78 */
79 *strrchr(strExePath, '\\')=0;
80 strcat(strExePath, "\\..");
81 add_script_search_dir(strExePath);
82 }
83 #else
84 /* Add dir for openocd supplied scripts last so that user can over
85 ride those scripts if desired. */
86 add_script_search_dir(PKGDATADIR);
87 add_script_search_dir(PKGLIBDIR);
88 #endif
89 return ERROR_OK;
90 }
91
92 int parse_cmdline_args(struct command_context_s *cmd_ctx, int argc, char *argv[])
93 {
94 int c;
95 char command_buffer[128];
96
97 while (1)
98 {
99 /* getopt_long stores the option index here. */
100 int option_index = 0;
101
102 c = getopt_long(argc, argv, "hvd::l:f:s:c:p", long_options, &option_index);
103
104 /* Detect the end of the options. */
105 if (c == -1)
106 break;
107
108 switch (c)
109 {
110 case 0:
111 break;
112 case 'h': /* --help | -h */
113 help_flag = 1;
114 break;
115 case 'v': /* --version | -v */
116 version_flag = 1;
117 break;
118 case 'f': /* --file | -f */
119 {
120 snprintf(command_buffer, 128, "script {%s}", optarg);
121 add_config_command(command_buffer);
122 break;
123 }
124 case 's': /* --search | -s */
125 add_script_search_dir(optarg);
126 break;
127 case 'd': /* --debug | -d */
128 if (optarg)
129 snprintf(command_buffer, 128, "debug_level %s", optarg);
130 else
131 snprintf(command_buffer, 128, "debug_level 3");
132 command_run_line(cmd_ctx, command_buffer);
133 break;
134 case 'l': /* --log_output | -l */
135 if (optarg)
136 {
137 snprintf(command_buffer, 128, "log_output %s", optarg);
138 command_run_line(cmd_ctx, command_buffer);
139 }
140 break;
141 case 'c': /* --command | -c */
142 if (optarg)
143 {
144 add_config_command(optarg);
145 }
146 break;
147 case 'p': /* --pipe | -p */
148 #if BUILD_ECOSBOARD == 1
149 /* pipes unsupported on hosted platforms */
150 LOG_WARNING("pipes not supported on this platform");
151 #else
152 server_use_pipes = 1;
153 #endif
154 break;
155 }
156 }
157
158 if (help_flag)
159 {
160 LOG_OUTPUT("Open On-Chip Debugger\n(c) 2005-2008 by Dominic Rath\n\n");
161 LOG_OUTPUT("--help | -h\tdisplay this help\n");
162 LOG_OUTPUT("--version | -v\tdisplay OpenOCD version\n");
163 LOG_OUTPUT("--file | -f\tuse configuration file <name>\n");
164 LOG_OUTPUT("--search | -s\tdir to search for config files and scripts\n");
165 LOG_OUTPUT("--debug | -d\tset debug level <0-3>\n");
166 LOG_OUTPUT("--log_output | -l\tredirect log output to file <name>\n");
167 LOG_OUTPUT("--command | -c\trun <command>\n");
168 LOG_OUTPUT("--pipe | -p\tuse pipes for gdb communication\n");
169 exit(-1);
170 }
171
172 if (version_flag)
173 {
174 /* Nothing to do, version gets printed automatically. */
175 // It is not an error to request the VERSION number.
176 exit(0);
177 }
178
179 return ERROR_OK;
180 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)