Vita3K/vita3k/modules/SceLibDbg/SceDbg.cpp
hobyst 168dfb19ca Add license notice on source files which didn't have one
- Also updated the copyright notice year on all files to 2021
2021-08-19 23:14:27 +02:00

96 lines
3 KiB
C++

// Vita3K emulator project
// Copyright (C) 2021 Vita3K team
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "SceDbg.h"
#include <util/lock_and_find.h>
#include <v3kprintf.h>
EXPORT(int, sceDbgAssertionHandler, const char *filename, int line, bool do_stop, const char *component, module::vargs messages) {
const ThreadStatePtr thread = lock_and_find(thread_id, host.kernel.threads, host.kernel.mutex);
if (!thread) {
return SCE_KERNEL_ERROR_UNKNOWN_THREAD_ID;
}
std::vector<char> buffer(KB(1));
const char *main_message = messages.next<Ptr<const char>>(*(thread->cpu), host.mem).get(host.mem);
const int result = utils::snprintf(buffer.data(), buffer.size(), main_message, *(thread->cpu), host.mem, messages);
LOG_INFO("file {}, line {}, {}", filename, line, buffer.data());
if (do_stop)
host.kernel.exit_delete_all_threads();
if (!result) {
return SCE_KERNEL_ERROR_INVALID_ARGUMENT;
}
assert(!do_stop);
return 0;
}
EXPORT(int, sceDbgLoggingHandler, const char *pFile, int line, int severity, const char *pComponent, module::vargs messages) {
const ThreadStatePtr thread = lock_and_find(thread_id, host.kernel.threads, host.kernel.mutex);
if (!thread) {
return SCE_KERNEL_ERROR_UNKNOWN_THREAD_ID;
}
std::string output = fmt::format("SCE libdbg LOG, LEVEL: {}", severity);
if (pComponent && (strlen(pComponent) > 0)) {
output += fmt::format(", COMPONENT: {}", pComponent);
}
if (pFile && (strlen(pFile) > 0)) {
output += fmt::format(", FILE:{}, LINE:{}", pFile, line);
}
std::vector<char> buffer(KB(1));
const char *main_message = messages.next<Ptr<const char>>(*(thread->cpu), host.mem).get(host.mem);
const int result = utils::snprintf(buffer.data(), buffer.size(), main_message, *(thread->cpu), host.mem, messages);
if (result) {
output += fmt::format(" {}", buffer.data());
}
LOG_INFO(output);
return 0;
}
EXPORT(int, sceDbgSetBreakOnErrorState) {
return UNIMPLEMENTED();
}
EXPORT(int, sceDbgSetBreakOnWarningState) {
return UNIMPLEMENTED();
}
EXPORT(int, sceDbgSetMinimumLogLevel) {
return UNIMPLEMENTED();
}
BRIDGE_IMPL(sceDbgAssertionHandler)
BRIDGE_IMPL(sceDbgLoggingHandler)
BRIDGE_IMPL(sceDbgSetBreakOnErrorState)
BRIDGE_IMPL(sceDbgSetBreakOnWarningState)
BRIDGE_IMPL(sceDbgSetMinimumLogLevel)