#include "magenta/debug/util.h" #include #include #include enum mxdbg_status mxdbg_host_handle_request(struct mxdbg_host *host) { struct mxdbg_packet packet = {0}; enum mxdbg_status status = mxdbg_host_recv(host, &packet); if (status != MXDBG_SUCCESS) { debug_printf("debug: failed to read packet"); return status; } if (packet.pkt_magic != MXDBG_PACKET_MAGIC) { debug_printf( "debug: packet is malformed (magic=%08x)", packet.pkt_magic); return MXDBG_ERR_BAD_FORMAT; } return mxdbg_handle_request(host, &packet); } enum mxdbg_status mxdbg_host_recv( struct mxdbg_host *host, struct mxdbg_packet *packet) { size_t r; if (host->read_remote) { return host->read_remote(host, packet, sizeof *packet, &r); } return MXDBG_ERR_NOT_SUPPORTED; } enum mxdbg_status mxdbg_host_recv_packet_data( struct mxdbg_host *host, struct mxdbg_packet *packet) { if (packet->pkt_magic != MXDBG_PACKET_MAGIC) { return MXDBG_ERR_INVALID_ARGUMENT; } if (!packet->pkt_length) { return MXDBG_SUCCESS; } size_t r; void *dest = packet + 1; if (host->read_remote) { return host->read_remote( host, dest, packet->pkt_length - sizeof *packet, &r); } return MXDBG_ERR_NOT_SUPPORTED; } enum mxdbg_status mxdbg_host_send( struct mxdbg_host *host, const struct mxdbg_packet *packet) { size_t w; if (host->write_remote) { return host->write_remote(host, packet, packet->pkt_length, &w); } return MXDBG_ERR_NOT_SUPPORTED; } enum mxdbg_status mxdbg_host_identify( struct mxdbg_host *host, enum mxdbg_identity_key key, void *out, size_t max) { if (host->identify) { return host->identify(host, key, out, max); } return MXDBG_ERR_NOT_SUPPORTED; } enum mxdbg_status mxdbg_host_identify_task( struct mxdbg_host *host, unsigned int tid, enum mxdbg_identity_key key, void *out, size_t max) { if (host->identify_task) { return host->identify_task(host, tid, key, out, max); } return MXDBG_ERR_NOT_SUPPORTED; } enum mxdbg_status mxdbg_host_resume(struct mxdbg_host *host) { if (host->resume) { return host->resume(host); } return MXDBG_ERR_NOT_SUPPORTED; }