microsoft / microsoft/STL

<stacktrace>: unloading fails of a dll that first obtained stacktrace

Open
#4,855 0 comments 1 reaction 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

If one calls to_string( std::stacktrace::current() ); initially from a dynamic library (DLL), then this library fails to unload properly. In particular, global objects it in are not destroyed.

Command-line test case

DLL's code:

#include <iostream>
#include <stacktrace>

__declspec(dllexport) void findStacktrace() {
    (void)to_string( std::stacktrace::current() ); //#1
}

struct A {
    ~A() { std::cout << "~A()\n"; } //this is not executed unless line #1 is commented
} a;

Main module code:

__declspec(dllimport) void findStacktrace();

int main() {
    findStacktrace();
}

Full code and project files:
StacktraceDll.zip

Expected behavior

~A() destructor must be called irrespectively of previous calls to std::stacktrace.

STL version

Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.10.0

Additional context

Please note that to_string( boost::stacktrace::stacktrace() ) works fine in this scenario.

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 with the provided DLL and main-module reproduction, focusing on the exported findStacktrace entry point and the call to std::stacktrace::current followed by to_string. Confirm the unload behavior by checking whether A's destructor runs, then trace the stacktrace-related DLL state; done means the DLL unloads and ~A() executes after the call.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.