Changeset 20774
- Timestamp:
- 09/06/07 15:27:10 (1 year ago)
- Files:
-
- juggler/trunk/modules/vapor/vpr/SystemBase.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/vapor/vpr/SystemBase.cpp
r20773 r20774 36 36 #include <vpr/vprConfig.h> 37 37 38 #include <cstdlib> 39 #include <sstream> 40 #include <string> 41 38 42 #if defined(HAVE_BACKTRACE) 39 43 # include <sys/types.h> 40 44 # include <unistd.h> 41 45 # include <execinfo.h> 42 # include <sstream>43 46 #elif defined(VPR_OS_Darwin) 44 47 # include <iomanip> 45 # include <sstream>46 48 # include <vector> 49 # include <boost/algorithm/string/predicate.hpp> 47 50 48 51 extern "C" … … 61 64 # endif 62 65 63 # include <stdlib.h>64 66 # include <dbghelp.h> 65 67 # include <iomanip> 66 # include <sstream>67 68 # include <boost/format.hpp> 68 69 #endif 69 70 #include <string>71 70 72 71 #if (! defined(__INTEL_COMPILER) && defined(__GNUC__) && \ … … 208 207 #endif /* ifdef VPR_OS_Windows */ 209 208 210 std::string demangleTraceString(c har*traceLine)209 std::string demangleTraceString(const std::string& traceLine) 211 210 { 212 211 #ifdef USE_CXA_DEMANGLE … … 214 213 // and replace it with a demangled version of the name. 215 214 // Example: build.linux/stuff/classfile(_ZN4vpr11Someing33methodEv+0xd3) [0x80cfa29] 215 // For Mac OS X, things are a little different. A symbol may be of the 216 // form _ZN3vpr9ExceptionC2ERKSsS2_:F(0,1), or it may be a simple function 217 // name, probably with a leading underscore. 216 218 217 219 std::string trace_line(traceLine); … … 219 221 220 222 std::string::size_type start(std::string::npos), end(std::string::npos); 223 224 #if defined(VPR_OS_Darwin) 225 end = trace_line.find(":F("); 226 227 // If trace_line does not contain ":F(", then we set the start to be either 228 // 0 or 1 depending on whether trace_line starts with "_", and we set end 229 // to be the end of the string. 230 if ( std::string::npos == end ) 231 { 232 start = boost::algorithm::starts_with(trace_line, "_") ? 1 : 0; 233 end = trace_line.size(); 234 } 235 else 236 { 237 start = 0; 238 } 239 #else 221 240 start = trace_line.find("(_"); 222 241 if(std::string::npos != start) … … 224 243 end = trace_line.find_first_of("+)",start); 225 244 } 245 #endif 226 246 227 247 if(std::string::npos != end) 228 248 { 229 mangled_name.assign(trace_line, start+1, end-start-1); 249 std::string::size_type assign_start, assign_end; 250 #if defined(VPR_OS_Darwin) 251 assign_start = start; 252 assign_end = end; 253 #else 254 assign_start = start + 1; 255 assign_end = end - start - 1; 256 #endif 257 mangled_name.assign(trace_line, assign_start, assign_end); 258 230 259 int status; 231 260 char* demangled_buf = abi::__cxa_demangle(mangled_name.c_str(), NULL, … … 233 262 if(0==status) 234 263 { 235 demangled_name = std::string(demangled_buf); 236 free(demangled_buf); 237 238 trace_line.replace(start+1, (end-start-1), demangled_name); 264 #if defined(VPR_OS_Darwin) 265 trace_line = demangled_buf; 266 #else 267 trace_line.replace(start + 1, end - start - 1, demangled_buf); 268 #endif 269 std::free(demangled_buf); 239 270 } 240 271 else if(-1==status) … … 501 532 cur_frame.pc = frame->savedLR; 502 533 cur_frame.frame = reinterpret_cast<size_t>(frame); 503 cur_frame.name = getFunctionName(frame->savedLR, &cur_frame.offset); 534 535 const std::string func_name = getFunctionName(frame->savedLR, 536 &cur_frame.offset); 537 538 if ( ! func_name.empty() ) 539 { 540 cur_frame.name = demangleTraceString(func_name); 541 } 504 542 505 543 if ( cur_frame.pc != 0 )
