command: Run clang-format across the code

This commit is contained in:
dragonmux 2022-07-26 12:11:20 +01:00 committed by Piotr Esden-Tempski
parent f85265438c
commit 68a6a7b85e
1 changed files with 80 additions and 90 deletions

View File

@ -40,7 +40,7 @@
#endif
#ifdef PLATFORM_HAS_TRACESWO
# include "traceswo.h"
#include "traceswo.h"
#endif
#include <alloca.h>
@ -75,34 +75,34 @@ static bool cmd_debug_bmp(target *t, int argc, const char **argv);
const struct command_s cmd_list[] = {
{"version", (cmd_handler)cmd_version, "Display firmware version info"},
{"help", (cmd_handler)cmd_help, "Display help for monitor commands"},
{"jtag_scan", (cmd_handler)cmd_jtag_scan, "Scan JTAG chain for devices" },
{"swdp_scan", (cmd_handler)cmd_swdp_scan, "Scan SW-DP for devices" },
{"jtag_scan", (cmd_handler)cmd_jtag_scan, "Scan JTAG chain for devices"},
{"swdp_scan", (cmd_handler)cmd_swdp_scan, "Scan SW-DP for devices"},
{"auto_scan", (cmd_handler)cmd_auto_scan, "Automatically scan all chain types for devices"},
{"frequency", (cmd_handler)cmd_frequency, "set minimum high and low times" },
{"targets", (cmd_handler)cmd_targets, "Display list of available targets" },
{"morse", (cmd_handler)cmd_morse, "Display morse error message" },
{"halt_timeout", (cmd_handler)cmd_halt_timeout, "Timeout (ms) to wait until Cortex-M is halted: (Default 2000)" },
{"connect_rst", (cmd_handler)cmd_connect_reset, "Configure connect under reset: (enable|disable)" },
{"reset", (cmd_handler)cmd_reset, "Pulse the nRST line - disconnects target" },
{"frequency", (cmd_handler)cmd_frequency, "set minimum high and low times"},
{"targets", (cmd_handler)cmd_targets, "Display list of available targets"},
{"morse", (cmd_handler)cmd_morse, "Display morse error message"},
{"halt_timeout", (cmd_handler)cmd_halt_timeout, "Timeout (ms) to wait until Cortex-M is halted: (Default 2000)"},
{"connect_rst", (cmd_handler)cmd_connect_reset, "Configure connect under reset: (enable|disable)"},
{"reset", (cmd_handler)cmd_reset, "Pulse the nRST line - disconnects target"},
{"tdi_low_reset", (cmd_handler)cmd_tdi_low_reset, "Pulse nRST with TDI set low to attempt to wake certain targets up (eg LPC82x)"},
#ifdef PLATFORM_HAS_POWER_SWITCH
{"tpwr", (cmd_handler)cmd_target_power, "Supplies power to the target: (enable|disable)"},
#endif
#ifdef ENABLE_RTT
{"rtt", (cmd_handler)cmd_rtt, "enable|disable|status|channel 0..15|ident (str)|cblock|poll maxms minms maxerr" },
{"rtt", (cmd_handler)cmd_rtt, "enable|disable|status|channel 0..15|ident (str)|cblock|poll maxms minms maxerr"},
#endif
#ifdef PLATFORM_HAS_TRACESWO
#if defined TRACESWO_PROTOCOL && TRACESWO_PROTOCOL == 2
{"traceswo", (cmd_handler)cmd_traceswo, "Start trace capture, NRZ mode: (baudrate) (decode channel ...)" },
{"traceswo", (cmd_handler)cmd_traceswo, "Start trace capture, NRZ mode: (baudrate) (decode channel ...)"},
#else
{"traceswo", (cmd_handler)cmd_traceswo, "Start trace capture, Manchester mode: (decode channel ...)" },
{"traceswo", (cmd_handler)cmd_traceswo, "Start trace capture, Manchester mode: (decode channel ...)"},
#endif
#endif
{"heapinfo", (cmd_handler)cmd_heapinfo, "Set semihosting heapinfo" },
{"heapinfo", (cmd_handler)cmd_heapinfo, "Set semihosting heapinfo"},
#if defined(PLATFORM_HAS_DEBUG) && (PC_HOSTED == 0)
{"debug_bmp", (cmd_handler)cmd_debug_bmp, "Output BMP \"debug\" strings to the second vcom: (enable|disable)"},
#endif
{NULL, NULL, NULL}
{NULL, NULL, NULL},
};
bool connect_assert_nrst;
@ -119,8 +119,9 @@ int command_process(target *t, char *cmd)
const char *part;
/* Initial estimate for argc */
for(char *s = cmd; *s; s++)
if((*s == ' ') || (*s == '\t')) argc++;
for (char *s = cmd; *s; s++)
if ((*s == ' ') || (*s == '\t'))
argc++;
/* This needs replacing with something more sensible.
* It should be pinging -Wvla among other things, and it failing is straight-up UB
@ -133,7 +134,7 @@ int command_process(target *t, char *cmd)
argv[argc++] = part;
/* Look for match and call handler */
for(c = cmd_list; c->cmd; c++) {
for (c = cmd_list; c->cmd; c++) {
/* Accept a partial match as GDB does.
* So 'mon ver' will match 'monitor version'
*/
@ -177,7 +178,7 @@ bool cmd_help(target *t, int argc, char **argv)
if (!t || t->tc->destroy_callback) {
gdb_out("General commands:\n");
for(c = cmd_list; c->cmd; c++)
for (c = cmd_list; c->cmd; c++)
gdb_outf("\t%s -- %s\n", c->cmd, c->help);
}
if (!t)
@ -199,8 +200,8 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv)
if (argc > 1) {
/* Accept a list of IR lengths on command line */
for (int i = 1; i < argc; i++)
irlens[i-1] = atoi(argv[i]);
irlens[argc-1] = 0;
irlens[i - 1] = atoi(argv[i]);
irlens[argc - 1] = 0;
}
if (connect_assert_nrst)
@ -208,7 +209,7 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv)
int devs = -1;
volatile struct exception e;
TRY_CATCH(e, EXCEPTION_ALL) {
TRY_CATCH (e, EXCEPTION_ALL) {
#if PC_HOSTED == 1
devs = platform_jtag_scan(argc > 1 ? irlens : NULL);
#else
@ -240,7 +241,7 @@ bool cmd_swdp_scan(target *t, int argc, char **argv)
(void)t;
volatile uint32_t targetid = 0;
if (argc > 1)
targetid = strtol(argv[1], NULL, 0);
targetid = strtol(argv[1], NULL, 0);
if (platform_target_voltage())
gdb_outf("Target voltage: %s\n", platform_target_voltage());
@ -249,13 +250,13 @@ bool cmd_swdp_scan(target *t, int argc, char **argv)
int devs = -1;
volatile struct exception e;
TRY_CATCH(e, EXCEPTION_ALL) {
TRY_CATCH (e, EXCEPTION_ALL) {
#if PC_HOSTED == 1
devs = platform_adiv5_swdp_scan(targetid);
#else
devs = adiv5_swdp_scan(targetid);
#endif
}
}
switch (e.type) {
case EXCEPTION_TIMEOUT:
gdb_outf("Timeout during scan. Is target stuck in WFI?\n");
@ -265,7 +266,7 @@ bool cmd_swdp_scan(target *t, int argc, char **argv)
break;
}
if(devs <= 0) {
if (devs <= 0) {
platform_nrst_set_val(false);
gdb_out("SW-DP scan failed!\n");
return false;
@ -289,7 +290,7 @@ bool cmd_auto_scan(target *t, int argc, char **argv)
int devs = -1;
volatile struct exception e;
TRY_CATCH(e, EXCEPTION_ALL) {
TRY_CATCH (e, EXCEPTION_ALL) {
#if PC_HOSTED == 1
devs = platform_jtag_scan(NULL);
#else
@ -341,7 +342,7 @@ bool cmd_frequency(target *t, int argc, char **argv)
frequency *= 1000;
break;
case 'M':
frequency *= 1000*1000;
frequency *= 1000 * 1000;
break;
}
platform_max_frequency_set(frequency);
@ -352,23 +353,18 @@ bool cmd_frequency(target *t, int argc, char **argv)
else
gdb_outf("Max SWJ freq %08" PRIx32 "\n", freq);
return true;
}
static void display_target(int i, target *t, void *context)
{
(void)context;
if (!strcmp(target_driver_name(t), "ARM Cortex-M")) {
gdb_outf("***%2d%sUnknown %s Designer 0x%03x Partno 0x%03x %s\n",
i, target_attached(t)?" * ":" ",
target_driver_name(t),
target_designer(t),
target_idcode(t),
(target_core_name(t)) ? target_core_name(t): "");
gdb_outf("***%2d%sUnknown %s Designer 0x%03x Partno 0x%03x %s\n", i, target_attached(t) ? " * " : " ",
target_driver_name(t), target_designer(t), target_idcode(t),
(target_core_name(t)) ? target_core_name(t) : "");
} else {
gdb_outf("%2d %c %s %s\n", i, target_attached(t)?'*':' ',
target_driver_name(t),
(target_core_name(t)) ? target_core_name(t): "");
gdb_outf("%2d %c %s %s\n", i, target_attached(t) ? '*' : ' ', target_driver_name(t),
(target_core_name(t)) ? target_core_name(t) : "");
}
}
@ -428,8 +424,7 @@ static bool cmd_connect_reset(target *t, int argc, const char **argv)
}
if (print_status) {
gdb_outf("Assert nRST during connect: %s\n",
connect_assert_nrst ? "enabled" : "disabled");
gdb_outf("Assert nRST during connect: %s\n", connect_assert_nrst ? "enabled" : "disabled");
}
return true;
}
@ -439,8 +434,7 @@ static bool cmd_halt_timeout(target *t, int argc, const char **argv)
(void)t;
if (argc > 1)
cortexm_wait_timeout = atol(argv[1]);
gdb_outf("Cortex-M timeout to wait for device haltes: %d\n",
cortexm_wait_timeout);
gdb_outf("Cortex-M timeout to wait for device haltes: %d\n", cortexm_wait_timeout);
return true;
}
@ -470,14 +464,12 @@ static bool cmd_target_power(target *t, int argc, const char **argv)
{
(void)t;
if (argc == 1) {
gdb_outf("Target Power: %s\n",
platform_target_get_power() ? "enabled" : "disabled");
gdb_outf("Target Power: %s\n", platform_target_get_power() ? "enabled" : "disabled");
} else if (argc == 2) {
bool want_enable = false;
if (parse_enable_or_disable(argv[1], &want_enable)) {
if (want_enable
&& !platform_target_get_power()
&& platform_target_voltage_sense() > POWER_CONFLICT_THRESHOLD) {
if (want_enable && !platform_target_get_power() &&
platform_target_voltage_sense() > POWER_CONFLICT_THRESHOLD) {
/* want to enable target power, but VREF > 0.5V sensed -> cancel */
gdb_outf("Target already powered (%s)\n", platform_target_voltage());
} else {
@ -493,8 +485,9 @@ static bool cmd_target_power(target *t, int argc, const char **argv)
#endif
#ifdef ENABLE_RTT
const char* onoroffstr[2] = {"off", "on"};
static const char* onoroff(bool bval) {
const char *onoroffstr[2] = {"off", "on"};
static const char *onoroff(bool bval)
{
return bval ? onoroffstr[1] : onoroffstr[0];
}
@ -504,27 +497,25 @@ static bool cmd_rtt(target *t, int argc, const char **argv)
if ((argc == 1) || ((argc == 2) && !strncmp(argv[1], "enabled", strlen(argv[1])))) {
rtt_enabled = true;
rtt_found = false;
}
else if ((argc == 2) && !strncmp(argv[1], "disabled", strlen(argv[1]))) {
} else if ((argc == 2) && !strncmp(argv[1], "disabled", strlen(argv[1]))) {
rtt_enabled = false;
rtt_found = false;
}
else if ((argc == 2) && !strncmp(argv[1], "status", strlen(argv[1]))) {
gdb_outf("rtt: %s found: %s ident: ",
onoroff(rtt_enabled), rtt_found ? "yes" : "no");
} else if ((argc == 2) && !strncmp(argv[1], "status", strlen(argv[1]))) {
gdb_outf("rtt: %s found: %s ident: ", onoroff(rtt_enabled), rtt_found ? "yes" : "no");
if (rtt_ident[0] == '\0')
gdb_out("off");
else
gdb_outf("\"%s\"", rtt_ident);
gdb_outf(" halt: %s", onoroff(target_no_background_memory_access(t)));
gdb_out(" channels: ");
if (rtt_auto_channel) gdb_out("auto ");
if (rtt_auto_channel)
gdb_out("auto ");
for (uint32_t i = 0; i < MAX_RTT_CHAN; i++)
if (rtt_channel[i].is_enabled) gdb_outf("%d ", i);
gdb_outf("\nmax poll ms: %u min poll ms: %u max errs: %u\n",
rtt_max_poll_ms, rtt_min_poll_ms, rtt_max_poll_errs);
}
else if ((argc >= 2) && !strncmp(argv[1], "channel", strlen(argv[1]))) {
if (rtt_channel[i].is_enabled)
gdb_outf("%d ", i);
gdb_outf(
"\nmax poll ms: %u min poll ms: %u max errs: %u\n", rtt_max_poll_ms, rtt_min_poll_ms, rtt_max_poll_errs);
} else if ((argc >= 2) && !strncmp(argv[1], "channel", strlen(argv[1]))) {
/* mon rtt channel switches to auto rtt channel selection
mon rtt channel number... selects channels given */
for (uint32_t i = 0; i < MAX_RTT_CHAN; i++)
@ -539,42 +530,39 @@ static bool cmd_rtt(target *t, int argc, const char **argv)
rtt_channel[chan].is_enabled = true;
}
}
}
else if ((argc == 2) && !strncmp(argv[1], "ident", strlen(argv[1]))) {
} else if ((argc == 2) && !strncmp(argv[1], "ident", strlen(argv[1]))) {
rtt_ident[0] = '\0';
}
else if ((argc == 2) && !strncmp(argv[1], "poll", strlen(argv[1])))
} else if ((argc == 2) && !strncmp(argv[1], "poll", strlen(argv[1])))
gdb_outf("%u %u %u\n", rtt_max_poll_ms, rtt_min_poll_ms, rtt_max_poll_errs);
else if ((argc == 2) && !strncmp(argv[1], "cblock", strlen(argv[1]))) {
gdb_outf("cbaddr: 0x%x\n", rtt_cbaddr);
gdb_out("ch ena cfg i/o buf@ size head@ tail@ flg\n");
for (uint32_t i = 0; i < MAX_RTT_CHAN; i++) {
gdb_outf("%2d %c %c %s 0x%08x %5d 0x%08x 0x%08x %d\n",
i, rtt_channel[i].is_enabled ? 'y' : 'n', rtt_channel[i].is_configured ? 'y' : 'n',
rtt_channel[i].is_output ? "out" : "in ", rtt_channel[i].buf_addr, rtt_channel[i].buf_size,
rtt_channel[i].head_addr, rtt_channel[i].tail_addr, rtt_channel[i].flag);
gdb_outf("%2d %c %c %s 0x%08x %5d 0x%08x 0x%08x %d\n", i, rtt_channel[i].is_enabled ? 'y' : 'n',
rtt_channel[i].is_configured ? 'y' : 'n', rtt_channel[i].is_output ? "out" : "in ",
rtt_channel[i].buf_addr, rtt_channel[i].buf_size, rtt_channel[i].head_addr, rtt_channel[i].tail_addr,
rtt_channel[i].flag);
}
}
else if ((argc == 3) && !strncmp(argv[1], "ident", strlen(argv[1]))) {
} else if ((argc == 3) && !strncmp(argv[1], "ident", strlen(argv[1]))) {
strncpy(rtt_ident, argv[2], sizeof(rtt_ident));
rtt_ident[sizeof(rtt_ident)-1] = '\0';
rtt_ident[sizeof(rtt_ident) - 1] = '\0';
for (uint32_t i = 0; i < sizeof(rtt_ident); i++)
if (rtt_ident[i] == '_') rtt_ident[i] = ' ';
}
else if ((argc == 5) && !strncmp(argv[1], "poll", strlen(argv[1]))) {
if (rtt_ident[i] == '_')
rtt_ident[i] = ' ';
} else if ((argc == 5) && !strncmp(argv[1], "poll", strlen(argv[1]))) {
/* set polling params */
int32_t new_max_poll_ms = atoi(argv[2]);
int32_t new_min_poll_ms = atoi(argv[3]);
int32_t new_max_poll_errs = atoi(argv[4]);
if ((new_max_poll_ms >= 0) && (new_min_poll_ms >= 0) && (new_max_poll_errs >= 0)
&& (new_max_poll_ms >= new_min_poll_ms)) {
if ((new_max_poll_ms >= 0) && (new_min_poll_ms >= 0) && (new_max_poll_errs >= 0) &&
(new_max_poll_ms >= new_min_poll_ms)) {
rtt_max_poll_ms = new_max_poll_ms;
rtt_min_poll_ms = new_min_poll_ms;
rtt_max_poll_errs = new_max_poll_errs;
}
else gdb_out("how?\n");
}
else gdb_out("what?\n");
} else
gdb_out("how?\n");
} else
gdb_out("what?\n");
return true;
}
#endif
@ -593,17 +581,18 @@ static bool cmd_traceswo(target *t, int argc, const char **argv)
/* argument: optional baud rate for async mode */
if ((argc > 1) && (*argv[1] >= '0') && (*argv[1] <= '9')) {
baudrate = atoi(argv[1]);
if (baudrate == 0) baudrate = SWO_DEFAULT_BAUD;
if (baudrate == 0)
baudrate = SWO_DEFAULT_BAUD;
decode_arg = 2;
}
#endif
/* argument: 'decode' literal */
if((argc > decode_arg) && !strncmp(argv[decode_arg], "decode", strlen(argv[decode_arg]))) {
if ((argc > decode_arg) && !strncmp(argv[decode_arg], "decode", strlen(argv[decode_arg]))) {
swo_channelmask = 0xFFFFFFFF; /* decoding all channels */
/* arguments: channels to decode */
if (argc > decode_arg + 1) {
swo_channelmask = 0x0;
for (int i = decode_arg+1; i < argc; i++) { /* create bitmask of channels to decode */
for (int i = decode_arg + 1; i < argc; i++) { /* create bitmask of channels to decode */
int channel = atoi(argv[i]);
if ((channel >= 0) && (channel <= 31))
swo_channelmask |= (uint32_t)0x1 << channel;
@ -616,7 +605,7 @@ static bool cmd_traceswo(target *t, int argc, const char **argv)
gdb_outf("baudrate: %lu ", baudrate);
#endif
gdb_outf("channel mask: ");
for (int8_t i=31;i>=0;i--) {
for (int8_t i = 31; i >= 0; i--) {
uint8_t bit = (swo_channelmask >> i) & 0x1;
gdb_outf("%u", bit);
}
@ -650,23 +639,24 @@ static bool cmd_debug_bmp(target *t, int argc, const char **argv)
}
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
static bool cmd_heapinfo(target *t, int argc, const char **argv)
{
if (t == NULL) gdb_out("not attached\n");
if (t == NULL)
gdb_out("not attached\n");
else if (argc == 5) {
target_addr heap_base = strtoul(argv[1], NULL, 16);
target_addr heap_limit = strtoul(argv[2], NULL, 16);
target_addr stack_base = strtoul(argv[3], NULL, 16);
target_addr stack_limit = strtoul(argv[4], NULL, 16);
gdb_outf("heapinfo heap_base: %p heap_limit: %p stack_base: %p stack_limit: %p\n",
heap_base, heap_limit, stack_base, stack_limit);
gdb_outf("heapinfo heap_base: %p heap_limit: %p stack_base: %p stack_limit: %p\n", heap_base, heap_limit,
stack_base, stack_limit);
target_set_heapinfo(t, heap_base, heap_limit, stack_base, stack_limit);
} else gdb_outf("heapinfo heap_base heap_limit stack_base stack_limit\n");
} else
gdb_outf("heapinfo heap_base heap_limit stack_base stack_limit\n");
return true;
}