kernel/condition_variable: Make the debug type fetcher a static function.

No behavioral change intended.
This commit is contained in:
Augustin Cavalier 2024-11-05 13:46:53 -05:00
parent 7746364088
commit e9c9b2e448
3 changed files with 18 additions and 20 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright 2007-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2019, Haiku, Inc. All rights reserved.
* Copyright 2019-2024, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _KERNEL_CONDITION_VARIABLE_H
@ -75,8 +75,10 @@ public:
const void* Object() const { return fObject; }
const char* ObjectType() const { return fObjectType; }
// Debug methods.
static void ListAll();
void Dump() const;
static status_t DebugGetType(ConditionVariable* cvar, char* name, size_t size);
private:
static int32 _Notify(const void* object, bool all, status_t result);
@ -97,8 +99,6 @@ protected:
friend struct ConditionVariableEntry;
friend struct ConditionVariableHashDefinition;
friend ssize_t debug_condition_variable_type_strlcpy(ConditionVariable* cvar,
char* name, size_t size);
};

View File

@ -471,6 +471,20 @@ ConditionVariable::Dump() const
}
/*static*/ status_t
ConditionVariable::DebugGetType(ConditionVariable* cvar, char* name, size_t size)
{
// Use debug_memcpy to handle faults in case the structure is corrupt.
const char* pointer;
status_t status = debug_memcpy(B_CURRENT_TEAM, &pointer,
(int8*)cvar + offsetof(ConditionVariable, fObjectType), sizeof(const char*));
if (status != B_OK)
return status;
return debug_strlcpy(B_CURRENT_TEAM, name, pointer, size);
}
static int
list_condition_variables(int argc, char** argv)
{
@ -503,7 +517,6 @@ dump_condition_variable(int argc, char** argv)
set_debug_variable("_cvar", (addr_t)variable);
set_debug_variable("_object", (addr_t)variable->Object());
} else
kprintf("no condition variable at or with key %p\n", (void*)address);
@ -536,18 +549,3 @@ condition_variable_init()
"\n"
"Lists all published condition variables\n", 0);
}
ssize_t
debug_condition_variable_type_strlcpy(ConditionVariable* cvar, char* name, size_t size)
{
const int32 typePointerOffset = offsetof(ConditionVariable, fObjectType);
const char* pointer;
status_t status = debug_memcpy(B_CURRENT_TEAM, &pointer,
(int8*)cvar + typePointerOffset, sizeof(const char*));
if (status != B_OK)
return status;
return debug_strlcpy(B_CURRENT_TEAM, name, pointer, size);
}

View File

@ -1711,7 +1711,7 @@ _dump_thread_info(Thread *thread, bool shortInfo)
case THREAD_BLOCK_TYPE_CONDITION_VARIABLE:
{
char name[5];
ssize_t length = debug_condition_variable_type_strlcpy(
ssize_t length = ConditionVariable::DebugGetType(
(ConditionVariable*)thread->wait.object, name, sizeof(name));
if (length > 0)
kprintf("cvar:%*s %p ", 4, name, thread->wait.object);