[Lldb-commits] [lldb] r153785 - /lldb/trunk/source/Host/macosx/Host.mm
Greg Clayton
gclayton at apple.com
Fri Mar 30 16:47:35 PDT 2012
Author: gclayton
Date: Fri Mar 30 18:47:35 2012
New Revision: 153785
URL: http://llvm.org/viewvc/llvm-project?rev=153785&view=rev
Log:
Don't log to a temp file and delete it, just use the API that gives us a malloc'ed string array.
Modified:
lldb/trunk/source/Host/macosx/Host.mm
Modified: lldb/trunk/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=153785&r1=153784&r2=153785&view=diff
==============================================================================
--- lldb/trunk/source/Host/macosx/Host.mm (original)
+++ lldb/trunk/source/Host/macosx/Host.mm Fri Mar 30 18:47:35 2012
@@ -872,29 +872,18 @@
void
Host::Backtrace (Stream &strm, uint32_t max_frames)
{
- char backtrace_path[] = "/tmp/lldb-backtrace-tmp-XXXXXX";
- int backtrace_fd = ::mkstemp (backtrace_path);
- if (backtrace_fd != -1)
+ if (max_frames > 0)
{
std::vector<void *> frame_buffer (max_frames, NULL);
- int count = ::backtrace (&frame_buffer[0], frame_buffer.size());
- ::backtrace_symbols_fd (&frame_buffer[0], count, backtrace_fd);
-
- const off_t buffer_size = ::lseek(backtrace_fd, 0, SEEK_CUR);
-
- if (::lseek(backtrace_fd, 0, SEEK_SET) == 0)
- {
- char *buffer = (char *)::malloc (buffer_size);
- if (buffer)
- {
- ssize_t bytes_read = ::read (backtrace_fd, buffer, buffer_size);
- if (bytes_read > 0)
- strm.Write(buffer, bytes_read);
- ::free (buffer);
- }
+ int num_frames = ::backtrace (&frame_buffer[0], frame_buffer.size());
+ char** strs = ::backtrace_symbols (&frame_buffer[0], num_frames);
+ if (strs)
+ {
+ // Start at 1 to skip the "Host::Backtrace" frame
+ for (int i = 1; i < num_frames; ++i)
+ strm.Printf("%s\n", strs[i]);
+ ::free (strs);
}
- ::close (backtrace_fd);
- ::unlink (backtrace_path);
}
}
More information about the lldb-commits
mailing list