home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,773 of 33,346   
   DeMarcus to All   
   Re: Wouldn't it be good to refactor __LI   
   30 Dec 12 14:29:46   
   
   From: use_my_alias_here_at_hotmail_com@tellus.orb.dotsrc.org   
      
   >> In the preprocessor everything fits better. It's plain textual   
   >> substitution and all filenames and line numbers are known from   
   >> #including the files.   
   >>   
   >   
   > You have a point, maybe we should investigate some kind a compile   
   > time std::trace_point instead that doesn't mention anything about   
   > line or file but later could be reverse engineered to provide such   
   > information.   
   >   
   > When I think of it, a system's administrator has no use of line and   
   > file anyway, so it would be better with a big hash value in the   
   > log. Then this hash value could together with the right version of   
   > the source code provide the line and file, and maybe even the whole   
   > stack trace.   
   >   
   > It's a wild vision but it shouldn't be impossible.   
   >   
      
   I investigated stack tracing a bit further. It's actually simpler than   
   I thought, so I guess I will stop using __LINE__ completely since the   
   whole stack is more valuable.   
      
   Here's an example for Linux using backtrace:   
      
   Don't forget to include debug information with -g if using gcc.   
      
   #include    
   #include    
   #include    
   #include    
      
   std::string getStackTrace()   
   {   
        std::stringstream stackTrace;   
      
        void* addresses[64];   
        int nAddresses = backtrace( addresses, 64 );   
      
        for( int i = 0; i < nAddresses; i++ )   
           stackTrace << addresses[i] << std::endl;   
      
        return stackTrace.str();   
   }   
      
   void func2()   
   {   
        std::cout << getStackTrace() << std::endl;   
   }   
      
   void func1()   
   {   
        func2();   
   }   
      
   int main( int argc, char *argv[] )   
   {   
        func1();   
      
        return 0;   
   }   
      
   Then you can use the program addr2line to extract file name and line   
   number, like so: addr2line -e myprog 0x4711ab   
      
   I think for Windows there's something called StackWalker but I haven't   
   tried it.   
   http://www.codeproject.com/Articles/11132/Walking-the-callstack   
      
   Hope this was useful and Happy New Year to all of you!   
      
      
   Best regards,   
   Daniel   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca