Date: Fri, 1 May 2026 11:33:54 +0200
On 01/05/2026 09:39, Frederick Virchanza Gotham via Std-Proposals wrote:
>
> David:
> > Why do you think it is so important for the interceptor function to be
> > separately compiled and invisible to the calling code, yet general
> > enough to handle any function signatures? Where would that be an
> > essential feature?
>
>
>
> I'll explain exactly what I had in mind when I first conceived
> interceptor functions.
>
> Let's say you have an executable file, "prog.exe", and it links at
> runtime with "graphics.dll". Dependency Walker shows you that the latter
> exports 3 functions:
>
> setCreate
> setPush
> setPop
> These 3 names are unmangled so you've no idea what the return type or
> parameter types are.
>
> For the sake of either logging or debugging, or for altering behaviour
> at runtime, you want to intercept calls to these three functions, so you
> write a replacement library something like:
>
> void (*p_setCreate)(void) = GetProcAddress(...);
> void (*p_setPush )(void) = GetProcAddress(...);
> void (*p_setPop )(void) = GetProcAddress(...);
>
> [[interceptor]] void setCreate(void) noexcept
> {
> DoLoggingOrWhatever();
> goto -> p_setCreate;
> }
>
> [[interceptor]] void setPush(void) noexcept
> {
> DoLoggingOrWhatever();
> goto -> p_setPush;
> }
>
> [[interceptor]] void setPop(void) noexcept
> {
> DoLoggingOrWhatever();
> goto -> p_setPop;
> }
> I needed this about a year ago when I spent about a week or two looking
> for the cause of a segfault . . . I ended up writing the solution in
> x86_64 assembler but it would have been so much handier and quicker to
> have had interceptor functions. So that's one use case.
>
I can't see any justification for thinking this is appropriate for the
C++ programming language. What you are doing is hacking binaries. C++
is for writing programs, and C++ compilers are for compiling C++ code.
What you are looking for here is something totally different - you want
tools like debuggers, disassemblers, tracers, monitors, etc. Trying to
put this kind of hack into C++ will not improve the language or the
ability of people to write good C++ code, any more than trying to add
features to let C++ be an editor or a file manager.
>
> David:
> > Why do you think it is so important for the interceptor function to be
> > separately compiled and invisible to the calling code, yet general
> > enough to handle any function signatures? Where would that be an
> > essential feature?
>
>
>
> I'll explain exactly what I had in mind when I first conceived
> interceptor functions.
>
> Let's say you have an executable file, "prog.exe", and it links at
> runtime with "graphics.dll". Dependency Walker shows you that the latter
> exports 3 functions:
>
> setCreate
> setPush
> setPop
> These 3 names are unmangled so you've no idea what the return type or
> parameter types are.
>
> For the sake of either logging or debugging, or for altering behaviour
> at runtime, you want to intercept calls to these three functions, so you
> write a replacement library something like:
>
> void (*p_setCreate)(void) = GetProcAddress(...);
> void (*p_setPush )(void) = GetProcAddress(...);
> void (*p_setPop )(void) = GetProcAddress(...);
>
> [[interceptor]] void setCreate(void) noexcept
> {
> DoLoggingOrWhatever();
> goto -> p_setCreate;
> }
>
> [[interceptor]] void setPush(void) noexcept
> {
> DoLoggingOrWhatever();
> goto -> p_setPush;
> }
>
> [[interceptor]] void setPop(void) noexcept
> {
> DoLoggingOrWhatever();
> goto -> p_setPop;
> }
> I needed this about a year ago when I spent about a week or two looking
> for the cause of a segfault . . . I ended up writing the solution in
> x86_64 assembler but it would have been so much handier and quicker to
> have had interceptor functions. So that's one use case.
>
I can't see any justification for thinking this is appropriate for the
C++ programming language. What you are doing is hacking binaries. C++
is for writing programs, and C++ compilers are for compiling C++ code.
What you are looking for here is something totally different - you want
tools like debuggers, disassemblers, tracers, monitors, etc. Trying to
put this kind of hack into C++ will not improve the language or the
ability of people to write good C++ code, any more than trying to add
features to let C++ be an editor or a file manager.
Received on 2026-05-01 09:33:57
