Namespaces
Variants

std:: basic_stacktrace

From cppreference.net
헤더 파일에 정의됨 <stacktrace>
template < class Allocator >
class basic_stacktrace ;
(1) (C++23부터)
using stacktrace =
std :: basic_stacktrace < std:: allocator < std:: stacktrace_entry >> ;
(2) (C++23부터)
namespace pmr {

using stacktrace =
std :: basic_stacktrace < std:: pmr :: polymorphic_allocator < std:: stacktrace_entry >> ;

}
(3) (C++23부터)
1) basic_stacktrace 클래스 템플릿은 전체 스택 트레이스 또는 그 일부의 스냅샷을 나타냅니다. 이는 AllocatorAwareContainer , SequenceContainer , 그리고 ReversibleContainer 요구 사항을 충족하지만, 이동(move), 할당(assignment), 교환(swap) 및 const 한정 시퀀스 컨테이너에 대한 연산만 지원되며, 비교 함수의 의미론은 컨테이너에 요구되는 것과 다릅니다.
2) 기본 std::allocator 를 사용하는 basic_stacktrace 에 대한 편의성 타입 별칭.
3) polymorphic allocator 를 사용하는 basic_stacktrace 의 편의용 타입 별칭.

현재 평가 x 0 호출 시퀀스 는 현재 실행 스레드에서 다음과 같은 평가들의 시퀀스 (x 0 , ..., x n ) 로, i≥0 인 모든 x i 가 함수 호출 x i+1 내에 존재하는 경우를 말합니다.

stacktrace 는 호출 시퀀스의 근사적 표현이며 스택트레이스 엔트리로 구성됩니다.

스택트레이스 항목 은 스택트레이스에서의 평가를 나타냅니다. 이것은 C++ 표준 라이브러리에서 std::stacktrace_entry 로 표현됩니다.

목차

템플릿 매개변수

Allocator - 메모리를 획득/해제하고 해당 메모리의 요소를 생성/소멸시키는 데 사용되는 할당자. 이 타입은 Allocator 요구 사항을 충족해야 합니다. Allocator::value_type std::stacktrace_entry 가 아닌 경우 프로그램은 형식이 잘못되었습니다.

멤버 타입

멤버 타입 정의
value_type std::stacktrace_entry
const_reference const value_type &
reference value_type &
const_iterator 구현 정의된 const LegacyRandomAccessIterator 타입으로 random_access_iterator 를 모델링함
iterator const_iterator
reverse_iterator std:: reverse_iterator < iterator >
reverse_const_iterator std:: reverse_iterator < const_iterator >
difference_type 구현 정의된 부호 있는 정수 타입
size_type 구현 정의된 부호 없는 정수 타입
allocator_type Allocator

멤버 함수

새로운 basic_stacktrace 를 생성함
(public member function)
basic_stacktrace 를 파괴함
(public member function)
basic_stacktrace 에 할당함
(public member function)
[static]
현재 스택 트레이스 또는 주어진 부분을 얻음
(public static member function)
연결된 할당자를 반환함
(public member function)
반복자
시작 부분을 가리키는 반복자를 반환함
(public member function)
끝 부분을 가리키는 반복자를 반환함
(public member function)
시작 부분을 가리키는 역방향 반복자를 반환함
(public member function)
끝 부분을 가리키는 역방향 반복자를 반환함
(public member function)
용량
basic_stacktrace 가 비어 있는지 확인함
(public member function)
스택 트레이스 항목의 개수를 반환함
(public member function)
가능한 최대 스택 트레이스 항목 개수를 반환함
(public member function)
요소 접근
지정된 스택 트레이스 항목에 접근함
(public member function)
범위 검사와 함께 지정된 스택 트레이스 항목에 접근함
(public member function)
수정자
내용을 교환함
(public member function)

비멤버 함수

두 개의 basic_stacktrace 값의 크기와 내용을 비교함
(함수 템플릿)
std::swap 알고리즘을 특수화함
(함수 템플릿)
(C++23)
basic_stacktrace 의 설명이 포함된 문자열을 반환함
(함수 템플릿)
(C++23)
basic_stracktrace 의 스트림 출력을 수행함
(함수 템플릿)

헬퍼 클래스

std::basic_stacktrace 에 대한 해시 지원
(클래스 템플릿 특수화)
basic_stacktrace 에 대한 포매팅 지원
(클래스 템플릿 특수화)

참고 사항

커스텀 할당자 지원은 핫 경로나 임베디드 환경에서 basic_stacktrace 사용을 위해 제공됩니다. 사용자는 적절한 경우 스택이나 다른 위치에 stacktrace_entry 객체를 할당할 수 있습니다.

std::stacktrace_entry 객체들로 이루어진 시퀀스는 std::basic_stacktrace 에 의해 소유되며 변경 불가능합니다. 이 시퀀스는 비어 있거나 전체 스택 트레이스의 연속적인 구간을 나타냅니다.

boost :: stacktrace :: basic_stacktrace (사용 가능한 라이브러리: Boost.Stacktrace )는 std::basic_stacktrace 를 사용할 수 없을 때 대신 사용할 수 있습니다.

기능 테스트 매크로 표준 기능
__cpp_lib_stacktrace 202011L (C++23) 스택트레이스 라이브러리
__cpp_lib_formatters 202302L (C++23) 포맷팅 std::thread::id std::stacktrace

예제

Compiler Explorer를 사용하여 얻은 출력: msvc gcc .

#include <iostream>
#include <stacktrace>
int nested_func(int c)
{
    std::cout << std::stacktrace::current() << '\n';
    return c + 1;
}
int func(int b)
{
    return nested_func(b + 1);
}
int main()
{
    std::cout << func(777);
}

가능한 출력:

// msvc output (the lines ending with '⤶' arrows are split to fit the width):
0> C:\Users\ContainerAdministrator\AppData\Local\Temp\compiler-explorer-compiler20221122-⤶
31624-2ja1sf.8ytzw\example.cpp(6): output_s!nested_func+0x1F
1> C:\Users\ContainerAdministrator\AppData\Local\Temp\compiler-explorer-compiler20221122-⤶
31624-2ja1sf.8ytzw\example.cpp(12): output_s!func+0x15
2> C:\Users\ContainerAdministrator\AppData\Local\Temp\compiler-explorer-compiler20221122-⤶
31624-2ja1sf.8ytzw\example.cpp(15): output_s!main+0xE
3> D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(288): output_s!⤶
__scrt_common_main_seh+0x10C
4> KERNEL32!BaseThreadInitThunk+0x14
5> ntdll!RtlUserThreadStart+0x21
779
gcc output:
   0# nested_func(int) at /app/example.cpp:7
   1# func(int) at /app/example.cpp:13
   2#      at /app/example.cpp:18
   3#      at :0
   4#      at :0
   5# 
779

참고 항목

스택 트레이스에서 평가의 표현
(클래스)