⛏️ index : haiku.git

author PulkoMandy <pulkomandy@pulkomandy.tk> 2025-11-30 16:08:55.0 +01:00:00
committer Adrien Destugues <pulkomandy@pulkomandy.tk> 2025-12-03 7:48:12.0 +00:00:00
commit
9cb525a2e34d9548ddaf49505c9096ae9f046cd3 [patch]
tree
02e239abb265f9a5473cd08107648ad8bd889f6d
parent
4b6432d8312c57a91d6184421b79903082f50da5
download
9cb525a2e34d9548ddaf49505c9096ae9f046cd3.tar.gz

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(-)

diff --git a/headers/private/shared/FunctionTracer.h b/headers/private/shared/FunctionTracer.h
index e8d2693..f375c65 100644
--- a/headers/private/shared/FunctionTracer.h
+++ b/headers/private/shared/FunctionTracer.h
@@ -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 - leave\n", fFunctionName.String());
		printf("%s}\n", fPrepend.String());
		fPrintFunction("%s}\n", fPrepend.String());
		fFunctionDepth--;
	}

@@ -35,6 +42,12 @@
	BString	fFunctionName;
	BString	fPrepend;
	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
diff --git a/src/apps/text_search/GrepWindow.cpp b/src/apps/text_search/GrepWindow.cpp
index 7dc99d4..f8e8f4c 100644
--- a/src/apps/text_search/GrepWindow.cpp
+++ b/src/apps/text_search/GrepWindow.cpp
@@ -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 // TRACE_FUNCTIONS
diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp
index 5197db3..1bddb26 100644
--- a/src/kits/interface/MenuField.cpp
+++ b/src/kits/interface/MenuField.cpp
@@ -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); }
diff --git a/src/kits/interface/TextControl.cpp b/src/kits/interface/TextControl.cpp
index 4696779..ea12187 100644
--- a/src/kits/interface/TextControl.cpp
+++ b/src/kits/interface/TextControl.cpp
@@ -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); }
diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp
index 2296942..73efc39 100644
--- a/src/kits/interface/TextView.cpp
+++ b/src/kits/interface/TextView.cpp
@@ -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); }
diff --git a/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp b/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp
index 9e07aa4..2b6ae6b 100644
--- a/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp
+++ b/src/add-ons/media/media-add-ons/opensound/OpenSoundNode.cpp
@@ -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...)