[Lldb-commits] [lldb] r151069 - in /lldb/trunk: include/lldb/Core/StreamCallback.h source/Core/StreamCallback.cpp
Jim Ingham
jingham at apple.com
Tue Feb 21 10:22:38 PST 2012
Author: jingham
Date: Tue Feb 21 12:22:37 2012
New Revision: 151069
URL: http://llvm.org/viewvc/llvm-project?rev=151069&view=rev
Log:
Forgot to add two files from the last checkin.
Added:
lldb/trunk/include/lldb/Core/StreamCallback.h
lldb/trunk/source/Core/StreamCallback.cpp
Added: lldb/trunk/include/lldb/Core/StreamCallback.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/StreamCallback.h?rev=151069&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Core/StreamCallback.h (added)
+++ lldb/trunk/include/lldb/Core/StreamCallback.h Tue Feb 21 12:22:37 2012
@@ -0,0 +1,47 @@
+//===-- StreamCallback.h -----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_StreamCallback_h_
+#define liblldb_StreamCallback_h_
+
+#include <string>
+
+#include "lldb/Core/Stream.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Host/Mutex.h"
+
+namespace lldb_private {
+
+class StreamCallback :
+ public Stream
+{
+public:
+ StreamCallback (lldb::LogOutputCallback callback, void *baton);
+
+ virtual ~StreamCallback ();
+
+ virtual void
+ Flush ();
+
+ virtual int
+ Write (const void *src, size_t src_len);
+
+
+private:
+ typedef std::map<lldb::tid_t, StreamString> collection;
+ lldb::LogOutputCallback m_callback;
+ void *m_baton;
+ collection m_accumulated_data;
+ Mutex m_collection_mutex;
+
+ StreamString &FindStreamForThread(lldb::tid_t cur_tid);
+};
+
+} // namespace lldb_private
+#endif // #ifndef liblldb_StreamCallback_h
Added: lldb/trunk/source/Core/StreamCallback.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamCallback.cpp?rev=151069&view=auto
==============================================================================
--- lldb/trunk/source/Core/StreamCallback.cpp (added)
+++ lldb/trunk/source/Core/StreamCallback.cpp Tue Feb 21 12:22:37 2012
@@ -0,0 +1,65 @@
+//===-- StreamCallback.cpp -------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#include "lldb/lldb-private.h"
+#include "lldb/Core/Broadcaster.h"
+#include "lldb/Core/Event.h"
+#include "lldb/Core/StreamCallback.h"
+#include "lldb/Host/Host.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+
+StreamCallback::StreamCallback (lldb::LogOutputCallback callback, void *baton) :
+ Stream (0, 4, eByteOrderBig),
+ m_callback (callback),
+ m_baton (baton),
+ m_accumulated_data (),
+ m_collection_mutex ()
+{
+}
+
+StreamCallback::~StreamCallback ()
+{
+}
+
+StreamString &
+StreamCallback::FindStreamForThread(lldb::tid_t cur_tid)
+{
+ Mutex::Locker (m_collection_mutex);
+ collection::iterator iter, end_iter = m_accumulated_data.end();
+ iter = m_accumulated_data.find (cur_tid);
+ if (iter == m_accumulated_data.end())
+ {
+ std::pair<collection::iterator, bool> ret;
+ ret = m_accumulated_data.insert(std::pair<lldb::tid_t,StreamString>(cur_tid, StreamString()));
+ iter = ret.first;
+ }
+ return (*iter).second;
+}
+
+void
+StreamCallback::Flush ()
+{
+ lldb::tid_t cur_tid = Host::GetCurrentThreadID();
+ StreamString &out_stream = FindStreamForThread(cur_tid);
+ m_callback (out_stream.GetData(), m_baton);
+ out_stream.Clear();
+}
+
+int
+StreamCallback::Write (const void *s, size_t length)
+{
+ lldb::tid_t cur_tid = Host::GetCurrentThreadID();
+ FindStreamForThread(cur_tid).Write (s, length);
+ return length;
+}
More information about the lldb-commits
mailing list