From c6c00f6465378d8a6285d97b4ab0defa7d871b7e Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Sat, 27 Aug 2016 13:43:10 -0700 Subject: [PATCH weston 1/2] weston-terminal crashes periodically due to race condition on init NOT FOR TRUNK This patchset adds a bunch of debugging gunk to diagnose where weston-terminal is crashing. Signed-off-by: Bryce Harrington --- clients/terminal.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/clients/terminal.c b/clients/terminal.c index 6257cb7..284d4d5 100644 --- a/clients/terminal.c +++ b/clients/terminal.c @@ -555,8 +555,14 @@ static union utf8_char * terminal_get_row(struct terminal *terminal, int row) { int index; - index = (row + terminal->start) & (terminal->buffer_height - 1); + if (row < 1) { + fprintf(stderr, "terminal_get_row: row = %d, index = %d\n", row, index); + fprintf(stderr, "terminal_get_row: terminal->buffer_height %d\n", + terminal->buffer_height); + fprintf(stderr, "terminal_get_row: terminal->data_pitch %d\n", + terminal->data_pitch); + } return (void *) terminal->data + index * terminal->data_pitch; } @@ -631,6 +637,7 @@ terminal_scroll_buffer(struct terminal *terminal, int d) { int i; + fprintf(stderr, "terminal_scroll_buffer\n"); terminal->start += d; if (d < 0) { d = 0 - d; @@ -658,6 +665,8 @@ terminal_scroll_window(struct terminal *terminal, int d) int window_height; int from_row, to_row; + fprintf(stderr, "terminal_scroll_window\n"); + // scrolling range is inclusive window_height = terminal->margin_bottom - terminal->margin_top + 1; d = d % (window_height + 1); @@ -702,10 +711,13 @@ terminal_scroll_window(struct terminal *terminal, int d) static void terminal_scroll(struct terminal *terminal, int d) { - if (terminal->margin_top == 0 && terminal->margin_bottom == terminal->height - 1) + if (terminal->margin_top == 0 && terminal->margin_bottom == terminal->height - 1) { + fprintf(stderr, "terminal_scroll: margin_top = %d, margin_bottom = %d, height -1 = %d\n", + terminal->margin_top, terminal->margin_bottom, terminal->height -1); terminal_scroll_buffer(terminal, d); - else + } else { terminal_scroll_window(terminal, d); + } } static void @@ -714,6 +726,8 @@ terminal_shift_line(struct terminal *terminal, int d) union utf8_char *row; struct attr *attr_row; + fprintf(stderr, "terminal_shift_line\n"); + row = terminal_get_row(terminal, terminal->row); attr_row = terminal_get_attr_row(terminal, terminal->row); @@ -754,6 +768,8 @@ terminal_resize_cells(struct terminal *terminal, struct rectangle allocation; struct winsize ws; + fprintf(stderr, "terminal_resize_cells\n"); + if (uheight > terminal->buffer_height) height = terminal->buffer_height; @@ -761,6 +777,8 @@ terminal_resize_cells(struct terminal *terminal, return; if (terminal->data && width <= terminal->max_width) { + fprintf(stderr, "width <= terminal->max_width (%d <= %d)\n", + width, terminal->max_width); d = 0; if (height < terminal->height && height <= terminal->row) d = terminal->height - height; @@ -776,6 +794,9 @@ terminal_resize_cells(struct terminal *terminal, } else { terminal->max_width = width; data_pitch = width * sizeof(union utf8_char); + fprintf(stderr, "width = %d, utf8_char size = %d; data_pitch = %d\n", + width, (int)sizeof(union utf8_char), data_pitch); + data = xzalloc(data_pitch * terminal->buffer_height); attr_pitch = width * sizeof(struct attr); data_attr = xmalloc(attr_pitch * terminal->buffer_height); @@ -858,6 +879,9 @@ resize_handler(struct widget *widget, struct terminal *terminal = data; int32_t columns, rows, m; + fprintf(stderr, "resize_handler(%p, %d, %d, %p)\n", + widget, width, height, data); + m = 2 * terminal->margin; columns = (width - m) / (int32_t) terminal->average_width; rows = (height - m) / (int32_t) terminal->extents.height; @@ -866,9 +890,12 @@ resize_handler(struct widget *widget, !window_is_maximized(terminal->window)) { width = columns * terminal->average_width + m; height = rows * terminal->extents.height + m; + fprintf(stderr, "resizing widget: width=%d, height=%d\n", + width, height); widget_set_size(terminal->widget, width, height); } + fprintf(stderr, "resizing cells: %d, %d\n", columns, rows); terminal_resize_cells(terminal, columns, rows); update_title(terminal); } @@ -938,6 +965,8 @@ terminal_send_selection(struct terminal *terminal, int fd) FILE *fp; int len; + fprintf(stderr, "terminal_send_selection\n"); + fp = fdopen(fd, "w"); if (fp == NULL){ close(fd); @@ -1046,6 +1075,8 @@ redraw_handler(struct widget *widget, void *data) double average_width; double unichar_width; + fprintf(stderr, "redraw_handler\n"); + surface = window_get_surface(terminal->window); widget_get_allocation(terminal->widget, &allocation); cr = widget_cairo_create(terminal->widget); @@ -1181,6 +1212,8 @@ handle_term_parameter(struct terminal *terminal, int code, int sr) { int i; + fprintf(stderr, "handle_term_parameter\n"); + if (terminal->escape_flags & ESC_FLAG_WHAT) { switch(code) { case 1: /* DECCKM */ @@ -1421,6 +1454,7 @@ handle_escape(struct terminal *terminal) terminal->column--; break; case 'J': /* ED - Erase display */ + fprintf(stderr, "ED - Erasing the display\n"); row = terminal_get_row(terminal, terminal->row); attr_row = terminal_get_attr_row(terminal, terminal->row); if (!set[0] || args[0] == 0 || args[0] > 2) { @@ -1450,6 +1484,7 @@ handle_escape(struct terminal *terminal) } break; case 'K': /* EL - Erase line */ + fprintf(stderr, "EL - Erase line\n"); row = terminal_get_row(terminal, terminal->row); attr_row = terminal_get_attr_row(terminal, terminal->row); if (!set[0] || args[0] == 0 || args[0] > 2) { @@ -1466,6 +1501,7 @@ handle_escape(struct terminal *terminal) } break; case 'L': /* IL - Insert blank lines */ + fprintf(stderr, "IL - Insert blank lines\n"); count = set[0] ? args[0] : 1; if (count == 0) count = 1; if (terminal->row >= terminal->margin_top && @@ -1483,6 +1519,7 @@ handle_escape(struct terminal *terminal) } break; case 'M': /* DL - Delete lines */ + fprintf(stderr, "DL - Deleting lines\n"); count = set[0] ? args[0] : 1; if (count == 0) count = 1; if (terminal->row >= terminal->margin_top && @@ -1503,12 +1540,15 @@ handle_escape(struct terminal *terminal) terminal_shift_line(terminal, 0 - count); break; case 'S': /* SU */ + fprintf(stderr, "SU\n"); terminal_scroll(terminal, set[0] ? args[0] : 1); break; case 'T': /* SD */ + fprintf(stderr, "SD\n"); terminal_scroll(terminal, 0 - (set[0] ? args[0] : 1)); break; case 'X': /* ECH - Erase characters on current line */ + fprintf(stderr, "ECH - Erasing characters\n"); count = set[0] ? args[0] : 1; if (count == 0) count = 1; if ((terminal->column + count) > terminal->width) @@ -1689,6 +1729,7 @@ handle_escape(struct terminal *terminal) static void handle_non_csi_escape(struct terminal *terminal, char code) { + fprintf(stderr, "handle_non_csi_escape\n"); switch(code) { case 'M': /* RI - Reverse linefeed */ terminal->row -= 1; @@ -1884,6 +1925,7 @@ handle_special_char(struct terminal *terminal, char c) /* fallthrough */ case '\v': case '\f': + fprintf(stderr, "\\f\n"); terminal->row++; if (terminal->row > terminal->margin_bottom) { terminal->row = terminal->margin_bottom; @@ -1919,6 +1961,8 @@ handle_special_char(struct terminal *terminal, char c) terminal->column = terminal->width - 1; terminal->row -= 1; if (terminal->row < terminal->margin_top) { + fprintf(stderr, "\\b row = %d, margin_top = %d\n", + terminal->row, terminal->margin_top); terminal->row = terminal->margin_top; terminal_scroll(terminal, -1); } @@ -1972,6 +2016,8 @@ handle_char(struct terminal *terminal, union utf8_char utf8) terminal->column = 0; terminal->row += 1; if (terminal->row > terminal->margin_bottom) { + fprintf(stderr, "handle right margin effects: row = %d, margin_top = %d\n", + terminal->row, terminal->margin_top); terminal->row = terminal->margin_bottom; terminal_scroll(terminal, +1); } @@ -1985,6 +2031,11 @@ handle_char(struct terminal *terminal, union utf8_char utf8) if (terminal->mode & MODE_IRM) terminal_shift_line(terminal, +1); + /* TODO: Crashing here. + utf8 = "b\000\000" + terminal->column = 0 + row is a union + */ row[terminal->column] = utf8; attr_row[terminal->column++] = terminal->curr_attr; @@ -2598,6 +2649,8 @@ recompute_selection(struct terminal *terminal) int cw, ch; union utf8_char *data; + fprintf(stderr, "recompute_selection\n"); + cw = terminal->average_width; ch = terminal->extents.height; widget_get_allocation(terminal->widget, &allocation); @@ -2975,8 +3028,10 @@ terminal_create(struct display *display) cairo_destroy(cr); cairo_surface_destroy(surface); + fprintf(stderr, "Resizing terminal to 20, 5 as default minimum\n"); terminal_resize(terminal, 20, 5); /* Set minimum size first */ - terminal_resize(terminal, 80, 25); + fprintf(stderr, "Resizing terminal to 80, 25\n"); + terminal_resize(terminal, 80, 25); /* Set minimum size first */ wl_list_insert(terminal_list.prev, &terminal->link); @@ -3040,13 +3095,16 @@ terminal_run(struct terminal *terminal, const char *path) terminal->master = master; fcntl(master, F_SETFL, O_NONBLOCK); terminal->io_task.run = io_handler; + fprintf(stderr, "display_watch_fd\n"); display_watch_fd(terminal->display, terminal->master, EPOLLIN | EPOLLHUP, &terminal->io_task); if (option_fullscreen) window_set_fullscreen(terminal->window, 1); - else + else { + fprintf(stderr, "calling terminal_resize(..., 80, 24)\n"); terminal_resize(terminal, 80, 24); + } return 0; } -- 1.9.1