Esempio n. 1
0
static int write_text(struct outbuf *out, const char *buf, FILE *fout)
{
	int want_color = opdb_get_boolean("color");
	int len = 0;

	while (*buf) {
		if (*buf == 27)
			out->in_code = 1;

		if (!out->in_code)
			len++;

		if (*buf == '\n') {
			out->buf[out->len] = 0;
			fprintf(fout, "%s\n", out->buf);
			if (capture_func)
				capture_func(capture_data, out->buf);
			out->len = 0;
		} else if ((want_color || !out->in_code) &&
			   out->len + 1 < sizeof(out->buf)) {
			out->buf[out->len++] = *buf;
		}

		if (isalpha(*buf))
			out->in_code = 0;

		buf++;
	}

	return len;
}
Esempio n. 2
0
int printc_dbg(const char *fmt, ...)
{
	char buf[4096];
	va_list ap;

	if (opdb_get_boolean("quiet"))
		return 0;

	va_start(ap, fmt);
	vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);

	return write_text(&stdout_buf, buf, stdout);
}
Esempio n. 3
0
void reader_loop(void)
{
	int old = in_reader_loop;

	in_reader_loop = 1;

	if (!opdb_get_boolean("quiet")) {
		printc("\n");
		cmd_help(NULL);
		printc("\n");
	}

	do {
		want_exit = 0;

		for (;;) {
			char *buf = readline("(mspdebug) ");
			char tmpbuf[MAX_READER_LINE];

			if (!buf) {
				printc("\n");
				break;
			}

			/* Copy into our local buffer and free */
			strncpy(tmpbuf, buf, sizeof(tmpbuf));
			tmpbuf[sizeof(tmpbuf) - 1] = 0;
			free(buf);
			buf = tmpbuf;

			if (*buf) {
				add_history(buf);
				repeat_buf[0] = 0;
			} else {
				memcpy(tmpbuf, repeat_buf, sizeof(tmpbuf));
			}

			do_command(buf, 1);

			if (want_exit)
				break;
		}
	} while (prompt_abort(MODIFY_SYMS));

	in_reader_loop = old;
}
Esempio n. 4
0
int cmd_gdb(char **arg)
{
	char *port_text = get_arg(arg);
	address_t port = 2000;

	if (port_text && expr_eval(port_text, &port) < 0) {
		printc_err("gdb: can't parse port: %s\n", port_text);
		return -1;
	}

	if (port <= 0 || port > 65535) {
		printc_err("gdb: invalid port: %d\n", port);
		return -1;
	}

	do {
		if (gdb_server(port) < 0)
			return -1;
	} while (opdb_get_boolean("gdb_loop"));

	return 0;
}