return nwords;
}
-void command_print(command_context_t *context, char *format, ...)
+static void command_printv(command_context_t *context, char *format, va_list ap)
{
char *buffer = NULL;
int n, size = 0;
/* process format string */
for (;;)
{
- va_list ap;
- va_start(ap, format);
if (!buffer || (n = vsnprintf(buffer, size, format, ap)) >= size)
{
/* increase buffer until it fits the whole string */
/* gotta free up */
if (buffer)
free(buffer);
- va_end(ap);
return;
}
buffer = p;
- va_end(ap);
continue;
}
- va_end(ap);
break;
}
return;
}
- p = buffer;
+ context->output_handler(context, buffer);
- /* process lines in buffer */
- do {
- char *next = strchr(p, '\n');
-
- if (next)
- *next++ = 0;
+ if (buffer)
+ free(buffer);
+}
- if (context->output_handler)
- context->output_handler(context, p);
+void command_print_sameline(command_context_t *context, char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ command_printv(context, format, ap);
+ va_end(ap);
+}
- p = next;
- } while (p);
+void command_print(command_context_t *context, char *format, ...)
+{
+ char *t=malloc(strlen(format)+2);
+ strcpy(t, format);
+ strcat(t, "\n");
+ va_list ap;
+ va_start(ap, format);
+ command_printv(context, t, ap);
+ va_end(ap);
+ free(t);
- if (buffer)
- free(buffer);
}
int find_and_run_command(command_context_t *context, command_t *commands, char *words[], int num_words, int start_word)
if (*line && (line[0] == '#'))
return ERROR_OK;
- if (context->echo)
- {
- command_print(context, "%s", line);
- }
+ DEBUG("%s", line);
nwords = parse_line(line, words, sizeof(words) / sizeof(words[0]));
context->mode = COMMAND_EXEC;
context->commands = NULL;
context->current_target = 0;
- context->echo = 0;
context->output_handler = NULL;
context->output_handler_priv = NULL;
enum command_mode mode;
struct command_s *commands;
int current_target;
- int echo;
int (*output_handler)(struct command_context_s *context, char* line);
void *output_handler_priv;
} command_context_t;
extern command_context_t* command_init();
extern int command_done(command_context_t *context);
extern void command_print(command_context_t *context, char *format, ...);
+extern void command_print_sameline(command_context_t *context, char *format, ...);
extern int command_run_line(command_context_t *context, char *line);
extern int command_run_file(command_context_t *context, FILE *file, enum command_mode mode);
int handle_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
FILE *script_file;
- int echo;
if (argc != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
command_print(cmd_ctx, "couldn't open script file %s", args[0]);
return ERROR_OK;
}
-
- echo = cmd_ctx->echo;
- cmd_ctx->echo = 1;
command_run_file(cmd_ctx, script_file, cmd_ctx->mode);
- cmd_ctx->echo = echo;
-
fclose(script_file);
return ERROR_OK;
"Debug: "
};
-void log_printf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...)
+static int count = 0;
+
+static void log_printfv(enum log_levels level, const char *file, int line, const char *function, const char *format, va_list args)
{
- static int count = 0;
- count++;
- va_list args;
char buffer[512];
log_callback_t *cb;
- if (level > debug_level)
- return;
-
- va_start(args, format);
vsnprintf(buffer, 512, format, args);
- va_end(args);
if (level == LOG_OUTPUT)
{
if (debug_level >= LOG_DEBUG)
{
/* print with count and time information */
- time_t t=time(NULL)-start;
- fprintf(log_output, "%s %d %ld %s:%d %s(): %s\n", log_strings[level+1], count, t, file, line, function, buffer);
+ int t=(int)(time(NULL)-start);\r
+ fprintf(log_output, "%s %d %d %s:%d %s(): %s\n", log_strings[level+1], count, t, file, line, function, buffer);\r
}
else
{
{
for (cb = log_callbacks; cb; cb = cb->next)
{
- va_start(args, format);
cb->fn(cb->priv, file, line, function, format, args);
- va_end(args);
}
}
}
+void log_printf(enum log_levels level, const char *file, int line, const char *function, const char *format, ...)
+{
+ count++;
+ if (level > debug_level)
+ return;
+
+ va_list args;
+ va_start(args, format);
+ log_printfv(level, file, line, function, format, args);
+ va_end(args);
+
+}
+
+void log_printfnl(enum log_levels level, const char *file, int line, const char *function, const char *format, ...)
+{
+ count++;
+ if (level > debug_level)
+ return;
+
+ char *t=malloc(strlen(format)+2);
+ strcpy(t, format);
+ strcat(t, "\n");
+
+ va_list args;
+ va_start(args, format);
+ log_printfv(level, file, line, function, t, args);
+ va_end(args);
+}
+
/* change the current debug level on the fly
* 0: only ERRORS
* 1: + WARNINGS
extern void log_printf(enum log_levels level, const char *file, int line,
const char *function, const char *format, ...)
- __attribute__ ((format (printf, 5, 6)));
+__attribute__ ((format (printf, 5, 6)));
+extern void log_printfnl(enum log_levels level, const char *file, int line,
+ const char *function, const char *format, ...)
+__attribute__ ((format (printf, 5, 6)));
extern int log_register_commands(struct command_context_s *cmd_ctx);
extern int log_init(struct command_context_s *cmd_ctx);
extern int set_log_output(struct command_context_s *cmd_ctx, FILE *output);
/* Avoid fn call and building parameter list if we're not outputting the information.
* Matters on feeble CPUs for DEBUG/INFO statements that are involved frequently */
+
#define DEBUG(expr ...) \
do { if (debug_level >= LOG_DEBUG) \
- log_printf (LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr); \
+ log_printfnl (LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define INFO(expr ...) \
do { if (debug_level >= LOG_INFO) \
- log_printf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr); \
+ log_printfnl (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define WARNING(expr ...) \
do { \
- log_printf (LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, expr); \
+ log_printfnl (LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define ERROR(expr ...) \
do { \
- log_printf (LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, expr); \
+ log_printfnl (LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define USER(expr ...) \
+ do { \
+ log_printfnl (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr); \
+ } while(0)
+
+#define USER_SAMELINE(expr ...) \
do { \
log_printf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
#define OUTPUT(expr ...) \
do { \
- log_printf (LOG_OUTPUT, __FILE__, __LINE__, __FUNCTION__, expr); \
+ log_printfnl (LOG_OUTPUT, __FILE__, __LINE__, __FUNCTION__, expr); \
} while(0)
bin_size = strlen(line);
- hex_buffer = malloc(bin_size*2 + 4);
+ hex_buffer = malloc(bin_size*2 + 2);
hex_buffer[0] = 'O';
for (i=0; i<bin_size; i++)
snprintf(hex_buffer + 1 + i*2, 3, "%2.2x", line[i]);
- hex_buffer[bin_size*2+1] = '0';
- hex_buffer[bin_size*2+2] = 'a';
- hex_buffer[bin_size*2+3] = 0x0;
+ hex_buffer[bin_size*2+1] = 0;
- gdb_put_packet(connection, hex_buffer, bin_size*2 + 3);
+ gdb_put_packet(connection, hex_buffer, bin_size*2 + 1);
free(hex_buffer);
return ERROR_OK;
int gdb_output(struct command_context_s *context, char* line)
{
/* this will be dumped to the log and also sent as an O packet if possible */
- USER(line);
+ USER_SAMELINE(line);
return ERROR_OK;
}
return ERROR_OK;
}
-
+\r
+\r
int gdb_new_connection(connection_t *connection)
{
gdb_connection_t *gdb_connection = malloc(sizeof(gdb_connection_t));
int telnet_outputline(connection_t *connection, char* line)
{
- telnet_write(connection, line, strlen(line));
- return telnet_write(connection, "\r\n\0", 3);
+
+ /* process lines in buffer */
+ char *p=line;
+ do {
+ char *next = strchr(p, '\n');
+
+ if (next)
+ *next++ = 0;
+
+
+ telnet_write(connection, p, strlen(p));
+ if (next)
+ {
+ telnet_write(connection, "\r\n\0", 3);
+ }
+
+ p = next;
+ } while (p);
+
+ return ERROR_OK;
}
int telnet_output(struct command_context_s *cmd_ctx, char* line)
{
connection_t *connection = priv;
char *t = alloc_printf(format, args);
- char *t2;
if (t == NULL)
return;
- t2=t;
- char *endline;
- do
- {
- if ((endline=strchr(t2, '\n'))!=NULL)
- {
- *endline=0;
- }
- telnet_outputline(connection, t2);
- t2=endline+1;
- } while (endline);
+ telnet_outputline(connection, t);
free(t);
}
return ERROR_OK;
}
+int target_charmsg(target_t *target, u8 msg)
+{
+ USER_SAMELINE("%c", msg);
+
+ return ERROR_OK;
+}
+
int target_hexmsg(target_t *target, int size, u32 length)
{
u8 *data = malloc(CEIL(length * size, 4) * 4);
target_hexmsg(target, (request & 0xff00) >> 8, (request & 0xffff0000) >> 16);
}
break;
+ case TARGET_REQ_DEBUGCHAR:
+ target_charmsg(target, (request & 0x00ff0000) >> 16);
+ break;
/* case TARGET_REQ_SEMIHOSTING:
* break;
*/
{
TARGET_REQ_TRACEMSG,
TARGET_REQ_DEBUGMSG,
+ TARGET_REQ_DEBUGCHAR,
/* TARGET_REQ_SEMIHOSTING, */
} target_req_cmd_t;