FunctionTracer: add support for "this" pointer and custom printf function
Prepare for replacement of modified version used in input_server addons.
Adapt existing callers.
The "this" argument is required, and the CALLED macro can only set it to
one single value for an entire file currently. So, in any case where at
least one standalone function or static method uses CALLED, the macro
has to use a NULL pointer for all calls.
Change-Id: I42fdcbeaf6dd039d4c4369818220ad85e0b8087e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10041
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Diff
headers/private/shared/FunctionTracer.h | 27 ++++++++++++++++++++++-----
src/apps/text_search/GrepWindow.cpp | 2 +-
src/kits/interface/MenuField.cpp | 2 +-
src/kits/interface/TextControl.cpp | 2 +-
src/kits/interface/TextView.cpp | 2 +-
src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp | 2 +-
6 files changed, 25 insertions(+), 12 deletions(-)
@@ -1,33 +1,40 @@
/*
* Copyright © 2008 Stephan Aßmus <superstippi@gmx.de>
* All rights reserved. Distributed under the terms of the MIT/X11 license.
* Copyright 2008 Stephan Aßmus <superstippi@gmx.de>
* Distributed under the terms of the MIT/X11 license.
*/
#ifndef FUNCTION_TRACER_H
#define FUNCTION_TRACER_H
#include <stdio.h>
#include <String.h>
namespace BPrivate {
class FunctionTracer {
public:
FunctionTracer(const char* functionName, int32& depth)
typedef int (*PrintFunction)(const char * fmt, ...);
FunctionTracer(PrintFunction printFunction, const void* pointer, const char* functionName,
int32& depth)
: fFunctionName(functionName),
fPrepend(),
fFunctionDepth(depth)
fFunctionDepth(depth),
fPrintFunction(printFunction)
{
fFunctionDepth++;
if (pointer != NULL)
fPrepend.SetToFormat("%p ->", pointer);
fPrepend.Append(' ', fFunctionDepth * 2);
printf("%s%s {\n", fPrepend.String(), fFunctionName.String());
fPrintFunction("%s%s {\n", fPrepend.String(), fFunctionName.String());
}
~FunctionTracer()
{
printf("%s}\n", fPrepend.String());
fPrintFunction("%s}\n", fPrepend.String());
fFunctionDepth--;
}
@@ -35,6 +42,12 @@
BString fFunctionName;
BString fPrepend;
int32& fFunctionDepth;
#if __GNUC__ < 3
PrintFunction fPrintFunction;
#else
PrintFunction _PRINTFLIKE(1, 2) fPrintFunction;
#endif
};
}
@@ -56,7 +56,7 @@
static int32 sDepth;
# define CALLED() FunctionTracer functionTracer(__PRETTY_FUNCTION__, sDepth)
# define CALLED() FunctionTracer functionTracer(printf, this, __PRETTY_FUNCTION__, sDepth)
#else
# define CALLED()
#endif
@@ -47,7 +47,7 @@
#ifdef TRACE_MENU_FIELD
# include <FunctionTracer.h>
static int32 sFunctionDepth = -1;
# define CALLED(x...) FunctionTracer _ft(__PRETTY_FUNCTION__, sFunctionDepth)
# define CALLED(x...) FunctionTracer _ft(printf, this, __PRETTY_FUNCTION__, sFunctionDepth)
# define TRACE(x...) { BString _to; \
_to.Append(' ', (sFunctionDepth + 1) * 2); \
printf("%s", _to.String()); printf(x); }
@@ -37,7 +37,7 @@
# include <stdio.h>
# include <FunctionTracer.h>
static int32 sFunctionDepth = -1;
# define CALLED(x...) FunctionTracer _ft(__PRETTY_FUNCTION__, sFunctionDepth)
# define CALLED(x...) FunctionTracer _ft(printf, this, __PRETTY_FUNCTION__, sFunctionDepth)
# define TRACE(x...) { BString _to; \
_to.Append(' ', (sFunctionDepth + 1) * 2); \
printf("%s", _to.String()); printf(x); }
@@ -78,7 +78,7 @@
#ifdef TRACE_TEXT_VIEW
# include <FunctionTracer.h>
static int32 sFunctionDepth = -1;
# define CALLED(x...) FunctionTracer _ft(__PRETTY_FUNCTION__, sFunctionDepth)
# define CALLED(x...) FunctionTracer _ft(printf, NULL, __PRETTY_FUNCTION__, sFunctionDepth)
# define TRACE(x...) { BString _to; \
_to.Append(' ', (sFunctionDepth + 1) * 2); \
printf("%s", _to.String()); printf(x); }
@@ -50,7 +50,7 @@
#ifdef TRACE_OSS_NODE
static int32 sDepth;
# define TRACE(x...) printf(x)
# define CALLED(x...) FunctionTracer _ft(__PRETTY_FUNCTION__, sDepth)
# define CALLED(x...) FunctionTracer _ft(printf, NULL, __PRETTY_FUNCTION__, sDepth)
# define PRINTING
#else
# define TRACE(x...)