c++ stack trace from unhandled exception? [duplicate]

Edited Answer: You can use std::set_terminate #include <cstdlib> #include <iostream> #include <stdexcept> #include <execinfo.h> void handler() { void *trace_elems[20]; int trace_elem_count(backtrace( trace_elems, 20 )); char **stack_syms(backtrace_symbols( trace_elems, trace_elem_count )); for ( int i = 0 ; i < trace_elem_count ; ++i ) { std::cout << stack_syms[i] << “\n”; } free( stack_syms ); exit(1); } int … Read more

Is there any way to set a breakpoint in gdb that is conditional on the call stack?

Update: There is now a better answer to this question: use GDB _is_caller convenience function. The need you describe comes up quite often, usually in the context of some_utility_fn being called a lot, but you only are interested in the call which comes from some_other_fn. You could probably script this entire interaction using the new … Read more

movq (%rsp), %rsp assembly stack pointer load?

movq (assuming you’re talking about x86) is a move of a quadword (64-bit value). This particular instruction: movq (%rsp), %rsp looks very much like code that will walk up through stack frames. This particular instruction grabs the quadword pointed to by the current stack pointer, and loads it into the stack pointer, overwriting it. By … Read more

Why does the Mac ABI require 16-byte stack alignment for x86-32?

From “Intel®64 and IA-32 Architectures Optimization Reference Manual”, section 4.4.2: “For best performance, the Streaming SIMD Extensions and Streaming SIMD Extensions 2 require their memory operands to be aligned to 16-byte boundaries. Unaligned data can cause significant performance penalties compared to aligned data.” From Appendix D: “It is important to ensure that the stack frame … Read more

How to filter call stack in Eclipse debug view for Java

Preparation: You can use step filters as described here. Then whenever you step-debug through your code, it will not jump into excluded packages or classes, e.g. from the JDK or some frameworks like Hibernate or Spring. But this is just a prerequisite. Solution: The stacktrace still contains frames from those those packages. In order to … Read more

What is the use of -fno-stack-protector?

In the standard/stock GCC, stack protector is off by default. However, some Linux distributions have patched GCC to turn it on by default. In my opinion, this is rather harmful, as it breaks the ability to compile anything that’s not linked against the standard userspace libraries unless the Makefile specifically disables stack protector. It would … Read more

tech