Questions tagged [stack-unwinding]

Stack-unwind will pop the top frame of the stack, depending on the language it may occur e.g. at the end of a code block, when returning from a called function, or during exception handling.

Stack-unwind will pop the top frame of the stack. Depending on the language this may occur e.g. at the end of a code block, when returning from a called function, or during exception handling.

Related tags: .

Related Q/A:

References:

128 questions
136
votes
4 answers

What are CFI directives in Gnu Assembler (GAS) used for?

There seem to be a .CFI directive after every line and also there are wide varieties of these ex.,.cfi_startproc , .cfi_endproc etc.. more here. .file "temp.c" .text .globl main .type main, @function main: .LFB0: .cfi_startproc …
claws
  • 52,236
  • 58
  • 146
  • 195
63
votes
6 answers

Why destructor is not called on exception?

I expected A::~A() to be called in this program, but it isn't: #include struct A { ~A() { std::cout << "~A()" << std::endl; } }; void f() { A a; throw "spam"; } int main() { f(); } However, if I change last line to int main()…
Constantin
  • 27,478
  • 10
  • 60
  • 79
24
votes
3 answers

How does Rust know whether to run the destructor during stack unwind?

The documentation for mem::uninitialized points out why it is dangerous/unsafe to use that function: calling drop on uninitialized memory is undefined behavior. So this code should be, I believe, undefined: let a: TypeWithDrop = unsafe {…
ustulation
  • 3,600
  • 25
  • 50
15
votes
2 answers

Different Behaviour Unwinding Stack in x64 and x32

Why in the scenario detailed below does the stack space increase in x64 but decrease in x32 with identical code? Background: Our customers can write scripts in a domain language which is interpretted at runtime using a recursive technique and…
Daniel James Bryars
  • 4,429
  • 3
  • 39
  • 57
15
votes
4 answers

How to get fullstacktrace using _Unwind_Backtrace on SIGSEGV

I handle SIGSEGV by code: int C() { int *i = NULL; *i = 10; // Crash there } int B() { return C(); } int A() { return B(); } int main(void) { struct sigaction handler; memset(&handler,0,sizeof(handler)); handler.sa_sigaction =…
Henry Pootle
  • 1,196
  • 1
  • 11
  • 30
15
votes
2 answers

Catching panic! when Rust called from C FFI, without spawning threads

I'm working on a Rust wrapper for the Duktape JavaScript interpreter. In a normal use case, the call stack will look like this: Rust: Arbitrary application code. Rust: My library wrapper. C: The Duktape interpreter. Rust: My Rust code. Rust:…
emk
  • 60,150
  • 6
  • 45
  • 50
14
votes
2 answers

C/C++ implementations where longjmp unwinds?

Are there major C/C++ implementations where the longjmp function "unwinds", i.e. where it interacts with destructors for automatic-storage objects, __attribute__((__cleanup__(...))), POSIX threads cancellation handlers, etc. rather than just…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
11
votes
4 answers

Java and C++ on Stack Unwinding issue

As far as I know, in case of an uncaught exception, C++ destroys the local variables immediately, Java releases the references and leaves the rest for the garbage collector. Is this right? What exactly is the difference between Java and C++ on this…
Feyyaz
  • 3,147
  • 4
  • 35
  • 50
11
votes
2 answers

Is there any trick to detect if an object is created during execution of another destructor?

This is kind of a follow up on Why can't Alexandrescu use std::uncaught_exception() to implement SCOPE_FAIL in ScopeGuard11? I would like to detect if someone is creating MyClass in the destructor of another class (or with an active destructor…
odinthenerd
  • 5,422
  • 1
  • 32
  • 61
10
votes
4 answers

Scope unwinding in PHP class constructors

I'm learning PHP classes and exceptions, and, coming from a C++ background, the following strikes me as odd: When the constructor of a derived class throws an exception, it appears that the destructor of the base class is not run…
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
9
votes
0 answers

Is it possible to unwind on panic in `#![no_std]` mode?

Is it possible to unwind on panic in #![no_std] mode, e.g. with a customized #[panic_handler]?
updogliu
  • 6,066
  • 7
  • 37
  • 50
9
votes
1 answer

Unable to set next statement when debugging

I am debugging my project in VS2015 and an exception is thrown in my code. When I try to set the next statement I get the error message displayed below. When I debug the same solution in VS2013 I am able to set the next statement without any…
9
votes
6 answers

How is destroying local variables when a block is exited normally called in C++?

C++ automagically calls destructors of all local variables in the block in reverse order regardless of whether the block is exited normally (control falls through) or an exception is thrown. Looks like the term stack unwinding only applies to the…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
9
votes
4 answers

.Net - what is an "unwind"?

While answering this question I noticed that I got the following dialog while atempting to move the "cursor" while an exception was being handled: Unable to set the next statement to this location. The attempt to unwind the callstack…
Justin
  • 84,773
  • 49
  • 224
  • 367
8
votes
1 answer

What kind of stack unwinding libraries do exist and what's the difference?

Trying to build my own non-GNU cross-platform C++ environment, I have faced the fact that I don't really understand the basics of the stack unwinding. The environment I build is as follows: libc++ ← libc++abi ← libunwind (or some other…
abyss.7
  • 13,882
  • 11
  • 56
  • 100
1
2 3
8 9