StackTrace c++应用程序

StackTrace C++ application

本文关键字:应用程序 c++ StackTrace      更新时间:2023-10-16

我编写了一个c++堆栈应用程序,并使用cygwin++编译器运行它。异常处理不完美导致应用程序崩溃

它给了我stacktrace dump作为文件Stack.exe.stackdump。我是StackTrace的新手,有人能告诉我怎么读它,它意味着什么吗?

根据收到的注释,只是为了澄清,堆栈数据结构只是一个例子,使应用程序崩溃,并给出stackTrace。我的意思是,这个堆栈跟踪是在程序崩溃的任何情况下生成的,与我的堆栈数据结构应用程序无关,我只是将其用作程序崩溃的现有代码。

生成异常的代码片段:

class RuntimeException{
    private:
    string errorMsg;
    public:
    RuntimeException(const string& err){errorMsg = err;}
    string getMessage() const {return errorMsg;}
    };
class StackEmpty : public RuntimeException{
public:
StackEmpty(const string& err) : RuntimeException(err){}
};
template <typename E >
const E& ArrayStack<E> ::top() const throw(StackEmpty)
{
        if(empty()) throw StackEmpty("Top of Empty Stack");
        return S[t];
    }
int main()
{
    ArrayStack <int> A;
    cout << "######n";
    cout << A.top() << "n";
    cout << "######n";
    }

输出:

$ ./Stack
######
Aborted (core dumped)

生成一个文件Stack.exe.stackdump,其内容如下:

Stack trace:
Frame     Function  Args
0022A774  7608C313  (000000C0, 0000EA60, 00000000, 0022A8A8)
0022A788  7608C2C2  (000000C0, 0000EA60, 000000A4, 0022A884)
0022A8A8  610DC559  (00000000, 00000000, 00000000, 00000000)
0022A998  610D9913  (00000000, 6110073E, 003B0023, 00230000)
0022A9F8  610D9DEE  (0022A9D0, 6110073E, 003B0023, 00000006)
0022AAA8  610D9F40  (000008F4, 00000006, 00000000, 00000000)
0022AAC8  610D9F6C  (00000006, 00000006, 0022AB38, 00404C6B)
0022AAF8  610DA233  (0022AB28, 611A1E9B, 0022ABAC, 00000001)
0022AB48  00404777  (00000000, 00000000, 0022AC18, 004142CB)
0022AB58  00404166  (20048588, 004460E0, 00410F78, 0040F89F)
0022AC18  004142CB  (0022AC50, 00445218, 20010100, 004011B5)
0022AC68  004011EC  (00000001, 0022AC90, 20010100, 612756CA)
0022ACF8  6100763A  (00000000, 0022CD78, 61006C50, 00000000)
End of stack trace

我想知道这个文件意味着什么以及如何阅读它,谷歌了很多,但无法找到令人满意的答案。

谢谢

我会尝试在调试器中解码转储的核心。

gdb ./Stack.exe ./Stack.exe.stackdump
backtrace

这给出了崩溃时的调用堆栈。这与您试图实现的堆栈数据结构无关。

对于调用堆栈上的每个函数,堆栈转储显示堆栈指针、函数地址和前四个参数。与尝试使用堆栈转储相比,使用调试器可能更容易对程序进行故障排除。