backtraceformat.cc

Go to the documentation of this file.
00001 /** @file rutz/backtraceformat.cc generate a human-readable string from
00002     a rutz::backtrace object */
00003 ///////////////////////////////////////////////////////////////////////
00004 //
00005 // Copyright (c) 2005-2007 University of Southern California
00006 // Rob Peters <rjpeters at klab dot caltech dot edu>
00007 //
00008 // created: Thu Jun 30 14:41:29 2005
00009 // commit: $Id: backtraceformat.cc 8249 2007-04-12 06:03:40Z rjpeters $
00010 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/backtraceformat.cc $
00011 //
00012 // --------------------------------------------------------------------
00013 //
00014 // This file is part of GroovX.
00015 //   [http://www.klab.caltech.edu/rjpeters/groovx/]
00016 //
00017 // GroovX is free software; you can redistribute it and/or modify it
00018 // under the terms of the GNU General Public License as published by
00019 // the Free Software Foundation; either version 2 of the License, or
00020 // (at your option) any later version.
00021 //
00022 // GroovX is distributed in the hope that it will be useful, but
00023 // WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025 // General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License
00028 // along with GroovX; if not, write to the Free Software Foundation,
00029 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00030 //
00031 ///////////////////////////////////////////////////////////////////////
00032 
00033 #ifndef GROOVX_RUTZ_BACKTRACEFORMAT_CC_UTC20050630214129_DEFINED
00034 #define GROOVX_RUTZ_BACKTRACEFORMAT_CC_UTC20050630214129_DEFINED
00035 
00036 #include "rutz/backtraceformat.h"
00037 
00038 #include "rutz/backtrace.h"
00039 #include "rutz/compat_snprintf.h"
00040 #include "rutz/fstring.h"
00041 #include "rutz/trace.h" // for rutz::prof
00042 
00043 #include <cstdio> // for snprintf()
00044 #include <sstream>
00045 
00046 rutz::fstring rutz::format(const rutz::backtrace& bt)
00047 {
00048   const unsigned int size = bt.size();
00049 
00050   if (size == 0) return rutz::fstring();
00051 
00052   std::ostringstream result;
00053 
00054   const int LINELEN = 256;
00055   char line[LINELEN];
00056 
00057   unsigned int s = size;
00058   int width = 0;
00059   while (s != 0)
00060     { s /= 10; ++width; }
00061 
00062   for (unsigned int i = size; i > 0; --i)
00063     {
00064       snprintf(&line[0], LINELEN, "[%*d] %-35s (%s:%d)\n",
00065                width,
00066                size - i,
00067                bt[i-1]->context_name(),
00068                bt[i-1]->src_file_name(),
00069                bt[i-1]->src_line_no());
00070 
00071       result << &line[0];
00072     }
00073 
00074   return rutz::fstring(result.str().c_str());
00075 }
00076 
00077 static const char __attribute__((used)) vcid_groovx_rutz_backtraceformat_cc_utc20050630214129[] = "$Id: backtraceformat.cc 8249 2007-04-12 06:03:40Z rjpeters $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/rutz/backtraceformat.cc $";
00078 #endif // !GROOVX_RUTZ_BACKTRACEFORMAT_CC_UTC20050630214129DEFINED
Generated on Sun May 8 08:42:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3