microsoft / microsoft/STL

`<stacktrace>`: stacktraces deeper than `USHORT_MAX` are truncated to `USHORT_MAX` by `stacktrace::current()`

Open
#2,776 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Describe the bug
see title - stacktraces grabbed by stacktrace::current() will always be at most the most recent USHORT_MAX entries.

This requires some amount of investigation to solve:

  • Is this a problem seen by real code? Do we even really need to worry about this?
  • Is this something we can solve? Can we loop over CaptureStackBackTrace() with Skip += 0xFFFF each time?
    • if not, should we fail in this case?

Command-line test case

C:\Temp>type stacktrace-deep.cpp
#include <stacktrace>
#include <iostream>

void print_stacktrace()
{
    auto s = std::stacktrace::current();
    if (s.empty())
    {
        std::cout << "failed to initialize\n";
    }
    else
    {
        std::cout << *s.rbegin() << '\n';
    }
}

#pragma optimize("", off) // inhibit TCO
void stackin(unsigned current_frame)
{
    if (current_frame == 0x10000)
    {
        print_stacktrace();
    }
    else
    {
        stackin(current_frame + 1);
    }
}
#pragma optimize("", on)

int main()
{
    stackin(0);
}

C:\Temp> cl /EHsc /W4 /WX /std:c++latest .\stacktrace-deep.cpp /F0x400000 /Z7 /nologo

stacktrace-deep.cpp
C:\Temp>.\stacktrace-deep.exe
C:\Temp\stacktrace-deep.cpp(26): stacktrace_deep!stackin+0x30

Expected behavior
It should print ntdll!RtlUserThreadStart+0x48

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the implementation of stacktrace::current() and its use of CaptureStackBackTrace(). Run the provided stacktrace-deep.cpp command-line reproduction with a 0x10000-frame recursion depth, then determine how deep frames should be handled. Done means the test reaches and reports ntdll!RtlUserThreadStart+0x48 instead of truncating at stackin.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.