+ // we are another level down from Walk(), so adjust the number of stack
+ // frames to skip accordingly
+ skip += 1;
+
+ // call addr2line only once since this call may be very slow
+ // (it has to load in memory the entire EXE of this app which may be quite
+ // big, especially if it contains debug info and is compiled statically!)
+ int numFrames = InitFrames(frames, m_depth - skip,
+ &ms_addresses[skip], &ms_symbols[skip]);
+
+ // now do user-defined operations on each frame
+ for ( int n = 0; n < numFrames; n++ )
+ OnStackFrame(frames[n]);
+}
+
+void wxStackWalker::FreeStack()
+{
+ // ms_symbols has been allocated by backtrace_symbols() and it's the responsibility
+ // of the caller, i.e. us, to free that pointer
+ if (ms_symbols)
+ free( ms_symbols );
+ ms_symbols = NULL;
+ m_depth = 0;
+}
+
+namespace
+{
+
+// Helper function to read a line from the file and return it without the
+// trailing newline. Line number is only used for error reporting.
+bool ReadLine(FILE* fp, unsigned long num, wxString* line)
+{
+ if ( !fgets(g_buf, WXSIZEOF(g_buf), fp) )
+ {
+ wxLogDebug(wxS("cannot read address information for stack frame #%lu"),
+ num);
+ return false;
+ }
+
+ *line = wxString::FromAscii(g_buf);
+ line->RemoveLast();
+
+ return true;
+}
+
+} // anonymous namespace