sim: m32c/rl78/rx: fix command parsing
Use buildargv to avoid writing to const memory and freeing invalid pointers, and to avoid doing any string parsing ourselves.
This commit is contained in:
parent
4467df35a9
commit
75070a4ede
6 changed files with 59 additions and 80 deletions
|
@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|||
#include <ctype.h>
|
||||
|
||||
#include "ansidecl.h"
|
||||
#include "libiberty.h"
|
||||
#include "gdb/callback.h"
|
||||
#include "gdb/remote-sim.h"
|
||||
#include "gdb/signals.h"
|
||||
|
@ -648,37 +649,25 @@ sim_stop_reason (SIM_DESC sd, enum sim_stop *reason_p, int *sigrc_p)
|
|||
void
|
||||
sim_do_command (SIM_DESC sd, const char *cmd)
|
||||
{
|
||||
const char *args;
|
||||
char *p = strdup (cmd);
|
||||
const char *arg;
|
||||
char **argv = buildargv (cmd);
|
||||
|
||||
check_desc (sd);
|
||||
|
||||
/* Skip leading whitespace. */
|
||||
while (isspace (*p))
|
||||
p++;
|
||||
|
||||
/* Find the extent of the command word. */
|
||||
for (p = cmd; *p; p++)
|
||||
if (isspace (*p))
|
||||
break;
|
||||
|
||||
/* Null-terminate the command word, and record the start of any
|
||||
further arguments. */
|
||||
if (*p)
|
||||
cmd = arg = "";
|
||||
if (argv != NULL)
|
||||
{
|
||||
*p = '\0';
|
||||
args = p + 1;
|
||||
while (isspace (*args))
|
||||
args++;
|
||||
if (argv[0] != NULL)
|
||||
cmd = argv[0];
|
||||
if (argv[1] != NULL)
|
||||
arg = argv[1];
|
||||
}
|
||||
else
|
||||
args = p;
|
||||
|
||||
if (strcmp (cmd, "trace") == 0)
|
||||
{
|
||||
if (strcmp (args, "on") == 0)
|
||||
if (strcmp (arg, "on") == 0)
|
||||
trace = 1;
|
||||
else if (strcmp (args, "off") == 0)
|
||||
else if (strcmp (arg, "off") == 0)
|
||||
trace = 0;
|
||||
else
|
||||
printf ("The 'sim trace' command expects 'on' or 'off' "
|
||||
|
@ -686,9 +675,9 @@ sim_do_command (SIM_DESC sd, const char *cmd)
|
|||
}
|
||||
else if (strcmp (cmd, "verbose") == 0)
|
||||
{
|
||||
if (strcmp (args, "on") == 0)
|
||||
if (strcmp (arg, "on") == 0)
|
||||
verbose = 1;
|
||||
else if (strcmp (args, "off") == 0)
|
||||
else if (strcmp (arg, "off") == 0)
|
||||
verbose = 0;
|
||||
else
|
||||
printf ("The 'sim verbose' command expects 'on' or 'off'"
|
||||
|
@ -698,7 +687,7 @@ sim_do_command (SIM_DESC sd, const char *cmd)
|
|||
printf ("The 'sim' command expects either 'trace' or 'verbose'"
|
||||
" as a subcommand.\n");
|
||||
|
||||
free (p);
|
||||
freeargv (argv);
|
||||
}
|
||||
|
||||
char **
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue