Topic
  • 5 replies
  • Latest Post - ‏2019-05-06T05:48:13Z by Sergey Chebotarev
Sergey Chebotarev
Sergey Chebotarev
19 Posts

Pinned topic The problem with debugging C++ code

‏2019-04-18T12:21:43Z |

Hello to all! I had a problem when I tried to debug C ++ code. The program stops at startup, the debugger opens, but the current position indicates the last line of code. Step-by-step execution of the F6 key does not change the pointer of the current line of code. The code is executed (data is displayed on the screen).
What is the reason for this behavior?

  • Andreas Bott
    Andreas Bott
    46 Posts
    ACCEPTED ANSWER

    Re: The problem with debugging C++ code

    ‏2019-05-02T11:50:43Z  

    Found the reason for the strange behavior of the debugger. All because of the output in std::cout numbers or variable of numeric type. That is, this code will cause a debug glitch:

    #include <iostream>
    
    int main()
    {
     int i;
     i = 5;
     std::cout << "Hello" << std::endl;
     std::cout << i << std::endl;
     return 0;
    }
    

    Obviously, this is a glitch RDi, as in the "green screen" debugging works correctly. And it seems to me that this is not a glitch, but just somewhere in the RDi settings you need to install or remove some tick :). It remains to find this setting.

    Hi,

     

    if you start the Debug over the "Call from RDi" Method, the Debugger starts at i = 5;

    Right Click on the PGM Object and Debug As - Interactiv - with the reserved Session -> STRRSESVR ....

    if you debug you Program over the Job-Debug, the Debugger start at Return and after some Steps he goes ack to i = 5; and back to return , then to STD::COUT ...

    if you Start the Debugger with Service Entry Point, then the Debugger Starts at Return an stays at Return.

     

    I searched the Preference for some Configurations, but i did not found anything like this.

     

    Try to debug with the "Reserved Session and the Call from RDi" Method.

     

    Greetz

  • mkwan
    mkwan
    33 Posts
    ACCEPTED ANSWER

    Re: The problem with debugging C++ code

    ‏2019-05-02T16:50:23Z  

    For the  service entry point (SEP) problem, it only happens if you set the SEP on the program or module object. If you set the SEP directly on the main() function, then the debugger will stop at the line "i=5".

     

    The underlying issue is that the C++ program contains some compiler generated symbols, and some of the symbols are mapped to the return statement. And even some of the generated functions are called before main() is hit. If you set a SEP on the program object, then the debugger will set one SEP on each symbol entry inside the program. When you call the program, one of the SEPs on a compiled generated symbol will trigger a program stop. And that generated symbol is mapped to "return" in the compiler generated debug information.

     

    The problem can also be reproduced from the green screen debugger (STRDBG) with the following sequence:

    1. break on line 6: i = 5;

    2. resume

    3. Step into --> Jump to line 7, which is the correct behavior

    4. Step into --> Jump to line 9: return 0;  This is not the correct behavior

    5. Set a breakpoint on line 8: std::cout << i << std::endl;

    6. Resume --> Debugger stops at line 8

     

     

  • Sergey Chebotarev
    Sergey Chebotarev
    19 Posts

    Re: The problem with debugging C++ code

    ‏2019-04-19T10:39:20Z  

    Found the reason for the strange behavior of the debugger. All because of the output in std::cout numbers or variable of numeric type. That is, this code will cause a debug glitch:

    #include <iostream>
    int main()
    {
     int i;
     i = 5;
     std::cout << "Hello" << std::endl;
     std::cout << i << std::endl;
     return 0;
    }
    

    Obviously, this is a glitch RDi, as in the "green screen" debugging works correctly. And it seems to me that this is not a glitch, but just somewhere in the RDi settings you need to install or remove some tick :). It remains to find this setting.

  • Andreas Bott
    Andreas Bott
    46 Posts

    Re: The problem with debugging C++ code

    ‏2019-05-02T11:50:43Z  

    Found the reason for the strange behavior of the debugger. All because of the output in std::cout numbers or variable of numeric type. That is, this code will cause a debug glitch:

    <pre class="java dw" dir="ltr">#include <iostream> int main() { int i; i = 5; std::cout << "Hello" << std::endl; std::cout << i << std::endl; return 0; } </pre>

    Obviously, this is a glitch RDi, as in the "green screen" debugging works correctly. And it seems to me that this is not a glitch, but just somewhere in the RDi settings you need to install or remove some tick :). It remains to find this setting.

    Hi,

     

    if you start the Debug over the "Call from RDi" Method, the Debugger starts at i = 5;

    Right Click on the PGM Object and Debug As - Interactiv - with the reserved Session -> STRRSESVR ....

    if you debug you Program over the Job-Debug, the Debugger start at Return and after some Steps he goes ack to i = 5; and back to return , then to STD::COUT ...

    if you Start the Debugger with Service Entry Point, then the Debugger Starts at Return an stays at Return.

     

    I searched the Preference for some Configurations, but i did not found anything like this.

     

    Try to debug with the "Reserved Session and the Call from RDi" Method.

     

    Greetz

  • mkwan
    mkwan
    33 Posts

    Re: The problem with debugging C++ code

    ‏2019-05-02T16:50:23Z  

    For the  service entry point (SEP) problem, it only happens if you set the SEP on the program or module object. If you set the SEP directly on the main() function, then the debugger will stop at the line "i=5".

     

    The underlying issue is that the C++ program contains some compiler generated symbols, and some of the symbols are mapped to the return statement. And even some of the generated functions are called before main() is hit. If you set a SEP on the program object, then the debugger will set one SEP on each symbol entry inside the program. When you call the program, one of the SEPs on a compiled generated symbol will trigger a program stop. And that generated symbol is mapped to "return" in the compiler generated debug information.

     

    The problem can also be reproduced from the green screen debugger (STRDBG) with the following sequence:

    1. break on line 6: i = 5;

    2. resume

    3. Step into --> Jump to line 7, which is the correct behavior

    4. Step into --> Jump to line 9: return 0;  This is not the correct behavior

    5. Set a breakpoint on line 8: std::cout << i << std::endl;

    6. Resume --> Debugger stops at line 8

     

     

  • mkwan
    mkwan
    33 Posts

    Re: The problem with debugging C++ code

    ‏2019-05-02T16:54:49Z  

    For RDi debug, please use the workaround to set the SEP on the procedure or function level. For the stepping issue (from return to entry, then to return, then back to cout), you can open a PMR against system debug, and let them figure out whether the problem is at system debug or the compiler.

  • Sergey Chebotarev
    Sergey Chebotarev
    19 Posts

    Re: The problem with debugging C++ code

    ‏2019-05-06T05:48:13Z  

    Andreas Bott, mkwan, thank you for your help!
    For debugging programs, I always used SEP, which I installed on PGM. Thanks to you, I now know that SEP can be installed on individual functions and it's great! Also thank you for the interactive debug prompt.
    Summing up, I can say that now I can debug the code.