This reduces the number of gdb conversion routines we have to maintain.
Change-Id: Ia43d6cac86cbe4f76fe0875b9d9c16ac340296db
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/1128
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
static int gdb_error(struct connection *connection, int retval);
static const char *gdb_port;
static const char *gdb_port_next;
static int gdb_error(struct connection *connection, int retval);
static const char *gdb_port;
static const char *gdb_port_next;
-static const char DIGITS[16] = "0123456789abcdef";
static void gdb_log_callback(void *priv, const char *file, unsigned line,
const char *function, const char *string);
static void gdb_log_callback(void *priv, const char *file, unsigned line,
const char *function, const char *string);
if ((size_t)len + 4 <= sizeof(local_buffer)) {
/* performance gain on smaller packets by only a single call to gdb_write() */
memcpy(local_buffer + 1, buffer, len++);
if ((size_t)len + 4 <= sizeof(local_buffer)) {
/* performance gain on smaller packets by only a single call to gdb_write() */
memcpy(local_buffer + 1, buffer, len++);
- local_buffer[len++] = '#';
- local_buffer[len++] = DIGITS[(my_checksum >> 4) & 0xf];
- local_buffer[len++] = DIGITS[my_checksum & 0xf];
+ len += snprintf(local_buffer + len, sizeof(local_buffer) - len, "#%02x", my_checksum);
retval = gdb_write(connection, local_buffer, len);
if (retval != ERROR_OK)
return retval;
} else {
/* larger packets are transmitted directly from caller supplied buffer
* by several calls to gdb_write() to avoid dynamic allocation */
retval = gdb_write(connection, local_buffer, len);
if (retval != ERROR_OK)
return retval;
} else {
/* larger packets are transmitted directly from caller supplied buffer
* by several calls to gdb_write() to avoid dynamic allocation */
- local_buffer[1] = '#';
- local_buffer[2] = DIGITS[(my_checksum >> 4) & 0xf];
- local_buffer[3] = DIGITS[my_checksum & 0xf];
+ snprintf(local_buffer + 1, sizeof(local_buffer) - 1, "#%02x", my_checksum);
retval = gdb_write(connection, local_buffer, 1);
if (retval != ERROR_OK)
return retval;
retval = gdb_write(connection, local_buffer, 1);
if (retval != ERROR_OK)
return retval;
-static int gdb_reg_pos(struct target *target, int pos, int len)
+static inline int gdb_reg_pos(struct target *target, int pos, int len)
{
if (target->endianness == TARGET_LITTLE_ENDIAN)
return pos;
{
if (target->endianness == TARGET_LITTLE_ENDIAN)
return pos;
for (i = 0; i < buf_len; i++) {
int j = gdb_reg_pos(target, i, buf_len);
for (i = 0; i < buf_len; i++) {
int j = gdb_reg_pos(target, i, buf_len);
- tstr[i*2] = DIGITS[(buf[j]>>4) & 0xf];
- tstr[i*2 + 1] = DIGITS[buf[j]&0xf];
+ tstr += sprintf(tstr, "%02x", buf[j]);
-static int hextoint(int c)
-{
- if (c >= '0' && c <= '9')
- return c - '0';
- c = toupper(c);
- if (c >= 'A' && c <= 'F')
- return c - 'A' + 10;
- LOG_ERROR("BUG: invalid register value %08x", c);
- return 0;
-}
-
/* copy over in register buffer */
static void gdb_target_to_reg(struct target *target,
char *tstr, int str_len, uint8_t *bin)
/* copy over in register buffer */
static void gdb_target_to_reg(struct target *target,
char *tstr, int str_len, uint8_t *bin)
int i;
for (i = 0; i < str_len; i += 2) {
int i;
for (i = 0; i < str_len; i += 2) {
- uint8_t t = hextoint(tstr[i]) << 4;
- t |= hextoint(tstr[i + 1]);
+ unsigned t;
+ if (sscanf(tstr + i, "%02x", &t) != 1) {
+ LOG_ERROR("BUG: unable to convert register value");
+ exit(-1);
+ }
int j = gdb_reg_pos(target, i/2, str_len/2);
bin[j] = t;
int j = gdb_reg_pos(target, i/2, str_len/2);
bin[j] = t;
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)