473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to print stack info when using assert?

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

Apr 15 '06 #1
2 7558
PengYu.UT wrote:
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...)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 15 '06 #2
> 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
Apr 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Andrew | last post by:
Last night I was reading about implementing my own stack. The example given pushes items on and off the stack at the start and end of each procedure (ie. in a std module). What's not so clear is...
12
by: neutrino | last post by:
Greetings to the Python gurus, I have a binary file and wish to see the "raw" content of it. So I open it in binary mode, and read one byte at a time to a variable, which will be of the string...
6
by: milkyway | last post by:
Hello out there, When one gets an error, they can use fprintf (Stdout, "File %s Line %d\n", __FILE__, __LINE__); Is there a similar way where on can print out the stack trace? Any help,...
2
by: Verane | last post by:
Hi all, I am writing code in C# using visual studio .NET 2003. I use System.Diagnostics.Trace.Assert, and when I get an assertion at run time, I can see the call stack. But for each line of the...
3
by: Robert Schuldenfrei | last post by:
Dear NG, I am making progress processing trees. I can "span" a tree if I make wise use of the C# stack methods, push() and pop(). What I want to place on the stack are rows from a data table. ...
15
by: Jim B. Wilson | last post by:
Am I nuts? Or only profoundly confused? I expected the this little script to print "0": class foo(int): def __init__(self, value): self = value & 0xF print foo(0x10) Instead, it prints...
5
by: Joel | last post by:
I would like to learn if there is any difference between the stack that MSIL uses for each method for executing instructions and the stack that it uses for storing Value types. Are they the same?...
15
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which...
4
by: call_me_anything | last post by:
Here is a code to have a debug printf : #ifdef DEBUG #define DEBUG_printf(...) {printf(":",__FUNCTION__);printf(__VA_ARGS__);printf("\n");} #else #define DEBUG #endif int main () {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.