How to print stack info when using assert?

P

PengYu.UT

Usually assert only print the current function. But I also need to know
which function called the current function. Is there anyway to make it
print out the whole stack?

Thanks,
Peng
 
P

Phlip

PengYu.UT said:
Usually assert only print the current function. But I also need to know
which function called the current function. Is there anyway to make it
print out the whole stack?

There are implementation-specific ways to walk the stack and find each
frame. They suck because finding the name of a function will be super-hard.

You may be familiar with languages designed to be interpreted, such as Java.
Languages designed to compile to machine language optimize much of their
data out.

I can write a system that does it with __FUNCTION__ (which is variously
supported), and a call to a macro at the top of each function to record its
name to a list. However, all of my assertions trigger a debugging
breakpoint. If you run your program in a debugger, it has a system to print
out the stack trace.

(You might also write a test case on the failing function directly, and then
find yourself tracing and debugging less...)
 
M

Marek Vondrak

Usually assert only print the current function. But I also need to know
which function called the current function. Is there anyway to make it
print out the whole stack?

Search this newsgroup. This question has been answered many times before.
-- Marek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top