/* Simulator option handling.
- Copyright (C) 1996, 1997, 2004, 2007, 2008, 2009, 2010
- Free Software Foundation, Inc.
+ Copyright (C) 1996-2013 Free Software Foundation, Inc.
Contributed by Cygnus Support.
This file is part of GDB, the GNU debugger.
case OPTION_ARCHITECTURE_INFO:
{
- const char **list = bfd_arch_list();
+ const char **list = bfd_arch_list ();
const char **lp;
if (list == NULL)
abort ();
case OPTION_SYSROOT:
/* Don't leak memory in the odd event that there's lots of
- --sysroot=... options. */
- if (simulator_sysroot[0] != '\0' && arg[0] != '\0')
+ --sysroot=... options. We treat "" specially since this
+ is the statically initialized value and cannot free it. */
+ if (simulator_sysroot[0] != '\0')
free (simulator_sysroot);
- simulator_sysroot = xstrdup (arg);
+ if (arg[0] != '\0')
+ simulator_sysroot = xstrdup (arg);
+ else
+ simulator_sysroot = "";
break;
}
arg_table[hash] = arg;
return 0;
}
-
+
/* Called by sim_open to parse the arguments. */
SIM_RC
char *name;
*lp = opt->opt;
/* Prepend --<cpuname>- to the option. */
- asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name);
+ if (asprintf (&name, "%s-%s", CPU_NAME (cpu), lp->name) < 0)
+ {
+ sim_io_eprintf (sd, "internal error, out of memory");
+ result = SIM_RC_FAIL;
+ break;
+ }
lp->name = name;
/* Dynamically assign `val' numbers for long options. */
lp->val = i++;
}
}
}
-
+
/* Terminate the short and long option lists. */
*p = 0;
lp->name = NULL;
}
}
- zfree (long_options);
- zfree (short_options);
- zfree (handlers);
- zfree (opt_cpu);
- zfree (orig_val);
+ free (long_options);
+ free (short_options);
+ free (handlers);
+ free (opt_cpu);
+ free (orig_val);
return result;
}
}
while (OPTION_VALID_P (o) && o->doc == NULL);
}
-
+
/* list any long options (aliases) for the current OPT */
o = opt;
do
return matching_opt;
}
+static char **
+complete_option_list (char **ret, size_t *cnt, const struct option_list *ol,
+ char *text, char *word)
+{
+ const OPTION *opt = NULL;
+ int argi;
+ size_t len = strlen (word);
+
+ for ( ; ol != NULL; ol = ol->next)
+ for (opt = ol->options; OPTION_VALID_P (opt); ++opt)
+ {
+ const char *name = opt->opt.name;
+
+ /* A long option to match against? */
+ if (!name)
+ continue;
+
+ /* Does this option actually match? */
+ if (strncmp (name, word, len))
+ continue;
+
+ ret = xrealloc (ret, ++*cnt * sizeof (ret[0]));
+ ret[*cnt - 2] = xstrdup (name);
+ }
+
+ return ret;
+}
+
+/* All leading text is stored in @text, while the current word being
+ completed is stored in @word. Trailing text of @word is not. */
+
+char **
+sim_complete_command (SIM_DESC sd, char *text, char *word)
+{
+ char **ret = NULL;
+ size_t cnt = 1;
+ sim_cpu *cpu;
+
+ /* Only complete first word for now. */
+ if (text != word)
+ return ret;
+
+ cpu = STATE_CPU (sd, 0);
+ if (cpu)
+ ret = complete_option_list (ret, &cnt, CPU_OPTIONS (cpu), text, word);
+ ret = complete_option_list (ret, &cnt, STATE_OPTIONS (sd), text, word);
+
+ if (ret)
+ ret[cnt - 1] = NULL;
+ return ret;
+}
+
SIM_RC
sim_args_command (SIM_DESC sd, char *cmd)
{
/* something to do? */
if (cmd == NULL)
return SIM_RC_OK; /* FIXME - perhaps help would be better */
-
+
if (cmd [0] == '-')
{
/* user specified -<opt> ... form? */
freeargv (argv);
}
-
+
/* didn't find anything that remotly matched */
return SIM_RC_FAIL;
}