5
0
mirror of git://git.proxmox.com/git/spiceterm.git synced 2025-03-11 16:58:29 +03:00

cleanup debugging code

This commit is contained in:
Dietmar Maurer 2013-09-11 12:56:28 +02:00
parent 4ef70811b8
commit a0579497f2
4 changed files with 72 additions and 83 deletions

View File

@ -33,7 +33,7 @@
#include <spice/macros.h>
#include "event_loop.h"
int debug = 1;
static int debug = 0;
#define DPRINTF(x, format, ...) { \
if (x <= debug) { \
@ -158,7 +158,7 @@ static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *
{
SpiceWatch *watch = g_new0(SpiceWatch, 1);
DPRINTF(0, "adding %p, fd=%d", watch, fd);
DPRINTF(1, "adding %p, fd=%d", watch, fd);
watch->fd = fd;
watch->event_mask = event_mask;
@ -179,7 +179,7 @@ static void watch_update_mask(SpiceWatch *watch, int event_mask)
{
g_assert(watch != NULL);
DPRINTF(0, "fd %d to %d", watch->fd, event_mask);
DPRINTF(1, "fd %d to %d", watch->fd, event_mask);
watch->event_mask = event_mask;
@ -193,7 +193,7 @@ static void watch_remove(SpiceWatch *watch)
{
g_assert(watch != NULL);
DPRINTF(0, "remove %p (fd %d)", watch, watch->fd);
DPRINTF(1, "remove %p (fd %d)", watch, watch->fd);
g_source_remove(watch->evid);
g_io_channel_unref(watch->channel);
@ -203,7 +203,7 @@ static void watch_remove(SpiceWatch *watch)
static void channel_event(int event, SpiceChannelEventInfo *info)
{
DPRINTF(0, "channel event con, type, id, event: %d, %d, %d, %d",
DPRINTF(1, "channel event con, type, id, event: %d, %d, %d, %d",
info->connection_id, info->type, info->id, event);
}

View File

@ -1,9 +1,4 @@
#ifndef __BASIC_EVENT_LOOP_H__
#define __BASIC_EVENT_LOOP_H__
#include <spice.h>
SpiceCoreInterface *basic_event_loop_init(void);
void basic_event_loop_mainloop(void);
#endif // __BASIC_EVENT_LOOP_H__

View File

@ -44,6 +44,14 @@
#include "spiceterm.h"
static int debug = 0;
#define DPRINTF(x, format, ...) { \
if (x <= debug) { \
printf("%s: " format "\n" , __FUNCTION__, ## __VA_ARGS__); \
} \
}
#define MEM_SLOT_GROUP_ID 0
#define NOTIFY_DISPLAY_BATCH (SINGLE_PART/2)
@ -550,7 +558,7 @@ set_client_capabilities(QXLInstance *qin, uint8_t client_present,
{
SpiceScreen *spice_screen = SPICE_CONTAINEROF(qin, SpiceScreen, qxl_instance);
printf("%s: present %d caps %d\n", __func__, client_present, caps[0]);
DPRINTF(1, "%s: present %d caps %d", __func__, client_present, caps[0]);
if (spice_screen->on_client_connected && client_present) {
spice_screen->on_client_connected(spice_screen);
@ -565,17 +573,17 @@ static int client_count = 0;
static void
client_connected(SpiceScreen *spice_screen)
{
printf("Client connected\n");
client_count++;
DPRINTF(1, "%s: client_count = %d", __func__, client_count);
}
static void
client_disconnected(SpiceScreen *spice_screen)
{
if (client_count > 0) {
client_count--;
printf("Client disconnected\n");
DPRINTF(1, "%s: client_count = %d", __func__, client_count);
exit(0); // fixme: cleanup?
}
}
@ -586,7 +594,7 @@ do_conn_timeout(void *opaque)
// SpiceScreen *spice_screen = opaque;
if (client_count <= 0) {
printf("connection timeout\n");
printf("connection timeout - stopping server\n");
exit (0); // fixme: cleanup?
}
}

View File

@ -55,16 +55,21 @@
#include "event_loop.h"
#include "translations.h"
/* define this for debugging */
//#define DEBUG
static int debug = 0;
#define DPRINTF(x, format, ...) { \
if (x <= debug) { \
printf("%s: " format "\n" , __FUNCTION__, ## __VA_ARGS__); \
} \
}
#define TERM "xterm"
#define TERMIDCODE "[?1;2c" // vt100 ID
#define CHECK_ARGC(argc,argv,i) if (i >= argc-1) { \
fprintf (stderr, "ERROR: not enough arguments for: %s\n", argv[i]); \
print_usage (NULL); \
fprintf(stderr, "ERROR: not enough arguments for: %s\n", argv[i]); \
print_usage(NULL); \
exit(1); \
}
@ -77,8 +82,8 @@ unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
static void
print_usage (const char *msg)
{
if (msg) { fprintf (stderr, "ERROR: %s\n", msg); }
fprintf (stderr, "USAGE: spiceterm [spiceopts] [-c command [args]]\n");
if (msg) { fprintf(stderr, "ERROR: %s\n", msg); }
fprintf(stderr, "USAGE: spiceterm [spiceopts] [-c command [args]]\n");
}
/* Convert UCS2 to UTF8 sequence, trailing zero */
@ -470,7 +475,7 @@ spiceterm_csi_m (spiceTerm *vt)
vt->cur_attrib.bgcol = vt->default_attrib.bgcol;
break;
default:
fprintf (stderr, "unhandled ESC[%d m code\n",vt->esc_buf[i]);
fprintf(stderr, "unhandled ESC[%d m code\n",vt->esc_buf[i]);
//fixme: implement
}
}
@ -616,10 +621,10 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
{
int x, y, i, c;
#ifdef DEBUG
if (!vt->tty_state)
fprintf (stderr, "CHAR:%2d: %4x '%c' (cur_enc %d) %d %d\n", vt->tty_state, ch, ch, vt->cur_enc, vt->cx, vt->cy);
#endif
if (!vt->tty_state) {
DPRINTF(1, "%s: CHAR:%2d: %4x '%c' (cur_enc %d) %d %d", __func__,
vt->tty_state, ch, ch, vt->cur_enc, vt->cx, vt->cy);
}
switch(vt->tty_state) {
case ESesc:
@ -661,9 +666,7 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
/* appl. keypad - ignored */
break;
default:
#ifdef DEBUG
fprintf(stderr, "got unhandled ESC%c %d\n", ch, ch);
#endif
DPRINTF(1, "%s: got unhandled ESC%c %d", __func__, ch, ch);
break;
}
break;
@ -691,9 +694,7 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
vt->tty_state = ESosc1;
break;
default:
#ifdef DEBUG
fprintf (stderr, "unhandled OSC %c\n", ch);
#endif
DPRINTF(1, "%s: got unhandled OSC %c", __func__, ch);
vt->tty_state = ESnormal;
break;
}
@ -703,9 +704,7 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
if (ch == ';') {
vt->tty_state = ESosc2;
} else {
#ifdef DEBUG
fprintf (stderr, "got illegal OSC sequence\n");
#endif
DPRINTF(1, "%s: got illegal OSC sequence", __func__);
}
break;
case ESosc2:
@ -715,9 +714,7 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
vt->osc_textbuf[i++] = ch;
vt->osc_textbuf[i] = 0;
} else {
#ifdef DEBUG
fprintf (stderr, "OSC:%c:%s\n", vt->osc_cmd, vt->osc_textbuf);
#endif
DPRINTF(1, "%s: OSC:%c:%s", __func__, vt->osc_cmd, vt->osc_textbuf);
vt->tty_state = ESnormal;
}
break;
@ -782,21 +779,22 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
vt->tty_state = ESnormal;
#ifdef DEBUG
char *qes = vt->esc_ques ? "?" : "";
if (vt->esc_count == 0) {
fprintf(stderr, "ESC[%s%c\n", qes, ch);
} else if (vt->esc_count == 1) {
fprintf(stderr, "ESC[%s%d%c\n", qes, vt->esc_buf[0], ch);
} else {
int i;
fprintf(stderr, "ESC[%s%d", qes, vt->esc_buf[0]);
for (i = 1; i < vt->esc_count; i++) {
fprintf(stderr, ";%d", vt->esc_buf[i]);
}
fprintf (stderr, "%c\n", ch);
if (debug) {
if (vt->esc_count == 0) {
DPRINTF(1, "%s: ESC[%s%c", __func__, qes, ch);
} else if (vt->esc_count == 1) {
DPRINTF(1, "%s: ESC[%s%d%c\n", __func__, qes, vt->esc_buf[0], ch);
} else {
int i;
printf("ESC[%s%d", qes, vt->esc_buf[0]);
for (i = 1; i < vt->esc_count; i++) {
printf(";%d", vt->esc_buf[i]);
}
printf("%c\n", ch);
}
}
#endif
switch (ch) {
case 'h':
@ -1033,27 +1031,25 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
vt->region_bottom = vt->esc_buf[1];
vt->cx = 0;
vt->cy = vt->region_top;
#ifdef DEBUG
fprintf (stderr, "set region %d %d\n", vt->region_top, vt->region_bottom);
#endif
DPRINTF(1, "%s: set region %d %d", __func__, vt->region_top, vt->region_bottom);
}
break;
default:
#ifdef DEBUG
if (vt->esc_count == 0) {
fprintf(stderr, "unhandled escape ESC[%s%c\n", qes, ch);
} else if (vt->esc_count == 1) {
fprintf(stderr, "unhandled escape ESC[%s%d%c\n", qes, vt->esc_buf[0], ch);
} else {
int i;
fprintf(stderr, "unhandled escape ESC[%s%d", qes, vt->esc_buf[0]);
for (i = 1; i < vt->esc_count; i++) {
fprintf(stderr, ";%d", vt->esc_buf[i]);
}
fprintf (stderr, "%c\n", ch);
if (debug) {
if (vt->esc_count == 0) {
DPRINTF(1, "%s: unhandled escape ESC[%s%c", __func__, qes, ch);
} else if (vt->esc_count == 1) {
DPRINTF(1, "%s: unhandled escape ESC[%s%d%c\n", __func__, qes, vt->esc_buf[0], ch);
} else {
int i;
printf("unhandled escape ESC[%s%d", qes, vt->esc_buf[0]);
for (i = 1; i < vt->esc_count; i++) {
printf(";%d", vt->esc_buf[i]);
}
printf("%c\n", ch);
}
}
#endif
break;
}
vt->esc_ques = 0;
@ -1094,9 +1090,7 @@ spiceterm_putchar (spiceTerm *vt, unicode ch)
vt->tty_state = ESnormal;
if (ch == 'c') {
#ifdef DEBUG
fprintf (stderr, "ESC[>c Query term ID\n");
#endif
DPRINTF(1, "%s: ESC[>c Query term ID", __func__);
spiceterm_respond_esc (vt, TERMIDCODE);
}
break;
@ -1459,7 +1453,8 @@ static void my_kbd_push_keyval(SpiceKbdInstance *sin, uint32_t keySym, int flags
guint uc = 0;
fprintf (stderr, "KEYEVENT:%d: %08x\n", flags, keySym);fflush (stderr);
DPRINTF(1, "%s: flags=%d keySym=%08x", __func__, flags, keySym);
if (flags & 1) {
if (keySym == GDK_KEY_Shift_L || keySym == GDK_KEY_Shift_R) {
shift = 1;
@ -1475,9 +1470,6 @@ static void my_kbd_push_keyval(SpiceKbdInstance *sin, uint32_t keySym, int flags
else
uc = 0;
//printf("CONTROL: %08x %d\n", keySym, uc);
} else {
switch (keySym) {
case GDK_KEY_Escape:
@ -1556,9 +1548,7 @@ static void my_kbd_push_keyval(SpiceKbdInstance *sin, uint32_t keySym, int flags
}
}
#ifdef DEBUG
fprintf(stderr, "KEYPRESS OUT:%s: %08x\n", esc, uc); fflush (stderr);
#endif
DPRINTF(1, "%s: escape=%s unicode=%08x\n", __func__, esc, uc);
if (vt->y_displ != vt->y_base) {
vt->y_displ = vt->y_base;
@ -1589,8 +1579,6 @@ static void my_kbd_push_keyval(SpiceKbdInstance *sin, uint32_t keySym, int flags
ret:
if (flags & 2) { // UP
//printf("KEYRELEASE %08x\n", keySym);
if (keySym == GDK_KEY_Shift_L || keySym == GDK_KEY_Shift_R) {
shift = 0;
} else if (keySym == GDK_KEY_Control_L || keySym == GDK_KEY_Control_R) {
@ -1688,8 +1676,6 @@ static void master_watch(int master, int event, void *opaque)
{
spiceTerm *vt = (spiceTerm *)opaque;
printf("CHANNEL EVENT %d\n", event);
// fixme: if (!vt->mark_active) {
if (event == SPICE_WATCH_EVENT_READ) {
@ -1704,7 +1690,7 @@ static void master_watch(int master, int event, void *opaque)
spiceterm_puts (vt, buffer, c);
} else {
if (vt->ibuf_count > 0) {
printf ("DEBUG: WRITE %x %d\n", vt->ibuf[0], vt->ibuf_count);
DPRINTF(1, "%s: write input %x %d", __func__, vt->ibuf[0], vt->ibuf_count);
write (master, vt->ibuf, vt->ibuf_count);
vt->ibuf_count = 0; // fixme: what if not all data written
}
@ -1753,7 +1739,7 @@ main (int argc, char** argv)
setenv ("TERM", TERM, 1);
printf("EXEC: %s\n", command);
DPRINTF(1, "%s: execute %s", __func__, command);
pid = forkpty (&master, ptyname, NULL, &dimensions);
if(!pid) {