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_tare 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_tracewith 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_tracereturns 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β tracetputs(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 toaddch.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
traceonandtraceoff, to control whether debugging information was written to the βtraceβ file. While the functions were always available, this feature was only enabled ifDEBUGwas defined when building the library.
The SVr4 tracing feature is undocumented. π
- PDCurses provides
traceonandtraceoff, 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_MASKandCURSES_TRACE_FILEto 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
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2019-2024,2025 Thomas E. Dickey
- Copyright 2000-2016,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms