how to get function call stack

This is a discussion on how to get function call stack within the C Programming forums, part of the General Programming Boards category; Hello everyone, I am using C/C++ on Windows. I am wondering how to get the function call stack from my ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    how to get function call stack

    Hello everyone,


    I am using C/C++ on Windows. I am wondering how to get the function call stack from my application.

    For example,

    if function foo call function goo, then function goo call function zoo, in function goo, I want to output the function call stack (foo --> goo --> zoo), and in goo, output the function call stack (foo --> goo).

    Are there any samples of how to implement that? Does Windows runtime support this feature?


    thanks in advance,
    George

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Just use a debugger if all you want is a look at the call stack.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    224
    Maybe I don't understand what you're trying to do, but can't you just print the name of the function as you go along?

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    As Prelude says, u need to use a inbuilt debugger which came along with your compiler. So what compiler are u using.

    ssharish2005

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    To get the names of the functions like that you would have to be working pretty closely with the compiler and look up debug info and stuff, and then you might as well use the compilers debugger I suppose.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Years ago, working on an '05 (which had no stack), the compiler generated a static [compile-time] call-stack type thing...
    [Dave rambling again...]
    Gosh. If such capabilities were available so many years ago...
    [/Dave]
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Prelude,


    Quote Originally Posted by Prelude
    Just use a debugger if all you want is a look at the call stack.
    I am using release version program, and I can not use debugger (do you mean debugged in Visual Studio?).


    regards,
    George

  8. #8
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Yasir_Malik,


    Quote Originally Posted by Yasir_Malik
    Maybe I don't understand what you're trying to do, but can't you just print the name of the function as you go along?
    I want to know which function calls current function in some certain situations. For example, when function a calls functions b, and function b calls function c, in function c, I want to get the information like, a-->b-->c.

    Any ideas?


    regards,
    George

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thank you ssharish2005,


    Quote Originally Posted by ssharish2005
    As Prelude says, u need to use a inbuilt debugger which came along with your compiler. So what compiler are u using.

    ssharish2005
    Your answer makes senses. Could you recommend some samples/tutorials for me to begin with?


    regards,
    George

  10. #10
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thank you Tonto,


    Quote Originally Posted by Tonto
    To get the names of the functions like that you would have to be working pretty closely with the compiler and look up debug info and stuff, and then you might as well use the compilers debugger I suppose.
    I am looking for similar approaches as you mentioned above. But I am lacking of such experiences. So, could you recommend some samples/tutorials for me to begin with please?


    regards,
    George

  11. #11
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Dave_Sinkula,


    Quote Originally Posted by Dave_Sinkula
    Years ago, working on an '05 (which had no stack), the compiler generated a static [compile-time] call-stack type thing...
    [Dave rambling again...]
    Gosh. If such capabilities were available so many years ago...
    [/Dave]
    Seems that what you described is what I am looking for. Could you post some URLs or tutorials on this topic please?


    regards,
    George

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    An easy exercise is to take programs you've written in the past, then put known bugs back in to the code.

    Then practice using the debugger to "find" them again based on the observations of the faulty program.

    Debuggers come with manuals, read them.
    The rest is pretty much practice.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    This link has some funny stuff about reading debug info perhaps in a context that you'd like. http://www.eptacom.net/pubblicazioni...ng/assert.html

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  14. #14
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Salem,


    Quote Originally Posted by Salem
    An easy exercise is to take programs you've written in the past, then put known bugs back in to the code.

    Then practice using the debugger to "find" them again based on the observations of the faulty program.

    Debuggers come with manuals, read them.
    The rest is pretty much practice.
    I am a little confused. Do you mean the Visual Studio's built-in debugger?


    regards,
    George

  15. #15
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thank you Tonto,


    Quote Originally Posted by Tonto
    This link has some funny stuff about reading debug info perhaps in a context that you'd like. http://www.eptacom.net/pubblicazioni...ng/assert.html
    But I can not access the URL. Is the URL correct? If it is correct, it may be caused by the school proxy settings. So, could you send an alternative URL with the same content please?


    regards,
    George

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 08:32 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21