473,721 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting a stack trace

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, hints or advice is appreciated ;-)

Nov 15 '05 #1
6 2414
"milkyway" <d0******@hotma il.com> writes:
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, hints or advice is appreciated ;-)


There is no way to do this in portable standard C, unless you keep
track of the information yourself by adding code to each function to
maintain a program-wide stack of trace information.

There may be Unix- or Linux-specific ways to do this. If you want to
discuss them, please consider dropping comp.lang.c from the
newsgroups.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #2
Hi,

Will drop but do not know how to do this. Is there a program to collect
the stack trace under Linux

TIA

Nov 15 '05 #3
"milkyway" <d0******@hotma il.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
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, hints or advice is appreciated ;-)


If all you want to know is the function call sequence (not the whole stack
contents) that has led to this situation, then there's a solution: you
create your own stack-like structure, into which you can push either a
number or a string (i.e. char*) and then pop it off. Upon entry to each
function you push that function's ID (number or string) to the stack, upon
return you pop it off. At error you just dump the contents of the stack to
stdout, stderr or elsewhere. The dump will contain the exact call
sequence...

Alex
Nov 15 '05 #4

"milkyway" <d0******@hotma il.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Will drop but do not know how to do this. Is there a program to collect
the stack trace under Linux


Yes. Replace the assert(expr) with:

if (!(expr)) *(char*)0=0;

Compile with full debug info. Run the program under gdb. When the seg fault
trips, use the 'bt' command which will give you a stack trace. The same
technique works under Windows.

-Walter
www.digitalmars.com free C, C++, D compilers
Nov 15 '05 #5
milkyway wrote:
Hi,

Will drop but do not know how to do this.
Send an email to whatever support Google provide and ask them how.
Alternatively read whatever instructions they provide.

Whilst you are about it, learn to quote context (it is possibly and
there has been at least one post to comp.lang.c with instructions) and
complain at google for providing such a broken interface.
Is there a program to collect
the stack trace under Linux


You will have to hope someone on one of the other groups knows, since
comp.lang.c is not the right place.

Follow ups set to exclude comp.lang.c
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #6

"milkyway" <d0******@hotma il.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi,

Will drop but do not know how to do this. Is there a program to collect
the stack trace under Linux

TIA


There are glibc-specific ways to do this. Look in execinfo.h for
functions like backtrace, backtrace_symbo ls, and backtrace_symbo ls_fd.
Helpful as well will be addr2line and similar tools. Google around, now that
you know you are looking for a 'glibc' feature to provide 'backtrace'.

DS
Nov 15 '05 #7

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

Similar topics

3
6299
by: Jas Shultz | last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework installed. I have this problem with getting "out of disk space" errors. It doesn't happen all the time but it does happen. When I installed Sharepoint Services I got the error and had to reboot and then everything was fine. I get it sometime when running aspx pages. It's very odd. Usually, I can just remove the application and readd it from the properties menu in the IIS...
7
2513
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
1
4784
by: Jason Coyne | last post by:
I am trying to use the StackTrace class to get my current stack trace for some logging. Everything is working fine, except when I am using threading (specifically WaitCallBack and ThreadPool.QueueUserWorkItem) When I try to walk the stack from a location that has been called via QueueUserWorkItem, the stack stops at the point where the thread was launched. Is there a way to walk back further into the parent thread's stack (at the time...
0
2490
by: Jas Shultz | last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework installed. I have this problem with getting "out of disk space" errors. It doesn't happen all the time but it does happen. When I installed Sharepoint Services I got the error and had to reboot and then everything was fine. I get it sometime when running aspx pages. It's very odd. Usually, I can just remove the application and readd it from the properties menu in the IIS...
2
4387
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
4
3003
by: Jeff Jarrell | last post by:
I have a block of code that during development is prone to casting errors. It is mostly a DataReader type thing. It looks something like this. _prtPNID = myDLReader.GetString("prtPNID") _prtSKU = myDLReader.GetString("prtSKU") _prtPic = myDLReader.GetString("prtPic") _prtRsvQty = myDLReader.GetInteger("prtRsvQty")
3
7227
by: Dave Anson | last post by:
I have a custom exception and I want to write the information to the event log, including the Stack Trace. I can create the message and write to the event log no problem, but the Stack Trace is empty. How do I append the Stack Trace in the custom exception? I can get the inner exception stack trace from the system exceptions, but how do I get my own stack trace information. Thanks in advance
0
2005
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ((string)(this.GetPropertyValue("Address1")));
2
4603
by: Scott | last post by:
I'm debugging an xmlrpc client/server application. Often when an exception occurs in the server, I receive only a very short error message on the client. For example: xmlrpclib.Fault: <Fault 1: "<type 'exceptions.AssertionError'>:"> Presumably this is because xmlrpclib on the server is catching the exception, and only sending the exception name to the client, not the server's stack trace.
0
8730
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9131
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9064
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.