/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2004 Marcel Moolenaar4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR17* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES18* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.19* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,20* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT21* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF25* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/2728#ifndef _GDB_GDB_INT_H_29#define _GDB_GDB_INT_H_3031#include "opt_ddb.h"3233#include <sys/sysctl.h>3435#ifdef DDB36#include <ddb/ddb.h>37#endif3839#ifndef EOF40#define EOF (-1)41#endif4243SYSCTL_DECL(_debug_gdb);4445extern struct gdb_dbgport *gdb_cur;4647extern int gdb_listening;48void gdb_consinit(void);4950extern char *gdb_rxp;51extern size_t gdb_rxsz;52extern char *gdb_txp;5354extern bool gdb_ackmode;5556#ifdef DDB57/* If set, return to DDB when controlling GDB detaches. */58extern bool gdb_return_to_ddb;59#endif6061int gdb_rx_begin(void);62int gdb_rx_equal(const char *);63int gdb_rx_mem(unsigned char *, size_t);64int gdb_rx_varhex(uintmax_t *);6566static __inline int67gdb_rx_char(void)68{69int c;7071if (gdb_rxsz > 0) {72c = *gdb_rxp++;73gdb_rxsz--;74} else75c = EOF;76return (c);77}7879void gdb_tx_begin(char);80int gdb_tx_end(void);81int gdb_tx_mem(const unsigned char *, size_t);82void gdb_tx_reg(int);83bool gdb_txbuf_has_capacity(size_t);84int gdb_rx_bindata(unsigned char *data, size_t datalen, size_t *amt);85int gdb_search_mem(const unsigned char *addr, size_t size,86const unsigned char *pat, size_t patlen, const unsigned char **found);8788static __inline void89gdb_tx_char(char c)90{91*gdb_txp++ = c;92}9394static __inline int95gdb_tx_empty(void)96{97gdb_tx_begin('\0');98return (gdb_tx_end());99}100101static __inline void102gdb_tx_hex(uintmax_t n, int sz)103{104gdb_txp += sprintf(gdb_txp, "%0*jx", sz, n);105}106107static __inline int108gdb_tx_err(int err)109{110gdb_tx_begin('E');111gdb_tx_hex(err, 2);112return (gdb_tx_end());113}114115static __inline int116gdb_tx_ok(void)117{118gdb_tx_begin('O');119gdb_tx_char('K');120return (gdb_tx_end());121}122123static __inline void124gdb_tx_str(const char *s)125{126while (*s)127*gdb_txp++ = *s++;128}129130static __inline void131gdb_tx_varhex(uintmax_t n)132{133gdb_txp += sprintf(gdb_txp, "%jx", n);134}135136static __inline void137gdb_nack(void)138{139if (gdb_ackmode)140gdb_cur->gdb_putc('-');141}142143static __inline void144gdb_ack(void)145{146if (gdb_ackmode)147gdb_cur->gdb_putc('+');148}149150#endif /* !_GDB_GDB_INT_H_ */151152153