26 #ifdef _DEBUG_FREE_SPACE_
30 #error "malloc.h is required to use --enable-malloc-logging"
55 static void log_forward(
const char *file,
unsigned line,
const char *
function,
const char *
string)
62 cb->
fn(cb->
priv, file, line,
function,
string);
87 fputs(
string, stderr);
99 f = strrchr(file,
'/');
106 #ifdef _DEBUG_FREE_SPACE_
107 struct mallinfo
info;
110 fprintf(
log_output,
"%s%d %" PRId64
" %s:%d %s()"
111 #ifdef _DEBUG_FREE_SPACE_
115 #ifdef _DEBUG_FREE_SPACE_
136 const char *
function,
147 va_start(ap, format);
151 log_puts(level, file, line,
function,
string);
159 const char *
function,
const char *format, va_list args)
178 log_puts(level, file, line,
function, tmp);
185 const char *
function,
191 va_start(ap, format);
226 FILE *file = fopen(
CMD_ARGV[0],
"w");
245 .
name =
"log_output",
246 .handler = handle_log_output_command,
248 .help =
"redirect logging to a file (default: stderr)",
249 .usage =
"[file_name | \"default\"]",
252 .name =
"debug_level",
253 .handler = handle_debug_level_command,
255 .help =
"Sets the verbosity level of debugging output. "
256 "0 shows errors only; 1 adds warnings; "
257 "2 (default) adds other info; 3 adds debugging; "
258 "4 adds extra verbose debugging.",
273 char *debug_env = getenv(
"OPENOCD_DEBUG_LEVEL");
276 int retval = parse_int(debug_env, &value);
348 va_copy(ap_copy, ap);
349 len = vsnprintf(
NULL, 0, fmt, ap_copy);
356 string = malloc(len + 2);
361 vsnprintf(
string, len + 1, fmt, ap);
370 va_start(ap, format);
397 #define KEEP_ALIVE_KICK_TIME_MS 500
398 #define KEEP_ALIVE_TIMEOUT_MS 1000
406 "%d ms timelimit. GDB alive packet not "
407 "sent! (%" PRId64
" ms). Workaround: increase "
408 "\"set remotetimeout\" in GDB",
412 LOG_DEBUG(
"keep_alive() was not invoked in the "
413 "%d ms timelimit (%" PRId64
" ms). This may cause "
414 "trouble with GDB connections.",
422 int64_t delta_time = current_time -
last_time;
451 int64_t delta_time = current_time -
last_time;
462 uint64_t nap_time = 10;
463 for (uint64_t i = 0; i < ms; i += nap_time) {
464 uint64_t sleep_a_bit = ms - i;
465 if (sleep_a_bit > nap_time)
466 sleep_a_bit = nap_time;
468 usleep(sleep_a_bit * 1000);
484 #define MAX_SOCKET_ERR_MSG_LENGTH 256
492 error_code = WSAGetLastError();
494 error_message[0] =
'\0';
495 DWORD retval = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error_code, 0,
498 const bool have_message = (retval != 0) && (error_message[0] !=
'\0');
499 LOG_ERROR(
"Error on socket '%s': WSAGetLastError==%d%s%s.", socket_desc, error_code,
500 (have_message ?
", message: " :
""),
501 (have_message ? error_message :
""));
504 LOG_ERROR(
"Error on socket '%s': errno==%d, message: %s.", socket_desc, error_code, strerror(error_code));
514 for (
unsigned int i = 0; i < buf_len; i++) {
515 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_actual_connections
int log_remove_callback(log_callback_fn fn, void *priv)
void log_printf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format,...)
void log_printf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format,...)
int log_register_commands(struct command_context *cmd_ctx)
void log_init(void)
Initialize logging module.
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)
char * find_nonprint_char(char *buf, unsigned buf_len)
Find the first non-printable character in the char buffer, return a pointer to it.
void alive_sleep(uint64_t ms)
void busy_sleep(uint64_t ms)
static struct log_callback * log_callbacks
void log_vprintf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format, va_list args)
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
#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]
static void log_forward(const char *file, unsigned 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(* log_callback_fn)(void *priv, const char *file, unsigned line, const char *function, const char *string)
void server_keep_clients_alive(void)
struct log_callback * next
static struct ublast_lowlevel_priv info