29 #ifdef HAVE_SYS_SYSCTL_H
30 #include <sys/sysctl.h>
33 #if IS_WIN32 && !IS_CYGWIN
42 {
"debug", optional_argument, 0,
'd'},
43 {
"file", required_argument, 0,
'f'},
44 {
"search", required_argument, 0,
's'},
45 {
"log_output", required_argument, 0,
'l'},
46 {
"command", required_argument, 0,
'c'},
65 #if IS_WIN32 && !IS_CYGWIN
66 exepath = malloc(MAX_PATH);
69 GetModuleFileName(
NULL, exepath, MAX_PATH);
72 for (
char *p = exepath; *p; p++) {
78 exepath = malloc(PROC_PIDPATHINFO_MAXSIZE);
81 if (proc_pidpath(getpid(), exepath, PROC_PIDPATHINFO_MAXSIZE) <= 0) {
86 #elif defined(CTL_KERN) && defined(KERN_PROC) && defined(KERN_PROC_PATHNAME)
90 char *path = malloc(PATH_MAX);
93 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
94 size_t size = PATH_MAX;
100 exepath = realpath(path,
NULL);
106 #elif defined(HAVE_REALPATH)
108 exepath = realpath(
"/proc/self/exe",
NULL);
110 exepath = realpath(
"/proc/self/path/a.out",
NULL);
112 exepath = realpath(
"/proc/curproc/file",
NULL);
118 *strrchr(exepath,
'/') =
'\0';
120 LOG_WARNING(
"Could not determine executable path, using configured BINDIR.");
123 exepath = realpath(BINDIR,
NULL);
125 exepath = strdup(BINDIR);
138 for (
size_t n = 0; from[n] == to[n]; n++) {
139 if (from[n] ==
'\0') {
151 while (from[0] !=
'\0') {
154 char *next = strchr(from,
'/');
161 char *relpath = malloc(i * 3 + strlen(to) + 1);
163 for (
size_t n = 0; n < i; n++)
164 strcat(relpath,
"../");
175 const char *appdata = getenv(
"APPDATA");
181 for (
char *p = path; *p; p++) {
192 const char *home = getenv(
"HOME");
195 path =
alloc_printf(
"%s/Library/Preferences/org.openocd", home);
202 const char *xdg_config = getenv(
"XDG_CONFIG_HOME");
243 path = getenv(
"OPENOCD_SCRIPTS");
249 path =
alloc_printf(
"%s/%s/%s", exepath, bin2data,
"site");
255 path =
alloc_printf(
"%s/%s/%s", exepath, bin2data,
"scripts");
271 int option_index = 0;
273 c = getopt_long(argc, argv,
"hvd::l:f:s:c:",
long_options, &option_index);
300 int retval =
command_run_linef(cmd_ctx,
"debug_level %s", optarg ? optarg :
"3");
321 LOG_OUTPUT(
"Unexpected command line argument: %s\n", argv[optind]);
326 LOG_OUTPUT(
"Open On-Chip Debugger\nLicensed under GNU GPL v2\n");
327 LOG_OUTPUT(
"--help | -h\tdisplay this help\n");
328 LOG_OUTPUT(
"--version | -v\tdisplay OpenOCD version\n");
329 LOG_OUTPUT(
"--file | -f\tuse configuration file <name>\n");
330 LOG_OUTPUT(
"--search | -s\tdir to search for config files and scripts\n");
331 LOG_OUTPUT(
"--debug | -d\tset debug level to 3\n");
332 LOG_OUTPUT(
" | -d<n>\tset debug level to <level>\n");
333 LOG_OUTPUT(
"--log_output | -l\tredirect log output to file <name>\n");
334 LOG_OUTPUT(
"--command | -c\trun <command>\n");
int command_run_linef(struct command_context *context, const char *format,...)
void add_config_command(const char *cfg)
void add_script_search_dir(const char *dir)
char * alloc_printf(const char *format,...)
#define LOG_OUTPUT(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_USER_N(expr ...)
#define LOG_DEBUG(expr ...)
static char * find_exe_path(void)
int configuration_output_handler(struct command_context *context, const char *line)
static void add_user_dirs(void)
static char * find_relative_path(const char *from, const char *to)
static const struct option long_options[]
int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[])
static void add_default_dirs(void)
size_t size
Size of the control block search area.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.