trace(3NCURSES)

πŸ’– trace(3NCURSES) β€” the ncurses debugging girlies πŸ’–

okay so bestie, this is a page from the ncurses manual, section 3NCURSES, aka Library calls. it's all about the tracing/debugging squad. strap in πŸŽ€


✨ NAME ✨

curses_trace, trace, _tracef, _traceattr, _traceattr2, _tracecchar_t, _tracecchar_t2, _tracechar, _tracechtype, _tracechtype2, _nc_tracebits, _tracedump, _tracemouse β€” the curses debugging routines πŸ•΅οΈβ™€οΈ


✨ SYNOPSIS ✨

#include <curses.h>

unsigned curses_trace(const unsigned trace-mask);

void _tracef(const char *format, ...);

char *_traceattr(attr_t attr);
char *_traceattr2(int buffer, chtype ch);
char *_tracecchar_t(const cchar_t *string);
char *_tracecchar_t2(int buffer, const cchar_t *string);
char *_tracechar(int c);
char *_tracechtype(chtype ch);
char *_tracechtype2(int buffer, chtype ch);

void _tracedump(const char *label, WINDOW *win);
char *_nc_tracebits(void);
char *_tracemouse(const MEVENT *event);

/* deprecated */
void trace(const unsigned int trace-mask);

✨ DESCRIPTION ✨

so the curses trace routines? they're for debugging the ncurses libraries, and also for debugging applications that use the ncurses libraries. iconic. but there are some limits, and we gotta talk about them πŸ’…

  • Aside from curses_trace, the other functions are normally available only with the debugging library, e.g. libncurses_g.a.

All of the trace functions may be compiled into any model (shared, static, profile) by defining the symbol TRACE.

  • Additionally, the functions which use cchar_t are only available with the wide-character configuration of the libraries.

🌸 Functions 🌸

the main characters of this interface are:

  • curses_trace, which selectively enables different tracing features, and
  • _tracef, which writes formatted data to the trace file.

the other functions either return a pointer to a string-area (allocated by the corresponding function), or return no value at all (like _tracedump, which implements the screen dump for TRACE_UPDATE). and listen β€” the caller should not free these strings, because the allocation gets reused on successive calls. to work around the whole single-string-area-per-function situation, some of them take a buffer-number parameter, which tells the library to allocate additional string-areas. no cap.

the curses_trace function is always available, whether or not the other trace functions are available:

  • If tracing is available, calling curses_trace with a nonzero parameter updates the trace mask, and returns the previous trace mask.

When the trace mask is nonzero, ncurses creates the file β€œtrace” in the current directory for output. If the file already exists, no tracing is done. (yes really, that's the vibe check 😭)

  • If tracing is not available, curses_trace returns zero (0).

πŸ¦‹ Trace Parameter πŸ¦‹

the trace parameter is formed by logically β€œor”-ing values from the list of TRACE_xxx definitions in <curses.h>. these include:

  • TRACE_DISABLE β€” turn off tracing by passing a zero parameter.

The library flushes the output file, but retains an open file-descriptor to the trace file so that it can resume tracing later if a nonzero parameter is passed to the curses_trace function.

  • TRACE_TIMES β€” trace user and system times of updates.
  • TRACE_TPUTS β€” trace tputs(3NCURSES) calls.
  • TRACE_UPDATE β€” trace update actions, old & new screens.
  • TRACE_MOVE β€” trace cursor movement and scrolling.
  • TRACE_CHARPUT β€” trace all character outputs.
  • TRACE_ORDINARY β€” trace all update actions. The old and new screen contents are written to the trace file for each refresh.
  • TRACE_CALLS β€” trace all curses calls. The parameters for each call are traced, as well as return values.
  • TRACE_VIRTPUT β€” trace virtual character puts, i.e., calls to addch.
  • TRACE_IEVENT β€” trace low-level input processing, including timeouts.
  • TRACE_BITS β€” trace state of TTY control bits.
  • TRACE_ICALLS β€” trace internal/nested calls.
  • TRACE_CCALLS β€” trace per-character calls.
  • TRACE_DATABASE β€” trace read/write of terminfo/termcap data.
  • TRACE_ATTRS β€” trace changes to video attributes and colors.
  • TRACE_MAXIMUM β€” maximum trace level, enables all of the separate trace features.

some tracing features are enabled whenever the curses_trace parameter is nonzero. some features overlap. the specific names are used as a guideline. that's it, that's the lore 🫢

πŸ’œ Command-line Utilities πŸ’œ

the command-line utilities, like tic(1), provide a verbose option which extends the set of messages written using the curses_trace function. both of these (-v and curses_trace) use the same variable (_nc_tracing), which determines the messages which are written.

because the command-line utilities may call initialization functions such as setupterm, tgetent or use_extended_names, some of their debugging output may be directed to the trace file if the NCURSES_TRACE environment variable is set:

  • messages produced in the utility are written to the standard error.
  • messages produced by the underlying library are written to trace.

if ncurses is built without tracing, none of the latter are produced, and fewer diagnostics are provided by the command-line utilities.


✨ RETURN VALUE ✨

routines which return a value are designed to be used as parameters to the _tracef routine. cute, right? πŸ’…


✨ ENVIRONMENT ✨

🌈 NCURSES_TRACE 🌈

a positive integral value stored in this variable causes the following functions to enable the tracing feature as if curses_trace were called.

filter, initscr, new_prescr, newterm, nofilter, restartterm,
ripoffline, setupterm, slk_init, tgetent, use_env,
use_extended_names, use_tioctl

✨ PORTABILITY ✨

ngl these functions are not part of the X/Open Curses interface. some other curses implementations are known to have similar features, but they are not compatible with ncurses:

  • SVr4 provided traceon and traceoff, to control whether debugging information was written to the β€œtrace” file. While the functions were always available, this feature was only enabled if DEBUG was defined when building the library.

The SVr4 tracing feature is undocumented. πŸ’€

  • PDCurses provides traceon and traceoff, which (like SVr4) are always available, and enable tracing to the β€œtrace” file only when a debug-library is built.

PDCurses has a short description of these functions, with a note that they are not present in X/Open Curses, ncurses or NetBSD. It does not mention SVr4, but the functions' inclusion in a header file section labeled β€œQuasi-standard” hints at the origin. iykyk πŸ‘‘

  • NetBSD does not provide functions for enabling/disabling traces. It uses environment variables CURSES_TRACE_MASK and CURSES_TRACE_FILE to determine what is traced, and where the results are written. This is available only when a debug-library is built.

The NetBSD tracing feature is undocumented. πŸ’€

a few ncurses functions are not provided when symbol versioning is used:

_nc_tracebits, _tracedump, _tracemouse

the original trace routine was deprecated because it often conflicted with application names. yeah. that's the whole reason. πŸ™ˆ


✨ SEE ALSO ✨

ncurses(3NCURSES)


and that's a wrap bestie!! this was ncurses 6.6, dated 2025-01-18, and you just read trace(3NCURSES). go forth and trace responsibly, mwah πŸŽ€βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from