ams: support building unit test programs on windows/linux/macos

This commit is contained in:
Michael Scire 2022-03-06 12:08:20 -08:00 committed by SciresM
parent 9a38be201a
commit 64a97576d0
756 changed files with 33359 additions and 9372 deletions

View file

@ -18,45 +18,51 @@
#if defined(ATMOSPHERE_OS_HORIZON)
#include "impl/osdbg_thread_info.os.horizon.hpp"
#else
#error "Unknown OS for ams::osdbg::ThreadInfo"
#include "impl/osdbg_thread_info.generic.hpp"
#endif
namespace ams::osdbg {
Result InitializeThreadInfo(ThreadInfo *thread_info, os::NativeHandle debug_handle, const svc::DebugInfoCreateProcess *create_process, const svc::DebugInfoCreateThread *create_thread) {
Result InitializeThreadInfo(ThreadInfo *thread_info, os::NativeHandle debug_handle, const osdbg::DebugInfoCreateProcess *create_process, const osdbg::DebugInfoCreateThread *create_thread) {
/* Set basic fields. */
thread_info->_thread_type = nullptr;
thread_info->_thread_type_type = ThreadTypeType_Unknown;
thread_info->_debug_handle = debug_handle;
#if defined(ATMOSPHERE_OS_HORIZON)
thread_info->_debug_info_create_process = *create_process;
thread_info->_debug_info_create_thread = *create_thread;
#else
AMS_UNUSED(create_process, create_thread);
#endif
/* Update the current info. */
return impl::ThreadInfoImpl::FillWithCurrentInfo(thread_info);
R_RETURN(impl::ThreadInfoImpl::FillWithCurrentInfo(thread_info));
}
Result UpdateThreadInfo(ThreadInfo *thread_info) {
/* Update the current info. */
return impl::ThreadInfoImpl::FillWithCurrentInfo(thread_info);
R_RETURN(impl::ThreadInfoImpl::FillWithCurrentInfo(thread_info));
}
Result GetThreadName(char *dst, const ThreadInfo *thread_info) {
/* Get the name pointer. */
const auto name_pointer = GetThreadNamePointer(thread_info);
#if defined(ATMOSPHERE_OS_HORIZON)
/* Read the name. */
if (name_pointer != 0) {
return svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(dst), thread_info->_debug_handle, name_pointer, os::ThreadNameLengthMax);
if (const auto name_pointer = GetThreadNamePointer(thread_info); name_pointer != 0) {
R_RETURN(svc::ReadDebugProcessMemory(reinterpret_cast<uintptr_t>(dst), thread_info->_debug_handle, name_pointer, os::ThreadNameLengthMax));
} else {
/* Special-case libnx threads. */
if (thread_info->_thread_type_type == ThreadTypeType_Libnx) {
util::TSNPrintf(dst, os::ThreadNameLengthMax, "libnx Thread_0x%010lx", reinterpret_cast<uintptr_t>(thread_info->_thread_type));
util::TSNPrintf(dst, os::ThreadNameLengthMax, "libnx Thread_0x%010" PRIx64 "", reinterpret_cast<uintptr_t>(thread_info->_thread_type));
} else {
util::TSNPrintf(dst, os::ThreadNameLengthMax, "Thread_0x%010lx", reinterpret_cast<uintptr_t>(thread_info->_thread_type));
util::TSNPrintf(dst, os::ThreadNameLengthMax, "Thread_0x%010" PRIx64 "", reinterpret_cast<uintptr_t>(thread_info->_thread_type));
}
return ResultSuccess();
R_SUCCEED();
}
#else
util::TSNPrintf(dst, os::ThreadNameLengthMax, "Thread_0x%010" PRIx64 "", static_cast<u64>(reinterpret_cast<uintptr_t>(thread_info->_thread_type)));
R_SUCCEED();
#endif
}
}