2021-07-17 14:27:40 +01:00
|
|
|
/*
|
2021-10-04 20:59:10 +01:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-07-17 14:27:40 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stratosphere.hpp>
|
|
|
|
#include "dmnt2_gdb_packet_io.hpp"
|
2021-07-20 09:29:00 +01:00
|
|
|
#include "dmnt2_gdb_signal.hpp"
|
|
|
|
#include "dmnt2_debug_process.hpp"
|
2021-07-17 14:27:40 +01:00
|
|
|
|
|
|
|
namespace ams::dmnt {
|
|
|
|
|
|
|
|
class GdbServerImpl {
|
2021-07-19 07:22:44 +01:00
|
|
|
private:
|
|
|
|
enum class State {
|
|
|
|
Initial,
|
|
|
|
Running,
|
|
|
|
Exited,
|
|
|
|
Destroyed,
|
|
|
|
};
|
2021-07-17 14:27:40 +01:00
|
|
|
private:
|
|
|
|
int m_socket;
|
|
|
|
HtcsSession m_session;
|
|
|
|
GdbPacketIo m_packet_io;
|
|
|
|
char *m_receive_packet{nullptr};
|
|
|
|
char *m_reply_packet{nullptr};
|
|
|
|
char m_buffer[GdbPacketBufferSize / 2];
|
2021-07-19 07:22:44 +01:00
|
|
|
bool m_killed{false};
|
|
|
|
os::ThreadType m_events_thread;
|
|
|
|
State m_state;
|
2021-07-20 09:29:00 +01:00
|
|
|
DebugProcess m_debug_process;
|
2021-07-19 07:22:44 +01:00
|
|
|
os::ProcessId m_process_id{os::InvalidProcessId};
|
|
|
|
os::Event m_event;
|
2021-07-17 14:27:40 +01:00
|
|
|
public:
|
2021-07-19 07:22:44 +01:00
|
|
|
GdbServerImpl(int socket, void *thread_stack, size_t stack_size);
|
2021-07-17 14:27:40 +01:00
|
|
|
~GdbServerImpl();
|
|
|
|
|
|
|
|
void LoopProcess();
|
|
|
|
private:
|
|
|
|
void ProcessPacket(char *receive, char *reply);
|
|
|
|
|
|
|
|
void SendPacket(bool *out_break, const char *src) { return m_packet_io.SendPacket(out_break, src, std::addressof(m_session)); }
|
|
|
|
char *ReceivePacket(bool *out_break, char *dst, size_t size) { return m_packet_io.ReceivePacket(out_break, dst, size, std::addressof(m_session)); }
|
|
|
|
private:
|
2021-07-20 09:29:00 +01:00
|
|
|
bool HasDebugProcess() const { return m_debug_process.IsValid(); }
|
|
|
|
bool Is64Bit() const { return m_debug_process.Is64Bit(); }
|
|
|
|
bool Is64BitAddressSpace() const { return m_debug_process.Is64BitAddressSpace(); }
|
2021-07-19 07:22:44 +01:00
|
|
|
private:
|
|
|
|
static void DebugEventsThreadEntry(void *arg) { static_cast<GdbServerImpl *>(arg)->DebugEventsThread(); }
|
|
|
|
void DebugEventsThread();
|
|
|
|
void ProcessDebugEvents();
|
|
|
|
void SetStopReplyPacket(GdbSignal signal);
|
2021-07-17 14:27:40 +01:00
|
|
|
private:
|
2021-07-23 13:29:39 +01:00
|
|
|
void D();
|
|
|
|
|
|
|
|
void G();
|
|
|
|
|
2021-07-17 14:27:40 +01:00
|
|
|
void H();
|
2021-07-19 07:22:44 +01:00
|
|
|
void Hg();
|
|
|
|
|
2021-07-23 13:29:39 +01:00
|
|
|
void M();
|
|
|
|
|
|
|
|
void P();
|
|
|
|
|
|
|
|
void Q();
|
|
|
|
|
2021-07-22 08:51:28 +01:00
|
|
|
void T();
|
|
|
|
|
|
|
|
void Z();
|
|
|
|
|
2021-07-23 13:29:39 +01:00
|
|
|
void c();
|
|
|
|
|
2021-07-19 07:22:44 +01:00
|
|
|
bool g();
|
|
|
|
|
2021-07-23 13:29:39 +01:00
|
|
|
void k();
|
|
|
|
|
2021-07-19 07:22:44 +01:00
|
|
|
void m();
|
|
|
|
|
2021-07-23 13:29:39 +01:00
|
|
|
void p();
|
|
|
|
|
2021-07-19 07:22:44 +01:00
|
|
|
void v();
|
|
|
|
|
|
|
|
void vAttach();
|
2021-07-22 08:51:28 +01:00
|
|
|
void vCont();
|
2021-07-19 07:22:44 +01:00
|
|
|
|
2021-07-17 14:27:40 +01:00
|
|
|
void q();
|
|
|
|
|
|
|
|
void qAttached();
|
|
|
|
void qC();
|
|
|
|
void qSupported();
|
|
|
|
void qXfer();
|
|
|
|
void qXferFeaturesRead();
|
2021-07-20 09:29:00 +01:00
|
|
|
void qXferLibrariesRead();
|
2021-07-17 14:27:40 +01:00
|
|
|
void qXferOsdataRead();
|
2021-07-19 07:22:44 +01:00
|
|
|
bool qXferThreadsRead();
|
2021-07-17 14:27:40 +01:00
|
|
|
|
2021-07-22 08:51:28 +01:00
|
|
|
void z();
|
|
|
|
|
2021-07-17 14:27:40 +01:00
|
|
|
void QuestionMark();
|
2021-07-22 08:51:28 +01:00
|
|
|
private:
|
|
|
|
Result ParseVCont(char * const token, u64 *thread_ids, u8 *continue_modes, s32 num_threads, DebugProcess::ContinueMode &default_continue_mode);
|
2021-07-17 14:27:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|