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 <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
4b6432d831
commit
9cb525a2e3
@@ -1,33 +1,40 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2008 Stephan Aßmus <[email protected]>
|
* Copyright 2008 Stephan Aßmus <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT/X11 license.
|
* Distributed under the terms of the MIT/X11 license.
|
||||||
*/
|
*/
|
||||||
#ifndef FUNCTION_TRACER_H
|
#ifndef FUNCTION_TRACER_H
|
||||||
#define FUNCTION_TRACER_H
|
#define FUNCTION_TRACER_H
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
class FunctionTracer {
|
class FunctionTracer {
|
||||||
public:
|
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),
|
: fFunctionName(functionName),
|
||||||
fPrepend(),
|
fPrepend(),
|
||||||
fFunctionDepth(depth)
|
fFunctionDepth(depth),
|
||||||
|
fPrintFunction(printFunction)
|
||||||
{
|
{
|
||||||
fFunctionDepth++;
|
fFunctionDepth++;
|
||||||
|
if (pointer != NULL)
|
||||||
|
fPrepend.SetToFormat("%p ->", pointer);
|
||||||
fPrepend.Append(' ', fFunctionDepth * 2);
|
fPrepend.Append(' ', fFunctionDepth * 2);
|
||||||
|
|
||||||
printf("%s%s {\n", fPrepend.String(), fFunctionName.String());
|
fPrintFunction("%s%s {\n", fPrepend.String(), fFunctionName.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
~FunctionTracer()
|
~FunctionTracer()
|
||||||
{
|
{
|
||||||
// printf("%s - leave\n", fFunctionName.String());
|
fPrintFunction("%s}\n", fPrepend.String());
|
||||||
printf("%s}\n", fPrepend.String());
|
|
||||||
fFunctionDepth--;
|
fFunctionDepth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +42,12 @@ private:
|
|||||||
BString fFunctionName;
|
BString fFunctionName;
|
||||||
BString fPrepend;
|
BString fPrepend;
|
||||||
int32& fFunctionDepth;
|
int32& fFunctionDepth;
|
||||||
|
#if __GNUC__ < 3
|
||||||
|
// gcc2 doesn't support function attributes on function pointers
|
||||||
|
PrintFunction fPrintFunction;
|
||||||
|
#else
|
||||||
|
PrintFunction _PRINTFLIKE(1, 2) fPrintFunction;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ using std::nothrow;
|
|||||||
#ifdef TRACE_OSS_NODE
|
#ifdef TRACE_OSS_NODE
|
||||||
static int32 sDepth;
|
static int32 sDepth;
|
||||||
# define TRACE(x...) printf(x)
|
# 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
|
# define PRINTING
|
||||||
#else
|
#else
|
||||||
# define TRACE(x...)
|
# define TRACE(x...)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ static const bigtime_t kChangesPulseInterval = 150000;
|
|||||||
|
|
||||||
static int32 sDepth;
|
static int32 sDepth;
|
||||||
|
|
||||||
# define CALLED() FunctionTracer functionTracer(__PRETTY_FUNCTION__, sDepth)
|
# define CALLED() FunctionTracer functionTracer(printf, this, __PRETTY_FUNCTION__, sDepth)
|
||||||
#else
|
#else
|
||||||
# define CALLED()
|
# define CALLED()
|
||||||
#endif // TRACE_FUNCTIONS
|
#endif // TRACE_FUNCTIONS
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
#ifdef TRACE_MENU_FIELD
|
#ifdef TRACE_MENU_FIELD
|
||||||
# include <FunctionTracer.h>
|
# include <FunctionTracer.h>
|
||||||
static int32 sFunctionDepth = -1;
|
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; \
|
# define TRACE(x...) { BString _to; \
|
||||||
_to.Append(' ', (sFunctionDepth + 1) * 2); \
|
_to.Append(' ', (sFunctionDepth + 1) * 2); \
|
||||||
printf("%s", _to.String()); printf(x); }
|
printf("%s", _to.String()); printf(x); }
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <FunctionTracer.h>
|
# include <FunctionTracer.h>
|
||||||
static int32 sFunctionDepth = -1;
|
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; \
|
# define TRACE(x...) { BString _to; \
|
||||||
_to.Append(' ', (sFunctionDepth + 1) * 2); \
|
_to.Append(' ', (sFunctionDepth + 1) * 2); \
|
||||||
printf("%s", _to.String()); printf(x); }
|
printf("%s", _to.String()); printf(x); }
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ using BPrivate::gSystemCatalog;
|
|||||||
#ifdef TRACE_TEXT_VIEW
|
#ifdef TRACE_TEXT_VIEW
|
||||||
# include <FunctionTracer.h>
|
# include <FunctionTracer.h>
|
||||||
static int32 sFunctionDepth = -1;
|
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; \
|
# define TRACE(x...) { BString _to; \
|
||||||
_to.Append(' ', (sFunctionDepth + 1) * 2); \
|
_to.Append(' ', (sFunctionDepth + 1) * 2); \
|
||||||
printf("%s", _to.String()); printf(x); }
|
printf("%s", _to.String()); printf(x); }
|
||||||
|
|||||||
Reference in New Issue
Block a user