GeezerVison is showing cpprefjp.github.io — std::basic_stacktrace::current - cpprefjp C++日本語リファレンス
最終更新日時:
2026年02月26日 13時20分38秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<stacktrace>
std:: basic_stacktrace:: current (C++23)
static basic_stacktrace
current ( const allocator_type & alloc = allocator_type ()) noexcept ; // (1) C++23
static basic_stacktrace
current ( size_type skip ,
const allocator_type & alloc = allocator_type ()) noexcept ; // (2) C++23
static basic_stacktrace
current ( size_type skip ,
size_type max_depth ,
const allocator_type & alloc = allocator_type ()) noexcept ; // (3) C++23
概要
現在位置からのスタックトレースを取得する。
(1) : 現在位置から現在の実行スレッドの初期関数までの全体のスタックトレースを取得する
(2) : 現在位置 + skipから実行スレッドの初期関数までのスタックトレースを取得する
(3) : 現在位置 + skipから最大でmax_depth個のスタックトレースを取得する
堅牢化された事前条件
(3) : skip <= skip + max_depthであること
戻り値
(1) :
(2) :
basic_stacktrace::current(alloc)で構築されたオブジェクトstのst.size() をnとして、
イテレータ範囲[st.begin() + min(n, skip), st.end())とallocを、stacktrace_entry オブジェクトの配列を保持するstd::vector 型メンバ変数として保持する。ただし、その初期化に失敗した場合、basic_stacktraceオブジェクトは空になる
(3) :
basic_stacktrace::current(alloc)で構築されたオブジェクトstのst.size() をnとして、
イテレータ範囲[st.begin() + min(n, skip), st.begin() + min(n, skip + max_depth))とallocを、stacktrace_entry オブジェクトの配列を保持するstd::vector 型メンバ変数として保持する。ただし、その初期化に失敗した場合、basic_stacktraceオブジェクトは空になる
備考
(1) : 正常にスタックトレースを取得できた場合、構築されたbasic_stacktrace型のオブジェクトstの先頭要素st[0]は、現在の評価を表すstacktrace_entry オブジェクトであり、末尾要素st[st.size() - 1]は現在の実行スレッドの初期関数を表すstacktrace_entry オブジェクトである
例
全体のスタックトレースを取得する
出力例 (GCC)
0# g() at /app/example.cpp:5
1# f() at /app/example.cpp:9
2# main at /app/example.cpp:13
3# at :0
4# __libc_start_main at :0
5# _start at :0
6#
現在位置からN個を除いたスタックトレースを取得する
出力例 (GCC)
0# f() at /app/example.cpp:9
1# main at /app/example.cpp:13
2# at :0
3# __libc_start_main at :0
4# _start at :0
5#
指定範囲のスタックトレースを取得する
出力例 (GCC)
0# f() at /app/example.cpp:9
1# main at /app/example.cpp:13
バージョン
言語
処理系
参照