当将头文件中的这个类添加到语言中时,我们将能够更容易地处理哪些问题,以及计划替换哪些语法?下面我分享了我从优先选择网站获得的代码。
std::stacktrace_entry 类
namespace std {
class stacktrace_entry {
public:
using native_handle_type = /* implementation-defined */;
// constructors
constexpr stacktrace_entry() noexcept;
constexpr stacktrace_entry(const stacktrace_entry& other) noexcept;
constexpr stacktrace_entry& operator=(const stacktrace_entry& other) noexcept;
~stacktrace_entry();
// observers
constexpr native_handle_type native_handle() const noexcept;
constexpr explicit operator bool() const noexcept;
// query
string description() const;
string source_file() const;
uint_least32_t source_line() const;
// comparison
friend constexpr bool operator==(const stacktrace_entry& x,
const stacktrace_entry& y) noexcept;
friend constexpr strong_ordering operator<=>(const stacktrace_entry& x,
const stacktrace_entry& y) noexcept;
};
}发布于 2021-05-08 17:51:29
当您附加到带有调试器并停止执行的C++程序时,一件相对容易做的事情(使用一些编译时工具)是在给定的点上计算出代码的调用堆栈。
通常,C++的实现是:调用堆栈是一个链接列表(可能以一种非平凡的方式存储),当您从函数返回时,调用方在调用您时跳到调用方注入的位置。
这些地址可以由调试器解码,然后指令位置可以映射回C++源位置,并且可以生成如何到达这一行代码的漂亮打印。根据优化设置的不同,这些信息有时可能不准确,缺少一些框架,或者完全没有意义;但它非常有用。
即使没有编译时工具,也可以保存指令集链,然后使用编译时工具的人可以很好地解码它。
有些库允许C++程序在内部执行此操作,而不需要外部调试器。这些包括boost stacktrace的库。
这是将该功能添加到std库中。
堆栈跟踪是一个框架链,该框架可以通过标准库的新部分映射到源文件、函数名和行号信息。
典型的用例可能是捕捉程序在C++源代码中以无效方式运行的情况,并生成一个日志来报告在尝试恢复之前发生的情况,或者只执行退出操作。然后,程序员可以查看这个堆栈跟踪,并获得有关如何修复该错误的信息。
https://stackoverflow.com/questions/67368931
复制相似问题