27 #ifdef _DEBUG_FREE_SPACE_
31 #error "malloc.h is required to use --enable-malloc-logging"
56 static void log_forward(
const char *file,
unsigned int line,
const char *
function,
const char *
string)
63 cb->
fn(cb->
priv, file, line,
function,
string);
88 fputs(
string, stderr);
100 f = strrchr(file,
'/');
107 #ifdef _DEBUG_FREE_SPACE_
108 struct mallinfo
info;
111 fprintf(
log_output,
"%s%d %" PRId64
" %s:%d %s()"
112 #ifdef _DEBUG_FREE_SPACE_
116 #ifdef _DEBUG_FREE_SPACE_
137 const char *
function,
148 va_start(ap, format);
152 log_puts(level, file, line,
function,
string);
160 const char *
function,
const char *format, va_list args)
179 log_puts(level, file, line,
function, tmp);
186 const char *
function,
192 va_start(ap, format);
243 .
name =
"log_output",
244 .handler = handle_log_output_command,
246 .help =
"redirect logging to a file (default: stderr)",
247 .usage =
"[file_name | 'default']",
250 .name =
"debug_level",
251 .handler = handle_debug_level_command,
253 .help =
"Sets the verbosity level of debugging output. "
254 "0 shows errors only; 1 adds warnings; "
255 "2 (default) adds other info; 3 adds debugging; "
256 "4 adds extra verbose debugging.",
271 char *debug_env = getenv(
"OPENOCD_DEBUG_LEVEL");
274 int retval = parse_int(debug_env, &value);
346 va_copy(ap_copy, ap);
347 len = vsnprintf(
NULL, 0, fmt, ap_copy);
354 string = malloc(len + 2);
359 vsnprintf(
string, len + 1, fmt, ap);
368 va_start(ap, format);
395 #define KEEP_ALIVE_KICK_TIME_MS 500
396 #define KEEP_ALIVE_TIMEOUT_MS 1000
402 "%d ms timelimit. GDB alive packet not "
403 "sent! (%" PRId64
" ms). Workaround: increase "
404 "\"set remotetimeout\" in GDB",
408 LOG_DEBUG(
"keep_alive() was not invoked in the "
409 "%d ms timelimit (%" PRId64
" ms). This may cause "
410 "trouble with GDB connections.",
418 int64_t delta_time = current_time -
last_time;
447 int64_t delta_time = current_time -
last_time;
458 uint64_t nap_time = 10;
459 for (uint64_t i = 0; i < ms; i += nap_time) {
460 uint64_t sleep_a_bit = ms - i;
461 if (sleep_a_bit > nap_time)
462 sleep_a_bit = nap_time;
464 usleep(sleep_a_bit * 1000);
480 #define MAX_SOCKET_ERR_MSG_LENGTH 256
488 error_code = WSAGetLastError();
490 error_message[0] =
'\0';
491 DWORD retval = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error_code, 0,
494 const bool have_message = (retval != 0) && (error_message[0] !=
'\0');
495 LOG_ERROR(
"Error on socket '%s': WSAGetLastError==%d%s%s.", socket_desc, error_code,
496 (have_message ?
", message: " :
""),
497 (have_message ? error_message :
""));
500 LOG_ERROR(
"Error on socket '%s': errno==%d, message: %s.", socket_desc, error_code, strerror(error_code));
510 for (
unsigned int i = 0; i < buf_len; i++) {
511 if (!isprint(buf[i]))
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
static struct esp_usb_jtag * priv
int gdb_get_actual_connections(void)
int log_remove_callback(log_callback_fn fn, void *priv)
int log_register_commands(struct command_context *cmd_ctx)
void log_printf_lf(enum log_levels level, const char *file, unsigned int line, const char *function, const char *format,...)
void log_init(void)
Initialize logging module.
void log_printf(enum log_levels level, const char *file, unsigned int line, const char *function, const char *format,...)
int log_add_callback(log_callback_fn fn, void *priv)
static const struct command_registration log_command_handlers[]
char * alloc_vprintf(const char *fmt, va_list ap)
static void gdb_timeout_warning(int64_t delta_time)
void alive_sleep(uint64_t ms)
static void log_forward(const char *file, unsigned int line, const char *function, const char *string)
void busy_sleep(uint64_t ms)
static struct log_callback * log_callbacks
COMMAND_HANDLER(handle_debug_level_command)
void log_socket_error(const char *socket_desc)
#define MAX_SOCKET_ERR_MSG_LENGTH
#define KEEP_ALIVE_TIMEOUT_MS
void log_vprintf_lf(enum log_levels level, const char *file, unsigned int line, const char *function, const char *format, va_list args)
const char * find_nonprint_char(const char *buf, unsigned int buf_len)
Find the first non-printable character in the char buffer, return a pointer to it.
#define KEEP_ALIVE_KICK_TIME_MS
char * alloc_printf(const char *format,...)
static void log_puts(enum log_levels level, const char *file, int line, const char *function, const char *string)
static const char *const log_strings[6]
void(* log_callback_fn)(void *priv, const char *file, unsigned int line, const char *function, const char *string)
#define LOG_WARNING(expr ...)
#define ERROR_BUF_TOO_SMALL
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
void server_keep_clients_alive(void)
struct log_callback * next
static struct ublast_lowlevel_priv info