aboutsummaryrefslogtreecommitdiff
path: root/ncurses/trace
diff options
context:
space:
mode:
Diffstat (limited to 'ncurses/trace')
-rw-r--r--ncurses/trace/lib_trace.c99
-rw-r--r--ncurses/trace/lib_traceatr.c26
-rw-r--r--ncurses/trace/lib_tracechr.c16
-rw-r--r--ncurses/trace/lib_tracedmp.c8
-rw-r--r--ncurses/trace/trace_buf.c10
-rw-r--r--ncurses/trace/varargs.c12
-rw-r--r--ncurses/trace/visbuf.c12
7 files changed, 120 insertions, 63 deletions
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
index 5eb87fe0c176..0904c132fee1 100644
--- a/ncurses/trace/lib_trace.c
+++ b/ncurses/trace/lib_trace.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2023,2024 Thomas E. Dickey *
* Copyright 1998-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -37,7 +37,7 @@
/*
* lib_trace.c - Tracing/Debugging routines
*
- * The _tracef() function is originally from pcurses (by Pavel Curtis) in 1982.
+ * The _tracef() function is originally from pcurses (by Pavel Curtis) in 1982.
* pcurses allowed one to enable/disable tracing using traceon() and traceoff()
* functions. ncurses provides a trace() function which allows one to
* selectively enable or disable several tracing features.
@@ -48,7 +48,7 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_trace.c,v 1.97 2020/08/29 16:22:03 juergen Exp $")
+MODULE_ID("$Id: lib_trace.c,v 1.106 2024/02/24 18:28:19 tom Exp $")
NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
@@ -89,45 +89,74 @@ NCURSES_EXPORT_VAR(long) _nc_outchars = 0;
#define MyFP _nc_globals.trace_fp
#define MyFD _nc_globals.trace_fd
#define MyInit _nc_globals.trace_opened
-#define MyPath _nc_globals.trace_fname
#define MyLevel _nc_globals.trace_level
#define MyNested _nc_globals.nested_tracef
#endif /* TRACE */
+#if USE_REENTRANT
+#define Locked(statement) \
+ do { \
+ _nc_lock_global(tst_tracef); \
+ statement; \
+ _nc_unlock_global(tst_tracef); \
+ } while (0)
+#else
+#define Locked(statement) statement
+#endif
+
NCURSES_EXPORT(unsigned)
curses_trace(unsigned tracelevel)
{
unsigned result;
+
#if defined(TRACE)
- result = _nc_tracing;
+ int bit;
+
+#define DATA(name) { name, #name }
+ static struct {
+ unsigned mask;
+ const char *name;
+ } trace_names[] = {
+ DATA(TRACE_TIMES),
+ DATA(TRACE_TPUTS),
+ DATA(TRACE_UPDATE),
+ DATA(TRACE_MOVE),
+ DATA(TRACE_CHARPUT),
+ DATA(TRACE_CALLS),
+ DATA(TRACE_VIRTPUT),
+ DATA(TRACE_IEVENT),
+ DATA(TRACE_BITS),
+ DATA(TRACE_ICALLS),
+ DATA(TRACE_CCALLS),
+ DATA(TRACE_DATABASE),
+ DATA(TRACE_ATTRS)
+ };
+#undef DATA
+
+ Locked(result = _nc_tracing);
+
if ((MyFP == 0) && tracelevel) {
MyInit = TRUE;
if (MyFD >= 0) {
MyFP = fdopen(MyFD, BIN_W);
} else {
- if (MyPath[0] == '\0') {
- size_t size = sizeof(MyPath) - 12;
- if (getcwd(MyPath, size) == 0) {
- perror("curses: Can't get working directory");
- exit(EXIT_FAILURE);
- }
- MyPath[size] = '\0';
- assert(strlen(MyPath) <= size);
- _nc_STRCAT(MyPath, "/trace", sizeof(MyPath));
- if (_nc_is_dir_path(MyPath)) {
- _nc_STRCAT(MyPath, ".log", sizeof(MyPath));
- }
+ char myFile[80];
+
+ _nc_STRCPY(myFile, "trace", sizeof(myFile));
+ if (_nc_is_dir_path(myFile)) {
+ _nc_STRCAT(myFile, ".log", sizeof(myFile));
}
- if (_nc_access(MyPath, W_OK) < 0
- || (MyFD = open(MyPath, O_CREAT | O_EXCL | O_RDWR, 0600)) < 0
+#define SAFE_MODE (O_CREAT | O_EXCL | O_RDWR)
+ if (_nc_access(myFile, W_OK) < 0
+ || (MyFD = safe_open3(myFile, SAFE_MODE, 0600)) < 0
|| (MyFP = fdopen(MyFD, BIN_W)) == 0) {
; /* EMPTY */
}
}
- _nc_tracing = tracelevel;
+ Locked(_nc_tracing = tracelevel);
/* Try to set line-buffered mode, or (failing that) unbuffered,
* so that the trace-output gets flushed automatically at the
- * end of each line. This is useful in case the program dies.
+ * end of each line. This is useful in case the program dies.
*/
if (MyFP != 0) {
#if HAVE_SETVBUF /* ANSI */
@@ -140,15 +169,33 @@ curses_trace(unsigned tracelevel)
NCURSES_VERSION,
NCURSES_VERSION_PATCH,
tracelevel);
+
+#define SPECIAL_MASK(mask) \
+ if ((tracelevel & mask) == mask) \
+ _tracef("- %s (%u)", #mask, mask)
+
+ for (bit = 0; bit < TRACE_SHIFT; ++bit) {
+ unsigned mask = (1U << bit) & tracelevel;
+ if ((mask & trace_names[bit].mask) != 0) {
+ _tracef("- %s (%u)", trace_names[bit].name, mask);
+ }
+ }
+ SPECIAL_MASK(TRACE_MAXIMUM);
+ else
+ SPECIAL_MASK(TRACE_ORDINARY);
+
+ if (tracelevel > TRACE_MAXIMUM) {
+ _tracef("- DEBUG_LEVEL(%u)", tracelevel >> TRACE_SHIFT);
+ }
} else if (tracelevel == 0) {
if (MyFP != 0) {
MyFD = dup(MyFD); /* allow reopen of same file */
fclose(MyFP);
MyFP = 0;
}
- _nc_tracing = tracelevel;
+ Locked(_nc_tracing = tracelevel);
} else if (_nc_tracing != tracelevel) {
- _nc_tracing = tracelevel;
+ Locked(_nc_tracing = tracelevel);
_tracef("tracelevel=%#x", tracelevel);
}
#else
@@ -213,11 +260,13 @@ _nc_va_tracef(const char *fmt, va_list ap)
# if USE_WEAK_SYMBOLS
if ((pthread_self))
# endif
+ fprintf(fp, "%#" PRIxPTR ":",
#ifdef _NC_WINDOWS
- fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self().p);
+ CASTxPTR(pthread_self().p)
#else
- fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self());
+ CASTxPTR(pthread_self())
#endif
+ );
#endif
if (before || after) {
int n;
diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c
index 940262750508..b36286253d6d 100644
--- a/ncurses/trace/lib_traceatr.c
+++ b/ncurses/trace/lib_traceatr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2022,2024 Thomas E. Dickey *
* Copyright 1998-2017,2018 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -44,7 +44,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_traceatr.c,v 1.94 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_traceatr.c,v 1.96 2024/02/04 00:11:35 tom Exp $")
#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
@@ -343,6 +343,7 @@ _tracecchar_t2(int bufnum, const cchar_t *ch)
} else {
PUTC_DATA;
int n;
+ int assume_unicode = _nc_unicode_locale()? 128 : 255;
(void) _nc_trace_bufcat(bufnum, "{ ");
for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
@@ -362,21 +363,22 @@ _tracecchar_t2(int bufnum, const cchar_t *ch)
UChar(ch->chars[PUTC_i])));
}
break;
- } else if (ch->chars[PUTC_i] > 255) {
+ } else if (ch->chars[PUTC_i] > assume_unicode) {
char temp[80];
_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
- "{%d:\\u%lx}",
+ "{%d:\\u%04lx}",
_nc_wacs_width(ch->chars[PUTC_i]),
(unsigned long) ch->chars[PUTC_i]);
(void) _nc_trace_bufcat(bufnum, temp);
- break;
- }
- for (n = 0; n < PUTC_n; n++) {
- if (n)
- (void) _nc_trace_bufcat(bufnum, ", ");
- (void) _nc_trace_bufcat(bufnum,
- _nc_tracechar(CURRENT_SCREEN,
- UChar(PUTC_buf[n])));
+ attr &= ~A_CHARTEXT; /* ignore WidecExt(ch) */
+ } else {
+ for (n = 0; n < PUTC_n; n++) {
+ if (n)
+ (void) _nc_trace_bufcat(bufnum, ", ");
+ (void) _nc_trace_bufcat(bufnum,
+ _nc_tracechar(CURRENT_SCREEN,
+ UChar(PUTC_buf[n])));
+ }
}
}
(void) _nc_trace_bufcat(bufnum, " }");
diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c
index 36158d6f45a6..9c879dc67397 100644
--- a/ncurses/trace/lib_tracechr.c
+++ b/ncurses/trace/lib_tracechr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2024 Thomas E. Dickey *
* Copyright 1998-2009,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -40,7 +40,7 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_tracechr.c,v 1.23 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_tracechr.c,v 1.24 2024/02/04 00:11:35 tom Exp $")
#ifdef TRACE
@@ -54,26 +54,28 @@ _nc_tracechar(SCREEN *sp, int ch)
? sp->tracechr_buf
: _nc_globals.tracechr_buf);
- if (ch > KEY_MIN || ch < 0) {
+ if ((ch > KEY_MIN && !_nc_unicode_locale()) || ch < 0) {
name = safe_keyname(SP_PARM, ch);
if (name == 0 || *name == '\0')
name = "NULL";
_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
- "'%.30s' = %#03o", name, ch);
- } else if (!is8bits(ch) || !isprint(UChar(ch))) {
+ "'%.30s' = \\x%02x", name, ch);
+ } else if (!is8bits(ch)
+ || (_nc_unicode_locale() && !is7bits(ch))
+ || !isprint(UChar(ch))) {
/*
* workaround for glibc bug:
* sprintf changes the result from unctrl() to an empty string if it
* does not correspond to a valid multibyte sequence.
*/
_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
- "%#03o", ch);
+ "\\x%02x", ch);
} else {
name = safe_unctrl(SP_PARM, (chtype) ch);
if (name == 0 || *name == 0)
name = "null"; /* shouldn't happen */
_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
- "'%.30s' = %#03o", name, ch);
+ "'%.30s' = \\x%02x", name, ch);
}
return (MyBuffer);
}
diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
index 3b7ea0749986..529148bb785a 100644
--- a/ncurses/trace/lib_tracedmp.c
+++ b/ncurses/trace/lib_tracedmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2012,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -40,7 +40,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_tracedmp.c,v 1.36 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: lib_tracedmp.c,v 1.37 2023/06/24 15:49:45 tom Exp $")
#ifdef TRACE
@@ -71,9 +71,9 @@ _tracedump(const char *name, WINDOW *win)
if (++width + 1 > (int) my_length) {
my_length = (unsigned) (2 * (width + 1));
my_buffer = typeRealloc(char, my_length, my_buffer);
- if (my_buffer == 0)
- return;
}
+ if (my_buffer == 0)
+ return;
for (n = 0; n <= win->_maxy; ++n) {
char *ep = my_buffer;
diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c
index 7e6384b54153..91b12e45c248 100644
--- a/ncurses/trace/trace_buf.c
+++ b/ncurses/trace/trace_buf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 1998-2011,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -36,7 +36,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_buf.c,v 1.21 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: trace_buf.c,v 1.22 2023/06/24 13:37:25 tom Exp $")
#ifdef TRACE
@@ -104,7 +104,11 @@ _nc_trace_buf(int bufnum, size_t want)
NCURSES_EXPORT(char *)
_nc_trace_bufcat(int bufnum, const char *value)
{
- char *buffer = _nc_trace_alloc(bufnum, (size_t) 0);
+ char *buffer;
+
+ if (value == NULL)
+ value = "";
+ buffer = _nc_trace_alloc(bufnum, (size_t) 0);
if (buffer != 0) {
size_t have = strlen(buffer);
size_t need = strlen(value) + have;
diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c
index 9be5fc254fb0..7b9533bd62f4 100644
--- a/ncurses/trace/varargs.c
+++ b/ncurses/trace/varargs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2020 Thomas E. Dickey *
+ * Copyright 2020,2023 Thomas E. Dickey *
* Copyright 2001-2008,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -35,7 +35,7 @@
#include <ctype.h>
-MODULE_ID("$Id: varargs.c,v 1.12 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: varargs.c,v 1.13 2023/06/24 13:41:46 tom Exp $")
#ifdef TRACE
@@ -59,18 +59,16 @@ typedef enum {
NCURSES_EXPORT(char *)
_nc_varargs(const char *fmt, va_list ap)
{
- static char dummy[] = "";
-
char buffer[BUFSIZ];
const char *param;
int n;
if (fmt == 0 || *fmt == '\0')
- return dummy;
+ return NULL;
if (MyLength == 0)
MyBuffer = typeMalloc(char, MyLength = BUFSIZ);
if (MyBuffer == 0)
- return dummy;
+ return NULL;
*MyBuffer = '\0';
while (*fmt != '\0') {
@@ -185,7 +183,7 @@ _nc_varargs(const char *fmt, va_list ap)
}
}
- return (MyBuffer ? MyBuffer : dummy);
+ return (MyBuffer ? MyBuffer : NULL);
}
#else
EMPTY_MODULE(_nc_varargs)
diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c
index 5f95a6bc50c0..590e42306f51 100644
--- a/ncurses/trace/visbuf.c
+++ b/ncurses/trace/visbuf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright 2019,2020 Thomas E. Dickey *
+ * Copyright 2019-2021,2023 Thomas E. Dickey *
* Copyright 2001-2016,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
@@ -43,7 +43,7 @@
#include <tic.h>
#include <ctype.h>
-MODULE_ID("$Id: visbuf.c,v 1.52 2020/02/02 23:34:34 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.54 2023/05/27 20:13:10 tom Exp $")
#define NUM_VISBUFS 4
@@ -67,7 +67,9 @@ static const char r_brace[] = StringOf(R_BRACE);
static char *
_nc_vischar(char *tp, unsigned c LIMIT_ARG)
{
- if (c == '"' || c == '\\') {
+ if (tp == NULL) {
+ return NULL;
+ } else if (c == '"' || c == '\\') {
*tp++ = '\\';
*tp++ = (char) c;
} else if (is7bits((int) c) && (isgraph((int) c) || c == ' ')) {
@@ -283,7 +285,7 @@ _nc_viswibuf(const wint_t *buf)
/* use these functions for displaying parts of a line within a window */
NCURSES_EXPORT(const char *)
-_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
+_nc_viscbuf2(int bufnum, const NCURSES_CH_T *buf, int len)
{
char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
@@ -371,7 +373,7 @@ _nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
}
NCURSES_EXPORT(const char *)
-_nc_viscbuf(const NCURSES_CH_T * buf, int len)
+_nc_viscbuf(const NCURSES_CH_T *buf, int len)
{
return _nc_viscbuf2(0, buf, len);
}