<i id='U5ayy'><tr id='U5ayy'><dt id='U5ayy'><q id='U5ayy'><span id='U5ayy'><b id='U5ayy'><form id='U5ayy'><ins id='U5ayy'></ins><ul id='U5ayy'></ul><sub id='U5ayy'></sub></form><legend id='U5ayy'></legend><bdo id='U5ayy'><pre id='U5ayy'><center id='U5ayy'></center></pre></bdo></b><th id='U5ayy'></th></span></q></dt></tr></i><div id='U5ayy'><tfoot id='U5ayy'></tfoot><dl id='U5ayy'><fieldset id='U5ayy'></fieldset></dl></div>

    <tfoot id='U5ayy'></tfoot>
    1. <legend id='U5ayy'><style id='U5ayy'><dir id='U5ayy'><q id='U5ayy'></q></dir></style></legend>
    2. <small id='U5ayy'></small><noframes id='U5ayy'>

        <bdo id='U5ayy'></bdo><ul id='U5ayy'></ul>

      如何检测 c/c++ 程序中可能/潜在的堆栈溢出问题

      时间:2023-09-15

        <legend id='SUFAl'><style id='SUFAl'><dir id='SUFAl'><q id='SUFAl'></q></dir></style></legend>

        <i id='SUFAl'><tr id='SUFAl'><dt id='SUFAl'><q id='SUFAl'><span id='SUFAl'><b id='SUFAl'><form id='SUFAl'><ins id='SUFAl'></ins><ul id='SUFAl'></ul><sub id='SUFAl'></sub></form><legend id='SUFAl'></legend><bdo id='SUFAl'><pre id='SUFAl'><center id='SUFAl'></center></pre></bdo></b><th id='SUFAl'></th></span></q></dt></tr></i><div id='SUFAl'><tfoot id='SUFAl'></tfoot><dl id='SUFAl'><fieldset id='SUFAl'></fieldset></dl></div>

            <small id='SUFAl'></small><noframes id='SUFAl'>

          1. <tfoot id='SUFAl'></tfoot>

              <tbody id='SUFAl'></tbody>
              <bdo id='SUFAl'></bdo><ul id='SUFAl'></ul>
                本文介绍了如何检测 c/c++ 程序中可能/潜在的堆栈溢出问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                是否有一种标准方法可以查看您的应用有多少堆栈空间以及在运行期间堆栈使用的最高水印是多少?

                Is there a standard way to see how much stack space your app has and what the highest watermark for stack usage is during a run?

                同样在实际溢出的可怕情况下会发生什么?

                Also in the dreaded case of actual overflow what happens?

                它是否崩溃、触发异常或发出信号?是否有标准或在所有系统和编译器上都不同?

                Does it crash, trigger an exception or signal? Is there a standard or is it different on all systems and compilers?

                我专门寻找 Windows、Linux 和 Macintosh.

                I'm looking specifically for Windows, Linux and Macintosh.

                推荐答案

                Windows 上会产生堆栈溢出异常.

                On Windows a stack overflow exception will be generated.

                以下 Windows 代码说明了这一点:

                The following windows code illustrates this:

                #include <stdio.h>
                #include <windows.h>
                
                void StackOverFlow()
                {
                  CONTEXT context;
                
                  // we are interested control registers
                  context.ContextFlags = CONTEXT_CONTROL;
                
                  // get the details
                  GetThreadContext(GetCurrentThread(), &context);
                
                  // print the stack pointer
                  printf("Esp: %X
                ", context.Esp);
                
                  // this will eventually overflow the stack
                  StackOverFlow();
                }
                
                DWORD ExceptionFilter(EXCEPTION_POINTERS *pointers, DWORD dwException)
                {
                  return EXCEPTION_EXECUTE_HANDLER;
                }
                
                void main()
                {
                  CONTEXT context;
                
                  // we are interested control registers
                  context.ContextFlags = CONTEXT_CONTROL;
                
                  // get the details
                  GetThreadContext(GetCurrentThread(), &context);
                
                  // print the stack pointer
                  printf("Esp: %X
                ", context.Esp);
                
                  __try
                  {
                    // cause a stack overflow
                    StackOverFlow();
                  }
                  __except(ExceptionFilter(GetExceptionInformation(), GetExceptionCode()))
                  {
                    printf("
                ****** ExceptionFilter fired ******
                ");
                  }
                }
                

                当这个 exe 运行时,会生成以下输出:

                When this exe is run the following output is generated:

                Esp: 12FC4C
                Esp: 12F96C
                Esp: 12F68C
                .....
                Esp: 33D8C
                Esp: 33AAC
                Esp: 337CC
                
                ****** ExceptionFilter fired ******
                

                这篇关于如何检测 c/c++ 程序中可能/潜在的堆栈溢出问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:未使用的成员变量是否占用内存? 下一篇:指针的大小是多少?它具体取决于什么?

                相关文章

                最新文章

                <legend id='JLtah'><style id='JLtah'><dir id='JLtah'><q id='JLtah'></q></dir></style></legend>

                  <small id='JLtah'></small><noframes id='JLtah'>

                1. <i id='JLtah'><tr id='JLtah'><dt id='JLtah'><q id='JLtah'><span id='JLtah'><b id='JLtah'><form id='JLtah'><ins id='JLtah'></ins><ul id='JLtah'></ul><sub id='JLtah'></sub></form><legend id='JLtah'></legend><bdo id='JLtah'><pre id='JLtah'><center id='JLtah'></center></pre></bdo></b><th id='JLtah'></th></span></q></dt></tr></i><div id='JLtah'><tfoot id='JLtah'></tfoot><dl id='JLtah'><fieldset id='JLtah'></fieldset></dl></div>

                  1. <tfoot id='JLtah'></tfoot>
                      <bdo id='JLtah'></bdo><ul id='JLtah'></ul>