/Gh causing infinite loop

Kohit _ 41 Reputation points
2020-10-12T15:56:24.39+00:00

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++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,755 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,002 questions
0 comments No comments
{count} votes

Accepted answer
  1. Igor Tandetnik 1,106 Reputation points
    2020-10-13T16:31:31.517+00:00

    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 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.