Merge pull request #450 from jelson/prefix-fix-2
Improve parsing of commands that require enable or disable arguments
This commit is contained in:
commit
88ec557683
|
@ -247,14 +247,40 @@ bool cmd_morse(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool parse_enable_or_disable(const char *s, bool *out) {
|
||||
if (strlen(s) == 0) {
|
||||
gdb_outf("'enable' or 'disable' argument must be provided\n");
|
||||
return false;
|
||||
} else if (!strncmp(s, "enable", strlen(s))) {
|
||||
*out = true;
|
||||
return true;
|
||||
} else if (!strncmp(s, "disable", strlen(s))) {
|
||||
*out = false;
|
||||
return true;
|
||||
} else {
|
||||
gdb_outf("Argument '%s' not recognized as 'enable' or 'disable'\n", s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool cmd_connect_srst(target *t, int argc, const char **argv)
|
||||
{
|
||||
(void)t;
|
||||
if (argc == 1)
|
||||
bool print_status = false;
|
||||
if (argc == 1) {
|
||||
print_status = true;
|
||||
} else if (argc == 2) {
|
||||
if (parse_enable_or_disable(argv[1], &connect_assert_srst)) {
|
||||
print_status = true;
|
||||
}
|
||||
} else {
|
||||
gdb_outf("Unrecognized command format\n");
|
||||
}
|
||||
|
||||
if (print_status) {
|
||||
gdb_outf("Assert SRST during connect: %s\n",
|
||||
connect_assert_srst ? "enabled" : "disabled");
|
||||
else
|
||||
connect_assert_srst = !strcmp(argv[1], "enable");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -280,11 +306,18 @@ static bool cmd_hard_srst(void)
|
|||
static bool cmd_target_power(target *t, int argc, const char **argv)
|
||||
{
|
||||
(void)t;
|
||||
if (argc == 1)
|
||||
if (argc == 1) {
|
||||
gdb_outf("Target Power: %s\n",
|
||||
platform_target_get_power() ? "enabled" : "disabled");
|
||||
else
|
||||
platform_target_set_power(!strncmp(argv[1], "enable", strlen(argv[1])));
|
||||
} else if (argc == 2) {
|
||||
bool want_enable = false;
|
||||
if (parse_enable_or_disable(argv[1], &want_enable)) {
|
||||
platform_target_set_power(want_enable);
|
||||
gdb_outf("%s target power\n", want_enable ? "Enabling" : "Disabling");
|
||||
}
|
||||
} else {
|
||||
gdb_outf("Unrecognized command format\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
@ -313,11 +346,21 @@ static bool cmd_traceswo(target *t, int argc, const char **argv)
|
|||
static bool cmd_debug_bmp(target *t, int argc, const char **argv)
|
||||
{
|
||||
(void)t;
|
||||
if (argc > 1) {
|
||||
debug_bmp = !strcmp(argv[1], "enable");
|
||||
bool print_status = false;
|
||||
if (argc == 1) {
|
||||
print_status = true;
|
||||
} else if (argc == 2) {
|
||||
if (parse_enable_or_disable(argv[1], &debug_bmp)) {
|
||||
print_status = true;
|
||||
}
|
||||
} else {
|
||||
gdb_outf("Unrecognized command format\n");
|
||||
}
|
||||
|
||||
if (print_status) {
|
||||
gdb_outf("Debug mode is %s\n",
|
||||
debug_bmp ? "enabled" : "disabled");
|
||||
}
|
||||
gdb_outf("Debug mode is %s\n",
|
||||
debug_bmp ? "enabled" : "disabled");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -21,9 +21,19 @@
|
|||
#ifndef __COMMAND_H
|
||||
#define __COMMAND_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "target.h"
|
||||
|
||||
int command_process(target *t, char *cmd);
|
||||
|
||||
/*
|
||||
* Attempts to parse a string as either being "enable" or "disable".
|
||||
* If the parse is successful, returns true and sets the out param to
|
||||
* indicate what was parsed. If not successful, emits a warning to the
|
||||
* gdb port, returns false and leaves out untouched.
|
||||
*/
|
||||
bool parse_enable_or_disable(const char *s, bool *out);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -26,6 +26,10 @@
|
|||
#define __TARGET_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef struct target_s target;
|
||||
typedef uint32_t target_addr;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "target_internal.h"
|
||||
#include "cortexm.h"
|
||||
#include "platform.h"
|
||||
#include "command.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -874,7 +875,7 @@ static bool cortexm_vector_catch(target *t, int argc, char *argv[])
|
|||
uint32_t tmp = 0;
|
||||
unsigned i;
|
||||
|
||||
if ((argc < 3) || ((argv[1][0] != 'e') && (argv[1][0] != 'd'))) {
|
||||
if (argc < 3) {
|
||||
tc_printf(t, "usage: monitor vector_catch (enable|disable) "
|
||||
"(hard|int|bus|stat|chk|nocp|mm|reset)\n");
|
||||
} else {
|
||||
|
@ -884,12 +885,16 @@ static bool cortexm_vector_catch(target *t, int argc, char *argv[])
|
|||
tmp |= 1 << i;
|
||||
}
|
||||
|
||||
if (argv[1][0] == 'e')
|
||||
priv->demcr |= tmp;
|
||||
else
|
||||
priv->demcr &= ~tmp;
|
||||
bool enable;
|
||||
if (parse_enable_or_disable(argv[1], &enable)) {
|
||||
if (enable) {
|
||||
priv->demcr |= tmp;
|
||||
} else {
|
||||
priv->demcr &= ~tmp;
|
||||
}
|
||||
|
||||
target_mem_write32(t, CORTEXM_DEMCR, priv->demcr);
|
||||
target_mem_write32(t, CORTEXM_DEMCR, priv->demcr);
|
||||
}
|
||||
}
|
||||
|
||||
tc_printf(t, "Catching vectors: ");
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
* K64 Sub-Family Reference Manual, Rev. 2,
|
||||
*/
|
||||
|
||||
#include "command.h"
|
||||
#include "general.h"
|
||||
#include "target.h"
|
||||
#include "target_internal.h"
|
||||
|
@ -81,11 +82,12 @@ const struct command_s kinetis_cmd_list[] = {
|
|||
|
||||
static bool kinetis_cmd_unsafe(target *t, int argc, char *argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
if (argc == 1) {
|
||||
tc_printf(t, "Allow programming security byte: %s\n",
|
||||
unsafe_enabled ? "enabled" : "disabled");
|
||||
else
|
||||
unsafe_enabled = argv[1][0] == 'e';
|
||||
} else {
|
||||
parse_enable_or_disable(argv[1], &unsafe_enabled);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
* KE04 Sub-Family Data Sheet
|
||||
*/
|
||||
|
||||
#include "command.h"
|
||||
#include "general.h"
|
||||
#include "target.h"
|
||||
#include "target_internal.h"
|
||||
|
@ -170,11 +171,12 @@ static bool ke04_cmd_mass_erase(target *t, int argc, char *argv[])
|
|||
|
||||
static bool kinetis_cmd_unsafe(target *t, int argc, char *argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
if (argc == 1) {
|
||||
tc_printf(t, "Allow programming security byte: %s\n",
|
||||
unsafe_enabled ? "enabled" : "disabled");
|
||||
else
|
||||
unsafe_enabled = argv[1][0] == 'e';
|
||||
} else {
|
||||
parse_enable_or_disable(argv[1], &unsafe_enabled);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue