Return address in logging is sometimes wrong. #21

Closed
opened 2026-02-28 13:55:56 -05:00 by yindo · 0 comments
Owner

Originally created by @grasmanek94 on GitHub (Jul 17, 2025).

Fixed in https://github.com/grasmanek94/UniverseLAN/commit/1aa328eaf3f93be9f0dad6711d6e57ce0ebe8f14

Issue analysis:

	Trace::Trace(const char* const extra, uint64_t mask, const char* const func, void* override_caller_address) :
		enabled{ tracing_enabled && ((enabled_tracing_flags & mask) == mask) },
		func{ func }, extra{ extra }, return_address{ nullptr } {
		if (!enabled) {
			return;
		}

#ifdef _WIN32
		if (return_address == nullptr) {
			return_address = _ReturnAddress();
		}
#endif
		Tracer::Enter(func, extra, return_address);
	}

_ReturnAddress() would point here to the alternate constructors:

	Trace::Trace(uint64_t mask, const char* const extra, const char* const func) : Trace{ extra, mask, func } {}
	Trace::Trace(const char* const extra, const char* const func, uint64_t mask) : Trace{ extra, mask, func } {}

As that's the return address (at least in unoptimized debug builds).
Fix is to get the return address at the highest level, in the upper constructors, and pass it to delegated constructors.

Originally created by @grasmanek94 on GitHub (Jul 17, 2025). Fixed in https://github.com/grasmanek94/UniverseLAN/commit/1aa328eaf3f93be9f0dad6711d6e57ce0ebe8f14 Issue analysis: ``` Trace::Trace(const char* const extra, uint64_t mask, const char* const func, void* override_caller_address) : enabled{ tracing_enabled && ((enabled_tracing_flags & mask) == mask) }, func{ func }, extra{ extra }, return_address{ nullptr } { if (!enabled) { return; } #ifdef _WIN32 if (return_address == nullptr) { return_address = _ReturnAddress(); } #endif Tracer::Enter(func, extra, return_address); } ``` `_ReturnAddress()` would point here to the alternate constructors: ``` Trace::Trace(uint64_t mask, const char* const extra, const char* const func) : Trace{ extra, mask, func } {} Trace::Trace(const char* const extra, const char* const func, uint64_t mask) : Trace{ extra, mask, func } {} ``` As that's the return address (at least in unoptimized debug builds). Fix is to get the return address at the highest level, in the upper constructors, and pass it to delegated constructors.
yindo added the bug label 2026-02-28 13:55:56 -05:00
yindo closed this issue 2026-02-28 13:55:56 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yindo/UniverseLAN#21