diff --git a/src/dispextern.h b/src/dispextern.h
index 25bd6b2..48e2606 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2587,6 +2587,16 @@ struct it
      produce_glyphs.  */
   int pixel_width;
 
+
+/* *************************************************************************** */
+/* Debug the pixel-width of a stretch tab. */
+
+  /* Width of the display element in pixels.  Result of produce_glyphs.  */
+  int my_pixel_width;
+
+/* *************************************************************************** */
+
+
   /* Current, maximum logical, and maximum physical line height
      information.  Result of produce_glyphs.  */
   int ascent, descent, max_ascent, max_descent;
diff --git a/src/xdisp.c b/src/xdisp.c
index 903815c..7256063 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -28295,6 +28295,34 @@ x_produce_glyphs (struct it *it)
 	    }
 	}
 
+
+/* *************************************************************************** */
+/* Debug the pixel-width of a stretch tab. */
+
+  if (it->char_to_display == '\t'
+      && !NILP (Vdisplay_line_numbers)
+      && it->w->hscroll > 0
+      && it->current_x < it->lnum_pixel_width)
+    {
+      int my_tab_width = it->tab_width * font->space_width;
+      int my_x = it->current_x + it->continuation_lines_width;
+      int my_next_tab_x = ((1 + my_x + my_tab_width - 1) / my_tab_width)
+                          * my_tab_width;
+      if (my_next_tab_x - my_x < font->space_width)
+        my_next_tab_x += my_tab_width;
+      if (!NILP (Vdisplay_line_numbers))
+        my_next_tab_x += it->lnum_pixel_width
+                         - ((it->w->hscroll * font->space_width)
+                            % my_tab_width);
+      /* FIXME:  Should we use font->space_width instead of it->current_x? */
+      it->my_pixel_width = my_next_tab_x - it->lnum_pixel_width - it->current_x;
+    }
+    else
+      it->my_pixel_width = 0;
+
+/* *************************************************************************** */
+
+
       if (FONT_TOO_HIGH (font))
 	{
 	  int font_ascent, font_descent;
@@ -32251,9 +32279,176 @@ x_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
 			    Initialization
  ***********************************************************************/
 
+
+/* *************************************************************************** */
+/* Debug the pixel-width of a stretch tab. */
+
+DEFUN ("debug-tab-pixel-width", Fdebug_tab_pixel_width, Sdebug_tab_pixel_width, 0, 0, 0,
+       doc: /* Debug the pixel-width of a stretch tab. */)
+  (void)
+{
+  Fscroll_left (make_number (1), Qnil);
+  struct window *w = decode_live_window (selected_window);
+  struct frame *f = XFRAME (w->frame);
+  Lisp_Object buf = w->contents;
+  CHECK_BUFFER (buf);
+  struct buffer *b = XBUFFER (buf);
+  struct it it;
+  void *itdata = bidi_shelve_cache ();
+  struct it saved_it_for_window_start;
+  void *saved_itdata_for_window_start = NULL;
+  enum move_it_result rc = MOVE_X_REACHED;
+  struct text_pos start_text_position;
+  ptrdiff_t it_start;
+  int first_x, last_x;
+  int lnum_width = 0;
+  int lnum_pixel_width = 0;
+  int frame_char_width = FRAME_COLUMN_WIDTH (f);
+  bool hscl = (!w->suspend_auto_hscroll
+               && EQ (Fbuffer_local_value (Qauto_hscroll_mode, buf), Qcurrent_line)
+               && w->hscroll > 0);
+  int w_hscroll = w->hscroll;
+  int hscl_first_hpos = window_hscroll_limited (w, f);
+  int hscl_first_x = hscl_first_hpos * frame_char_width;
+  int text_area_width = window_box_width (w, TEXT_AREA);
+  int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w);
+  int relative_x, hpos, vpos;
+  int opoint_x = w->output_cursor.x;
+  int opoint_y = w->output_cursor.y;
+  int opoint_hpos = w->output_cursor.hpos;
+  int opoint_vpos = w->output_cursor.vpos;
+  int count = 1;
+  int my_pixel_width = 0;
+/* ******************************************************************************
+                      START DISPLAY AND PRIME IT
+****************************************************************************** */
+  /* Begin the journey at w->start. */
+  SET_TEXT_POS_FROM_MARKER (start_text_position, w->start);
+  start_display (&it, w, start_text_position);
+  first_x = it.first_visible_x;
+  last_x = it.last_visible_x;
+  it_start = IT_CHARPOS (it);
+  SAVE_IT (saved_it_for_window_start, it, saved_itdata_for_window_start);
+  /* Finish priming the IT for potential line numbers. */
+  if (!NILP (Vdisplay_line_numbers)
+      && !EQ (Vdisplay_line_numbers, Qvisual))
+    {
+      it.first_visible_x = 0;
+      move_it_by_lines (&it, 1);
+      lnum_width = it.lnum_width;
+      lnum_pixel_width = it.lnum_pixel_width;
+      RESTORE_IT (&it, &saved_it_for_window_start, saved_itdata_for_window_start);
+      it.first_visible_x = first_x;
+      it.last_visible_x = last_x;
+      it.lnum_width = lnum_width;
+      it.lnum_pixel_width = lnum_pixel_width;
+      SAVE_IT (saved_it_for_window_start, it, saved_itdata_for_window_start);
+    }
+/* ******************************************************************************
+                            GOTO LINE BEGIN
+****************************************************************************** */
+  /* Place the IT on the current line containing PT. */
+  int voffset = (header_line_height > 0
+                 && opoint_vpos > 0)
+                  ? opoint_vpos - 1
+                  : opoint_vpos;
+  if (voffset > 0)
+    move_it_by_lines (&it, voffset);
+/* ******************************************************************************
+                        FIRST X => PENULTIMATE EOL
+****************************************************************************** */
+  while (true)
+    {
+      if (hscl)
+        {
+          relative_x = it.current_x - (hscl_first_hpos * frame_char_width);
+          hpos = it.hpos - hscl_first_hpos;
+        }
+        else
+          {
+            relative_x = it.current_x - first_x;
+            hpos = it.hpos;
+          }
+      if (header_line_height > 0)
+        vpos = it.vpos + 1;
+        else
+          vpos = it.vpos;
+      bool final_loop_p = (ITERATOR_AT_END_OF_LINE_P (&it)
+                           || FETCH_BYTE (IT_BYTEPOS (it)) == '\n'
+                           || rc == MOVE_POS_MATCH_OR_ZV);
+      if (final_loop_p)
+        break;
+      bool nothing_p = (it.c == 0);
+      bool tab_visible_p = (it.c == 187);
+      bool tab_invisible_p = (it.c == '\t');
+      if (w->hscroll > 0)
+        fprintf (stderr, "\n%d.  %s\n\
+    it.c (%d)\n\
+    w->hscroll (%d)\n\
+    it.current_x (%d)\n\
+    it.pixel_width (%d)\n\
+    it.my_pixel_width (%d)\n\
+    %s (%d)\n",
+                 count,
+                 (nothing_p
+                   ? "NOTHING"
+                   : tab_visible_p
+                     ? "TAB CHARACTER"
+                   : tab_invisible_p
+                     ? "TAB STRETCH"
+                   : "TEXT"),
+                 it.c,
+                 w_hscroll,
+                 it.current_x,
+                 it.pixel_width,
+                 it.my_pixel_width,
+                 ((!nothing_p
+                   && !tab_visible_p
+                   && !tab_invisible_p)
+                  ? "first_x + lnum_pixel_width + it.my_pixel_width"
+                  : "N/A"),
+                 ((!nothing_p
+                   && !tab_visible_p
+                   && !tab_invisible_p)
+                  ? first_x + lnum_pixel_width + my_pixel_width
+                  : 0));
+      rc = move_it_in_display_line_to (&it, ZV, it.current_x + it.pixel_width,
+                                       MOVE_TO_POS | MOVE_TO_X);
+      count = count + 1;
+      if (it.my_pixel_width > 0)
+        my_pixel_width = it.my_pixel_width;
+      if (rc == MOVE_LINE_CONTINUED)
+        break;
+      relative_x = (hscl)
+                   ? it.current_x - (hscl_first_hpos * frame_char_width)
+                   : it.current_x - first_x;
+      if (relative_x + frame_char_width >= text_area_width)
+        break;
+    }
+  redisplay_internal ();
+  fprintf (stderr, "\n");
+  struct glyph_row *glyph_row = MATRIX_ROW (w->current_matrix, it.vpos);
+  dump_glyph_row (glyph_row, it.vpos, 2);
+  bidi_unshelve_cache (itdata, false);
+  return Qnil;
+}
+
+/* *************************************************************************** */
+
+
 void
 syms_of_xdisp (void)
 {
+
+
+/* *************************************************************************** */
+/* Debug the pixel-width of a stretch tab. */
+
+  defsubr (&Sdebug_tab_pixel_width);
+
+/* *************************************************************************** */
+
+
   Vwith_echo_area_save_vector = Qnil;
   staticpro (&Vwith_echo_area_save_vector);
 
