473,326 Members | 2,192 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,326 software developers and data experts.

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 2394
"milkyway" <d0******@hotmail.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_Keith) 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******@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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******@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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_symbols, and backtrace_symbols_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
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...
7
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
1
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...
0
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...
2
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
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")...
3
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...
0
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 ...
2
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:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.