Switched over to using the new lldb::SharingPtr from Howard Hinnant.

We need to put this in LLDB since we need to vend this in our API
because our public API uses shared pointers to our private objects.

Removed a deprecated file: include/lldb/Host/Types.h

Added the new SharingPtr.cpp/.h files into source/Utility.

Added a shell script build phase that fixes up all headers in the
LLDB.framework.

llvm-svn: 105895
This commit is contained in:
Greg Clayton 2010-06-12 17:45:57 +00:00
parent 250a21b79b
commit ef59f829e4
13 changed files with 330 additions and 135 deletions

View File

@ -1,98 +0,0 @@
//===-- Types.h -------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#if 0
#ifndef liblldb_host_types_h_
#define liblldb_host_types_h_
//----------------------------------------------------------------------
//----------------------------------------------------------------------
// MACOSX START
//----------------------------------------------------------------------
//----------------------------------------------------------------------
#include <assert.h>
#include <mach/mach_types.h>
#include <machine/endian.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/syslimits.h>
#include <unistd.h>
#ifndef NO_RTTI
//----------------------------------------------------------------------
// And source files that may not have RTTI enabled during their
// compilation will want to do a "#define NO_RTTI" before including the
// lldb-include.h file.
//----------------------------------------------------------------------
#include <tr1/memory> // for std::tr1::shared_ptr
#endif
//----------------------------------------------------------------------
// All host systems must define:
// liblldb::condition_t The native condition type (or a substitute class) for conditions on the host system.
// liblldb::mutex_t The native mutex type for mutex objects on the host system.
// liblldb::thread_t The native thread type for spawned threads on the system
// liblldb::thread_arg_t The type of the one any only thread creation argument for the host system
// liblldb::thread_result_t The return type that gets returned when a thread finishes.
// liblldb::thread_func_t The function prototype used to spawn a thread on the host system.
// liblldb::SharedPtr The template that wraps up the host version of a reference counted pointer (like boost::shared_ptr)
// #define LLDB_INVALID_PROCESS_ID ...
// #define LLDB_INVALID_THREAD_ID ...
// #define LLDB_INVALID_HOST_THREAD ...
//----------------------------------------------------------------------
// TODO: Add a bunch of ifdefs to determine the host system and what
// things should be defined. Currently MacOSX is being assumed by default
// since that is what lldb was first developed for.
namespace lldb_private {
//----------------------------------------------------------------------
// MacOSX Types
//----------------------------------------------------------------------
typedef ::pthread_mutex_t mutex_t;
typedef pthread_cond_t condition_t;
typedef pthread_t thread_t; // Host thread type
typedef void * thread_arg_t; // Host thread argument type
typedef void * thread_result_t; // Host thread result type
typedef void * (*thread_func_t)(void *); // Host thread function type
#ifndef NO_RTTI
// The template below can be used in a few useful ways:
//
// // Make a single shared pointer a class Foo
// lldb::SharePtr<Foo>::Type foo_sp;
//
// // Make a typedef to a Foo shared pointer
// typedef lldb::SharePtr<Foo>::Type FooSP;
//
template<typename _Tp>
struct SharedPtr
{
typedef std::tr1::shared_ptr<_Tp> Type;
};
#endif
} // namespace lldb_private
#define LLDB_INVALID_HOST_THREAD ((lldb::thread_t)NULL)
#define LLDB_INVALID_HOST_TIME { 0, 0 }
//----------------------------------------------------------------------
//----------------------------------------------------------------------
// MACOSX END
//----------------------------------------------------------------------
//----------------------------------------------------------------------
#endif // liblldb_host_types_h_
#endif

View File

@ -12,13 +12,6 @@
#if defined(__cplusplus)
#ifndef NO_RTTI
//----------------------------------------------------------------------
// And source files that may not have RTTI enabled during their
// compilation will want to do a "#define NO_RTTI" before including the
// lldb-include.h file.
//----------------------------------------------------------------------
#include "lldb/lldb-types.h"
#include "lldb/lldb-forward.h"
@ -69,8 +62,6 @@ namespace lldb {
} // namespace lldb
#endif // #ifndef NO_RTTI
#endif // #if defined(__cplusplus)
#endif // LLDB_forward_rtti_h_

View File

@ -11,7 +11,6 @@
#define liblldb_lldb_interfaces_h_
#if defined(__cplusplus)
#ifndef NO_RTTI
#include "lldb/lldb-private.h"
@ -31,7 +30,6 @@ namespace lldb_private
typedef ThreadPlan * (*ThreadPlanShouldStopHereCallback) (ThreadPlan *current_plan, Flags &flags, void *baton);
} // namespace lldb_private
#endif // #ifndef NO_RTTI
#endif // #if defined(__cplusplus)
#endif // liblldb_lldb_interfaces_h_

View File

@ -68,13 +68,9 @@ IsLogVerbose ();
void
DisableLog ();
#ifndef NO_RTTI
Log *
EnableLog (lldb::StreamSP &log_stream_sp, uint32_t log_options, Args &args, Stream *feedback_strm);
#endif
void
ListLogCategories (Stream *strm);

View File

@ -26,17 +26,7 @@
#include <stdbool.h>
#include <unistd.h>
#ifndef NO_RTTI
//----------------------------------------------------------------------
// And source files that may not have RTTI enabled during their
// compilation will want to do a "#define NO_RTTI" before including the
// lldb-include.h file.
//----------------------------------------------------------------------
#include <tr1/memory> // for std::tr1::shared_ptr
#endif
#include "SharingPtr.h"
//----------------------------------------------------------------------
// All host systems must define:
@ -67,7 +57,6 @@ namespace lldb {
typedef void * thread_result_t; // Host thread result type
typedef void * (*thread_func_t)(void *); // Host thread function type
#ifndef NO_RTTI
// The template below can be used in a few useful ways:
//
// // Make a single shared pointer a class Foo
@ -79,9 +68,8 @@ namespace lldb {
template<typename _Tp>
struct SharedPtr
{
typedef std::tr1::shared_ptr<_Tp> Type;
typedef lldb::SharingPtr<_Tp> Type;
};
#endif
} // namespace lldb

View File

@ -10,6 +10,8 @@
260C876A10F538E700BB2B04 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 260C876910F538E700BB2B04 /* Foundation.framework */; };
261744781168585B005ADD65 /* SBType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 261744771168585B005ADD65 /* SBType.cpp */; };
2617447A11685869005ADD65 /* SBType.h in Headers */ = {isa = PBXBuildFile; fileRef = 2617447911685869005ADD65 /* SBType.h */; settings = {ATTRIBUTES = (Public, ); }; };
261B5A5411C3F2AD00AABD0A /* SharingPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 261B5A5211C3F2AD00AABD0A /* SharingPtr.cpp */; };
261B5A5511C3F2AD00AABD0A /* SharingPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 261B5A5311C3F2AD00AABD0A /* SharingPtr.h */; settings = {ATTRIBUTES = (Public, ); }; };
262CFC7711A4510000946C6C /* debugserver in Resources */ = {isa = PBXBuildFile; fileRef = 26CE05A0115C31E50022F371 /* debugserver */; };
265ABF6310F42EE900531910 /* DebugSymbols.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 265ABF6210F42EE900531910 /* DebugSymbols.framework */; };
2668020E115FD12C008E1FE4 /* lldb-defines.h in Headers */ = {isa = PBXBuildFile; fileRef = 26BC7C2510F1B3BC00F91463 /* lldb-defines.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -497,6 +499,8 @@
26109B3C1155D70100CC3529 /* LogChannelDWARF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogChannelDWARF.h; sourceTree = "<group>"; };
261744771168585B005ADD65 /* SBType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBType.cpp; path = source/API/SBType.cpp; sourceTree = "<group>"; };
2617447911685869005ADD65 /* SBType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBType.h; path = include/lldb/API/SBType.h; sourceTree = "<group>"; };
261B5A5211C3F2AD00AABD0A /* SharingPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SharingPtr.cpp; path = source/Utility/SharingPtr.cpp; sourceTree = "<group>"; };
261B5A5311C3F2AD00AABD0A /* SharingPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharingPtr.h; path = source/Utility/SharingPtr.h; sourceTree = "<group>"; };
261E18CC1148966100BADCD3 /* GDBRemoteRegisterContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GDBRemoteRegisterContext.h; path = "source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.h"; sourceTree = "<group>"; };
261E18CD1148966100BADCD3 /* GDBRemoteRegisterContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GDBRemoteRegisterContext.cpp; path = "source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp"; sourceTree = "<group>"; };
263664921140A4930075843B /* Debugger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Debugger.cpp; path = source/Core/Debugger.cpp; sourceTree = "<group>"; };
@ -676,7 +680,6 @@
26BC7DD410F1B7D500F91463 /* Host.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Host.h; path = include/lldb/Host/Host.h; sourceTree = "<group>"; };
26BC7DD510F1B7D500F91463 /* Mutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Mutex.h; path = include/lldb/Host/Mutex.h; sourceTree = "<group>"; };
26BC7DD610F1B7D500F91463 /* Predicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Predicate.h; path = include/lldb/Host/Predicate.h; sourceTree = "<group>"; };
26BC7DD710F1B7D500F91463 /* Types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Types.h; path = include/lldb/Host/Types.h; sourceTree = "<group>"; };
26BC7DE110F1B7F900F91463 /* CommandContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandContext.h; path = include/lldb/Interpreter/CommandContext.h; sourceTree = "<group>"; };
26BC7DE210F1B7F900F91463 /* CommandInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandInterpreter.h; path = include/lldb/Interpreter/CommandInterpreter.h; sourceTree = "<group>"; };
26BC7DE310F1B7F900F91463 /* CommandObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObject.h; path = include/lldb/Interpreter/CommandObject.h; sourceTree = "<group>"; };
@ -1497,6 +1500,8 @@
2682F168115ED9C800CCFF99 /* Utility */ = {
isa = PBXGroup;
children = (
261B5A5211C3F2AD00AABD0A /* SharingPtr.cpp */,
261B5A5311C3F2AD00AABD0A /* SharingPtr.h */,
26F996A7119B79C300412154 /* ARM_DWARF_Registers.h */,
26F996A8119B79C300412154 /* ARM_GCC_Registers.h */,
2660D9F611922A1300958FBD /* StringExtractor.cpp */,
@ -1862,7 +1867,6 @@
26BC7DD610F1B7D500F91463 /* Predicate.h */,
2689B0A4113EE3CD00A4AEDB /* Symbols.h */,
26B4E26E112F35F700AB3F64 /* TimeValue.h */,
26BC7DD710F1B7D500F91463 /* Types.h */,
);
name = Host;
sourceTree = "<group>";
@ -2186,6 +2190,7 @@
49F1A74A11B338AE003ED505 /* ClangExpressionDeclMap.h in Headers */,
49D7072711B5AD03001AD875 /* ClangASTSource.h in Headers */,
4CA9637C11B6E99A00780E28 /* CommandObjectApropos.h in Headers */,
261B5A5511C3F2AD00AABD0A /* SharingPtr.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -2202,6 +2207,7 @@
26680203115FD0ED008E1FE4 /* Resources */,
26680204115FD0ED008E1FE4 /* Sources */,
26680205115FD0ED008E1FE4 /* Frameworks */,
261B5A7511C3FA6F00AABD0A /* Fixup Framework Headers */,
9A19ACE2116563A700E0D453 /* Finish swig wrapper classes (lldb) */,
);
buildRules = (
@ -2278,6 +2284,20 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
261B5A7511C3FA6F00AABD0A /* Fixup Framework Headers */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Fixup Framework Headers";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd \"${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}\"\nfor file in *.h\ndo\n\tsed -i '' 's/\\(#include[ ]*\\)\"lldb\\/\\(API\\/\\)\\{0,1\\}\\(.*\\)\"/\\1 <LLDB\\/\\3>/1' \"$file\"\ndone\n";
};
26D5B06111B07468009A862E /* Build llvm and clang */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -2622,6 +2642,7 @@
49D7072911B5AD11001AD875 /* ClangASTSource.cpp in Sources */,
4CA9637B11B6E99A00780E28 /* CommandObjectApropos.cpp in Sources */,
AF94005911C03F6500085DB9 /* SymbolVendor.cpp in Sources */,
261B5A5411C3F2AD00AABD0A /* SharingPtr.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -97,7 +97,6 @@ $opt_h and help();
our %seds = (
'\s+$' => "\n", # Get rid of spaces at the end of a line
'^\s+$' => "\n", # Get rid spaces on lines that are all spaces
'^\s*//\s*[Cc]opyright.*$' => '//', # Get rid of all copyright lines
);

View File

@ -7,8 +7,6 @@
*
*/
#define NO_RTTI
#include "clang/AST/ASTContext.h"
#include "lldb/Expression/ClangASTSource.h"
#include "lldb/Expression/ClangExpression.h"

View File

@ -58,7 +58,6 @@
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#define NO_RTTI
#include "lldb/Core/StreamString.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Core/dwarf.h"

View File

@ -14,7 +14,6 @@
// Other libraries and framework includes
#include "clang/AST/RecordLayout.h"
#define NO_RTTI
#include "lldb/Core/dwarf.h"
#include "lldb/Core/Scalar.h"
#include "lldb/Core/StreamString.h"

View File

@ -7,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
#define NO_RTTI
// C Includes
// C++ Includes
// Other libraries and framework includes

View File

@ -0,0 +1,53 @@
//===---------------------SharingPtr.cpp ------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "SharingPtr.h"
namespace lldb {
namespace imp
{
template <class T>
inline T
increment(T& t)
{
return __sync_add_and_fetch(&t, 1);
}
template <class T>
inline T
decrement(T& t)
{
return __sync_add_and_fetch(&t, -1);
}
shared_count::~shared_count()
{
}
void
shared_count::add_shared()
{
increment(shared_owners_);
}
void
shared_count::release_shared()
{
if (decrement(shared_owners_) == -1)
{
on_zero_shared();
delete this;
}
}
} // imp
} // namespace lldb

View File

@ -0,0 +1,252 @@
//===---------------------SharingPtr.h --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef utility_SharingPtr_h_
#define utility_SharingPtr_h_
#include <algorithm>
namespace lldb {
namespace imp {
class shared_count
{
shared_count(const shared_count&);
shared_count& operator=(const shared_count&);
protected:
long shared_owners_;
virtual ~shared_count();
private:
virtual void on_zero_shared() = 0;
public:
explicit shared_count(long refs = 0)
: shared_owners_(refs) {}
void add_shared();
void release_shared();
long use_count() const {return shared_owners_ + 1;}
};
template <class T>
class shared_ptr_pointer
: public shared_count
{
T data_;
public:
shared_ptr_pointer(T p)
: data_(p) {}
private:
virtual void on_zero_shared();
};
template <class T>
void
shared_ptr_pointer<T>::on_zero_shared()
{
delete data_;
}
} // namespace
template<class T>
class SharingPtr
{
public:
typedef T element_type;
private:
element_type* ptr_;
imp::shared_count* cntrl_;
public:
SharingPtr();
template<class Y> explicit SharingPtr(Y* p);
template<class Y> SharingPtr(const SharingPtr<Y>& r, element_type *p);
SharingPtr(const SharingPtr& r);
template<class Y>
SharingPtr(const SharingPtr<Y>& r);
~SharingPtr();
SharingPtr& operator=(const SharingPtr& r);
template<class Y> SharingPtr& operator=(const SharingPtr<Y>& r);
void swap(SharingPtr& r);
void reset();
template<class Y> void reset(Y* p);
element_type* get() const {return ptr_;}
element_type& operator*() const {return *ptr_;}
element_type* operator->() const {return ptr_;}
long use_count() const {return cntrl_ ? cntrl_->use_count() : 0;}
bool unique() const {return use_count() == 1;}
bool empty() const {return cntrl_ == 0;}
operator void*() const { return get(); }
private:
template <class U> friend class SharingPtr;
};
template<class T>
inline
SharingPtr<T>::SharingPtr()
: ptr_(0),
cntrl_(0)
{
}
template<class T>
template<class Y>
SharingPtr<T>::SharingPtr(Y* p)
: ptr_(p)
{
std::auto_ptr<Y> hold(p);
typedef imp::shared_ptr_pointer<Y*> _CntrlBlk;
cntrl_ = new _CntrlBlk(p);
hold.release();
}
template<class T>
template<class Y>
inline
SharingPtr<T>::SharingPtr(const SharingPtr<Y>& r, element_type *p)
: ptr_(p),
cntrl_(r.cntrl_)
{
if (cntrl_)
cntrl_->add_shared();
}
template<class T>
inline
SharingPtr<T>::SharingPtr(const SharingPtr& r)
: ptr_(r.ptr_),
cntrl_(r.cntrl_)
{
if (cntrl_)
cntrl_->add_shared();
}
template<class T>
template<class Y>
inline
SharingPtr<T>::SharingPtr(const SharingPtr<Y>& r)
: ptr_(r.ptr_),
cntrl_(r.cntrl_)
{
if (cntrl_)
cntrl_->add_shared();
}
template<class T>
SharingPtr<T>::~SharingPtr()
{
if (cntrl_)
cntrl_->release_shared();
}
template<class T>
inline
SharingPtr<T>&
SharingPtr<T>::operator=(const SharingPtr& r)
{
SharingPtr(r).swap(*this);
return *this;
}
template<class T>
template<class Y>
inline
SharingPtr<T>&
SharingPtr<T>::operator=(const SharingPtr<Y>& r)
{
SharingPtr(r).swap(*this);
return *this;
}
template<class T>
inline
void
SharingPtr<T>::swap(SharingPtr& r)
{
std::swap(ptr_, r.ptr_);
std::swap(cntrl_, r.cntrl_);
}
template<class T>
inline
void
SharingPtr<T>::reset()
{
SharingPtr().swap(*this);
}
template<class T>
template<class Y>
inline
void
SharingPtr<T>::reset(Y* p)
{
SharingPtr(p).swap(*this);
}
template<class T, class U>
inline
bool
operator==(const SharingPtr<T>& __x, const SharingPtr<U>& __y)
{
return __x.get() == __y.get();
}
template<class T, class U>
inline
bool
operator!=(const SharingPtr<T>& __x, const SharingPtr<U>& __y)
{
return !(__x == __y);
}
template<class T, class U>
inline
bool
operator<(const SharingPtr<T>& __x, const SharingPtr<U>& __y)
{
return __x.get() < __y.get();
}
template<class T>
inline
void
swap(SharingPtr<T>& __x, SharingPtr<T>& __y)
{
__x.swap(__y);
}
template<class T, class U>
inline
SharingPtr<T>
static_pointer_cast(const SharingPtr<U>& r)
{
return SharingPtr<T>(r, static_cast<T*>(r.get()));
}
template<class T, class U>
SharingPtr<T>
const_pointer_cast(const SharingPtr<U>& r)
{
return SharingPtr<T>(r, const_cast<T*>(r.get()));
}
} // namespace lldb
#endif // utility_SharingPtr_h_