question

Kohit-8404 avatar image
0 Votes"
Kohit-8404 asked Kohit-8404 commented

/Gh causing infinite loop

Topic: https://github.com/MicrosoftDocs/cpp-docs/issues/2278
mentioned that the _penter function must compile along,
I countered another problem,
I need to use functions from other libraries in _penter function, for example

void myfunc(){
// function from dbghelp.lib
SymFromAddr(GetCurrentProcess(), dwAddr, &dwDisplacement, pSymbol);
}

_penter(){
... // save registers
myfunc();
... // pop registers
}
I have compiled this file along, event tried to compile a static library(containing dbghelp.lib).
Both way, when the program runs, SymFromAddr would trigger _penter, which causing a stack overflow.

Is there a way to told the compiler not to trigger _penter in the following function calls?
gcc's way:

attribute((no_instrument_function))

c++vs-debugging
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IgorTandetnik-1300 avatar image
1 Vote"
IgorTandetnik-1300 answered Kohit-8404 commented

I suspect it's myfunc and not SymFromAddr that triggers a recursive call to _penter. After all, myfunc is a function, too.

Perhaps something along these lines might help:

 void _penter() {
   thread_local bool in_recursive = false;
   if (in_recursive) return;
   in_recursive = true;
   // Do work
   in_recursive = false;
 }


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

the full type of _penter is

void __declspec(naked) __cdecl _penter( void );

so declare new variable in _penter function is not allowed.

but this way actually help!

0 Votes 0 ·