Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_TRACE_MARK - Debug macro to print \n and text
librock_TRACE_FN - Debug macro to note function call
librock_TRACE_FR - Debug macro to note function return, and return value type.
librock_TRACE_STRUCT_B - Debug macro to note start of structure dump
librock_TRACE_STRUCT_E - Debug macro to note end of structure dump
librock_TRACE_V_I - Debug macro to note integer value
librock_TRACE_V_MEM - Debug macro to note contents of memory
librock_TRACE_V_PSZ - Debug macro to note contents of string

librock_dumpmem - Function to dump memory to a FILE *.

#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/exec.h>
NOTE: Caller has to #define or have a FILE *librock_ftrace in scope

void
librock_dumpmem(
    FILE *f,
    const char *p,
    int c
);

int
librock_TRACE_MARK(
    const char *psz
);

int
librock_TRACE_FN(
    const char *pszFunctionName
);
int
librock_TRACE_FR(
    const char *pszFunctionName,const char *pszType
);

int
librock_TRACE_STRUCT_B();

int
librock_TRACE_STRUCT_E();

int
librock_TRACE_V_I(
    int i
);

int librock_TRACE_V_MEM(
    void *p, int c
);

int librock_TRACE_V_PSZ(
    const char *psz
);

DESCRIPTION

Except for librock_dumpmem(), these are macros which are enabled at compile time when defined(librock_DEBUG). They check for a non-zero librock_ftrace, which should be (or #defined to be) a FILE * in scope, and then call fprintf() to show the values. Formatting characters such as '{}' and '[]' are added to help in reading the output.

Return values are not useful.

librock_dumpmem() will URL encode (% escape) the c bytes at p. ASCII Spaces are converted to '+'. '+', '%' and any characters outside the range 0x21-0x7f inclusive are escaped. Other characters appear unchanged.

Typical use is to instrument code for debugging and regression testing. Here is an example of an instrumented function wrapper.

int librock_VSBInsert(struct librock_VSB_s *v,int loc,const char *buf,int len)
{

    int ret;
    /* Show what function we just entered */
    librock_TRACE_FN("librock_VSBInsert");

    /* Show parameters (and initial state.) We dump the contents of

       the librock_VSB_s, not the memory pointer values.
     */
    librock_TRACE_STRUCT_B();
        librock_TRACE_V_I(v->inbuf);
        librock_TRACE_V_MEM(v->buf,v->inbuf);
    librock_TRACE_STRUCT_E();

    librock_TRACE_V_I(loc);
    librock_TRACE_V_MEM(buf,len);

    /* Do the call */
    ret = librock_body_VSBInsert(v,loc,buf,len);

    /* Note the function returned, and the return type, and value */
    librock_TRACE_FR("librock_VSBInsert","int");
    librock_TRACE_V_I(ret);

    /* Show the exit state. */
    librock_TRACE_STRUCT_B();
        librock_TRACE_V_I(v->inbuf);
        librock_TRACE_V_MEM(v->buf,v->inbuf);
    librock_TRACE_STRUCT_E();

    return ret;
}
Typical use of dumpmem
#ifdef librock_TYPICAL_USE_dumpmem
    #include <stdio.h>
    #include <librock/exec.h>
    char buf[4] = { 'a', '\x04', '\x85', 'c'};

    librock_dumpmem(stdout,buf,sizeof(buf));
    printf("\n");
#endif

USES

  fprintf()
  librock_ftrace  // Must be a FILE * in scope.  Can be 0.


LICENSE

  Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com
  Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block.
  License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45

Source Code

./exec/debug/trace.c (implementation, plus source of this manual page)

Tests and Supported Platform Types

This is a representative sample. Librock code is highly portable. For a particular platform not reported here, request paid support

librock_TRACE_FN passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_FN passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_TRACE_FR passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_FR passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_TRACE_MARK passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_MARK passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_TRACE_STRUCT_B passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_STRUCT_B passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_TRACE_STRUCT_E passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_STRUCT_E passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_TRACE_V_I passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_V_I passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_TRACE_V_MEM passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_V_MEM passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_TRACE_V_PSZ passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_TRACE_V_PSZ passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_dumpmem passed tests in tfsil (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_dumpmem passed tests in tfsil_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)


This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)

Want to help? We welcome comments, patches. -- Need help? Request paid support.