2015-09-02 08:56:38 -04:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
// Originally written by Sven Peter <sven@fail0verflow.com> for anergistic.
|
|
|
|
|
|
|
|
#pragma once
|
2016-12-15 16:19:30 -05:00
|
|
|
|
2018-07-12 23:22:59 -04:00
|
|
|
#include <string>
|
2016-03-20 08:55:08 -04:00
|
|
|
#include "common/common_types.h"
|
2018-06-06 00:20:47 -04:00
|
|
|
#include "core/hle/kernel/thread.h"
|
2016-03-20 08:55:08 -04:00
|
|
|
|
2015-09-02 08:56:38 -04:00
|
|
|
namespace GDBStub {
|
|
|
|
|
|
|
|
/// Breakpoint Method
|
|
|
|
enum class BreakpointType {
|
2016-09-17 20:38:01 -04:00
|
|
|
None, ///< None
|
|
|
|
Execute, ///< Execution Breakpoint
|
|
|
|
Read, ///< Read Breakpoint
|
|
|
|
Write, ///< Write Breakpoint
|
|
|
|
Access ///< Access (R/W) Breakpoint
|
2015-09-02 08:56:38 -04:00
|
|
|
};
|
|
|
|
|
2015-10-04 11:22:31 -04:00
|
|
|
struct BreakpointAddress {
|
2018-08-05 15:55:57 -04:00
|
|
|
VAddr address;
|
2015-10-04 11:22:31 -04:00
|
|
|
BreakpointType type;
|
|
|
|
};
|
|
|
|
|
2015-09-02 08:56:38 -04:00
|
|
|
/**
|
|
|
|
* Set the port the gdbstub should use to listen for connections.
|
|
|
|
*
|
|
|
|
* @param port Port to listen for connection
|
|
|
|
*/
|
|
|
|
void SetServerPort(u16 port);
|
|
|
|
|
|
|
|
/**
|
2016-12-15 16:19:30 -05:00
|
|
|
* Starts or stops the server if possible.
|
2015-09-02 08:56:38 -04:00
|
|
|
*
|
|
|
|
* @param status Set the server to enabled or disabled.
|
|
|
|
*/
|
|
|
|
void ToggleServer(bool status);
|
|
|
|
|
|
|
|
/// Start the gdbstub server.
|
|
|
|
void Init();
|
|
|
|
|
2020-02-23 15:33:49 -05:00
|
|
|
/**
|
|
|
|
* Defer initialization of the gdbstub to the first packet processing functions.
|
|
|
|
* This avoids a case where the gdbstub thread is frozen after initialization
|
|
|
|
* and fails to respond in time to packets.
|
|
|
|
*/
|
|
|
|
void DeferStart();
|
|
|
|
|
2015-09-02 08:56:38 -04:00
|
|
|
/// Stop gdbstub server.
|
2015-10-11 20:07:58 -04:00
|
|
|
void Shutdown();
|
2015-09-02 08:56:38 -04:00
|
|
|
|
2016-12-15 16:19:30 -05:00
|
|
|
/// Checks if the gdbstub server is enabled.
|
|
|
|
bool IsServerEnabled();
|
|
|
|
|
2015-09-02 08:56:38 -04:00
|
|
|
/// Returns true if there is an active socket connection.
|
|
|
|
bool IsConnected();
|
|
|
|
|
2018-07-12 23:22:59 -04:00
|
|
|
/// Register module.
|
2018-08-05 15:55:57 -04:00
|
|
|
void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext = true);
|
2018-07-12 23:22:59 -04:00
|
|
|
|
2015-09-02 08:56:38 -04:00
|
|
|
/**
|
|
|
|
* Signal to the gdbstub server that it should halt CPU execution.
|
|
|
|
*
|
|
|
|
* @param is_memory_break If true, the break resulted from a memory breakpoint.
|
|
|
|
*/
|
|
|
|
void Break(bool is_memory_break = false);
|
|
|
|
|
|
|
|
/// Determine if there was a memory breakpoint.
|
|
|
|
bool IsMemoryBreak();
|
|
|
|
|
|
|
|
/// Read and handle packet from gdb client.
|
|
|
|
void HandlePacket();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the nearest breakpoint of the specified type at the given address.
|
|
|
|
*
|
|
|
|
* @param addr Address to search from.
|
|
|
|
* @param type Type of breakpoint.
|
|
|
|
*/
|
2018-08-05 15:55:57 -04:00
|
|
|
BreakpointAddress GetNextBreakpointFromAddress(VAddr addr, GDBStub::BreakpointType type);
|
2015-09-02 08:56:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a breakpoint of the specified type exists at the given address.
|
|
|
|
*
|
|
|
|
* @param addr Address of breakpoint.
|
|
|
|
* @param type Type of breakpoint.
|
|
|
|
*/
|
2018-08-05 15:55:57 -04:00
|
|
|
bool CheckBreakpoint(VAddr addr, GDBStub::BreakpointType type);
|
2015-09-02 08:56:38 -04:00
|
|
|
|
2018-07-12 23:22:59 -04:00
|
|
|
/// If set to true, the CPU will halt at the beginning of the next CPU loop.
|
2015-09-02 08:56:38 -04:00
|
|
|
bool GetCpuHaltFlag();
|
|
|
|
|
2018-07-12 23:22:59 -04:00
|
|
|
/// If set to true and the CPU is halted, the CPU will step one instruction.
|
2015-09-02 08:56:38 -04:00
|
|
|
bool GetCpuStepFlag();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When set to true, the CPU will step one instruction when the CPU is halted next.
|
|
|
|
*
|
|
|
|
* @param is_step
|
|
|
|
*/
|
|
|
|
void SetCpuStepFlag(bool is_step);
|
2018-06-06 00:20:47 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send trap signal from thread back to the gdbstub server.
|
|
|
|
*
|
|
|
|
* @param thread Sending thread.
|
|
|
|
* @param trap Trap no.
|
|
|
|
*/
|
|
|
|
void SendTrap(Kernel::Thread* thread, int trap);
|
2018-01-20 02:48:02 -05:00
|
|
|
} // namespace GDBStub
|