Converted several assertions into error messages.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7461
This commit is contained in:
Bart Van Assche
2008-02-25 19:46:14 +00:00
parent 7942f5b386
commit 4c1cf5e2b2

View File

@@ -110,6 +110,16 @@ mutex_get_or_allocate(const Addr mutex,
{
if (s_mutex[i].mutex == 0)
{
if (drd_is_any_suppressed(mutex, mutex + size))
{
MutexErrInfo MEI = { 0, 0, 0 };
VG_(maybe_record_error)(VG_(get_running_tid)(),
MutexErr,
VG_(get_IP)(VG_(get_running_tid)()),
"Not a mutex",
&MEI);
return 0;
}
mutex_initialize(&s_mutex[i], mutex, size, mutex_type);
drd_start_suppression(mutex, mutex + size,
mutex_get_typename(&s_mutex[i]));
@@ -220,7 +230,6 @@ int mutex_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
{
const DrdThreadId drd_tid = VgThreadIdToDrdThreadId(VG_(get_running_tid)());
struct mutex_info* const p = mutex_get_or_allocate(mutex, size, mutex_type);
const DrdThreadId last_owner = p->owner;
if (s_trace_mutex)
{
@@ -235,6 +244,17 @@ int mutex_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
p ? p->owner : VG_INVALID_THREADID);
}
if (p == 0)
{
MutexErrInfo MEI = { 0, 0, 0 };
VG_(maybe_record_error)(VG_(get_running_tid)(),
MutexErr,
VG_(get_IP)(VG_(get_running_tid)()),
"Not a mutex",
&MEI);
return 0;
}
tl_assert(mutex_type == mutex_type_mutex
|| mutex_type == mutex_type_spinlock);
tl_assert(p->mutex_type == mutex_type);
@@ -265,6 +285,8 @@ int mutex_lock(const Addr mutex, const SizeT size, MutexT mutex_type)
if (p->recursion_count == 1)
{
const DrdThreadId last_owner = p->owner;
if (last_owner != drd_tid && last_owner != DRD_INVALID_THREADID)
thread_combine_vc2(drd_tid, mutex_get_last_vc(mutex));
thread_new_segment(drd_tid);
@@ -299,6 +321,17 @@ int mutex_unlock(const Addr mutex, const MutexT mutex_type)
p->owner);
}
if (p == 0 || p->owner == DRD_INVALID_THREADID)
{
MutexErrInfo MEI = { 0, 0, 0 };
VG_(maybe_record_error)(vg_tid,
MutexErr,
VG_(get_IP)(vg_tid),
"Not a mutex",
&MEI);
return 0;
}
tl_assert(p);
tl_assert(p->mutex_type == mutex_type);
tl_assert(p->owner != DRD_INVALID_THREADID);
@@ -363,7 +396,6 @@ const char* mutex_type_name(const MutexT mt)
Bool mutex_is_locked_by(const Addr mutex, const DrdThreadId tid)
{
struct mutex_info* const p = mutex_get(mutex);
tl_assert(p);
if (p)
{
return (p->recursion_count > 0 && p->owner == tid);