diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/source/Utility/SharingPtr.cpp | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.bz2 |
*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
Diffstat (limited to 'lldb/source/Utility/SharingPtr.cpp')
-rw-r--r-- | lldb/source/Utility/SharingPtr.cpp | 193 |
1 files changed, 80 insertions, 113 deletions
diff --git a/lldb/source/Utility/SharingPtr.cpp b/lldb/source/Utility/SharingPtr.cpp index 7eedeb0..cf32b21 100644 --- a/lldb/source/Utility/SharingPtr.cpp +++ b/lldb/source/Utility/SharingPtr.cpp @@ -9,12 +9,12 @@ #include "lldb/Utility/SharingPtr.h" -#if defined (ENABLE_SP_LOGGING) +#if defined(ENABLE_SP_LOGGING) // If ENABLE_SP_LOGGING is defined, then log all shared pointer assignments // and allow them to be queried using a pointer by a call to: -#include <execinfo.h> #include <assert.h> +#include <execinfo.h> #include "llvm/ADT/STLExtras.h" @@ -22,147 +22,114 @@ #include <mutex> #include <vector> -class Backtrace -{ +class Backtrace { public: - Backtrace (); - - ~Backtrace (); - - void - GetFrames (); - - void - Dump () const; - + Backtrace(); + + ~Backtrace(); + + void GetFrames(); + + void Dump() const; + private: - void *m_sp_this; - std::vector<void *> m_frames; + void *m_sp_this; + std::vector<void *> m_frames; }; +Backtrace::Backtrace() : m_frames() {} -Backtrace::Backtrace () : m_frames() -{ -} - -Backtrace::~Backtrace () -{ -} +Backtrace::~Backtrace() {} -void -Backtrace::GetFrames () -{ - void *frames[1024]; - const int count = ::backtrace (frames, llvm::array_lengthof(frames)); - if (count > 2) - m_frames.assign (frames + 2, frames + (count - 2)); +void Backtrace::GetFrames() { + void *frames[1024]; + const int count = ::backtrace(frames, llvm::array_lengthof(frames)); + if (count > 2) + m_frames.assign(frames + 2, frames + (count - 2)); } -void -Backtrace::Dump () const -{ - if (!m_frames.empty()) - ::backtrace_symbols_fd (m_frames.data(), m_frames.size(), STDOUT_FILENO); - write (STDOUT_FILENO, "\n\n", 2); +void Backtrace::Dump() const { + if (!m_frames.empty()) + ::backtrace_symbols_fd(m_frames.data(), m_frames.size(), STDOUT_FILENO); + write(STDOUT_FILENO, "\n\n", 2); } -extern "C" void track_sp (void *sp_this, void *ptr, long use_count) -{ - typedef std::pair<void *, Backtrace> PtrBacktracePair; - typedef std::map<void *, PtrBacktracePair> PtrToBacktraceMap; - static std::mutex g_mutex; - std::lock_guard<std::mutex> guard(g_mutex); - static PtrToBacktraceMap g_map; - - if (sp_this) - { - printf ("sp(%p) -> %p %lu\n", sp_this, ptr, use_count); - - if (ptr) - { - Backtrace bt; - bt.GetFrames(); - g_map[sp_this] = std::make_pair(ptr, bt); - } - else - { - g_map.erase (sp_this); - } +extern "C" void track_sp(void *sp_this, void *ptr, long use_count) { + typedef std::pair<void *, Backtrace> PtrBacktracePair; + typedef std::map<void *, PtrBacktracePair> PtrToBacktraceMap; + static std::mutex g_mutex; + std::lock_guard<std::mutex> guard(g_mutex); + static PtrToBacktraceMap g_map; + + if (sp_this) { + printf("sp(%p) -> %p %lu\n", sp_this, ptr, use_count); + + if (ptr) { + Backtrace bt; + bt.GetFrames(); + g_map[sp_this] = std::make_pair(ptr, bt); + } else { + g_map.erase(sp_this); } - else - { - if (ptr) - printf ("Searching for shared pointers that are tracking %p: ", ptr); - else - printf ("Dump all live shared pointres: "); - - uint32_t matches = 0; - PtrToBacktraceMap::iterator pos, end = g_map.end(); - for (pos = g_map.begin(); pos != end; ++pos) - { - if (ptr == NULL || pos->second.first == ptr) - { - ++matches; - printf ("\nsp(%p): %p\n", pos->first, pos->second.first); - pos->second.second.Dump(); - } - } - if (matches == 0) - { - printf ("none.\n"); - } + } else { + if (ptr) + printf("Searching for shared pointers that are tracking %p: ", ptr); + else + printf("Dump all live shared pointres: "); + + uint32_t matches = 0; + PtrToBacktraceMap::iterator pos, end = g_map.end(); + for (pos = g_map.begin(); pos != end; ++pos) { + if (ptr == NULL || pos->second.first == ptr) { + ++matches; + printf("\nsp(%p): %p\n", pos->first, pos->second.first); + pos->second.second.Dump(); + } } + if (matches == 0) { + printf("none.\n"); + } + } } -// Put dump_sp_refs in the lldb namespace to it gets through our exports lists filter in the LLDB.framework or lldb.so +// Put dump_sp_refs in the lldb namespace to it gets through our exports lists +// filter in the LLDB.framework or lldb.so namespace lldb { - - void dump_sp_refs (void *ptr) - { - // Use a specially crafted call to "track_sp" which will - // dump info on all live shared pointers that reference "ptr" - track_sp (NULL, ptr, 0); - } - + +void dump_sp_refs(void *ptr) { + // Use a specially crafted call to "track_sp" which will + // dump info on all live shared pointers that reference "ptr" + track_sp(NULL, ptr, 0); +} } #endif namespace lldb_private { -namespace imp -{ +namespace imp { +shared_count::~shared_count() {} - shared_count::~shared_count() - { - } - - void - shared_count::add_shared() - { +void shared_count::add_shared() { #ifdef _MSC_VER - _InterlockedIncrement(&shared_owners_); + _InterlockedIncrement(&shared_owners_); #else - ++shared_owners_; + ++shared_owners_; #endif - } +} - void - shared_count::release_shared() - { +void shared_count::release_shared() { #ifdef _MSC_VER - if (_InterlockedDecrement(&shared_owners_) == -1) + if (_InterlockedDecrement(&shared_owners_) == -1) #else - if (--shared_owners_ == -1) + if (--shared_owners_ == -1) #endif - { - on_zero_shared(); - delete this; - } - } + { + on_zero_shared(); + delete this; + } +} } // imp - } // namespace lldb - |