bug#43404: 28.0.50; .gdbinit 'pp' command cannot print stack-based Lisp values.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

bug#43404: 28.0.50; .gdbinit 'pp' command cannot print stack-based Lisp values.

Eli Zaretskii
This problem seems to be very old: I see it as far back as Emacs 25.
But it's an annoying problem that makes debugging Emacs harder than it
could be, so I hope we can fix it.

The problem is that stack-based Lisp variables created by the likes of
AUTO_STRING cannot have their values displayed by the 'pp' command
defined in src/.gdbinit.  To reproduce:

 $ cd /path/to/emacs/src
 $ gdb ./emacs
 (gdb) break fileio.c:4004
 (gdb) r -Q

Then in Emacs:

  C-x C-f README RET
  C-x i ../etc/HELLO RET

At this point the breakpoint breaks and GDB gets control.  Then:

  Thread 1 hit Breakpoint 2, Finsert_file_contents (
      filename=XIL(0x8000000006d00380), visit=XIL(0), beg=XIL(0), end=XIL(0),
      replace=XIL(0)) at fileio.c:4004
  4004                      record_unwind_current_buffer ();
  (gdb) pp name
  #<INVALID_LISP_OBJECT 0x8000000000829580>

But 'name' is a perfectly valid Lisp string:

  (gdb) p name
  $1 = XIL(0x8000000000829580)
  (gdb) xtype
  Lisp_String
  (gdb) xstring
  $2 = (struct Lisp_String *) 0x829580
  " *code-converting-work*"

The reason for this misfeature is the following safety net:

  void
  safe_debug_print (Lisp_Object arg)
  {
    int valid = valid_lisp_object_p (arg);

    if (valid > 0)
      debug_print (arg);
    else
      {
        EMACS_UINT n = XLI (arg);
        fprintf (stderr, "#<%s_LISP_OBJECT 0x%08"pI"x>\r\n",
                 !valid ? "INVALID" : "SOME",
                 n);
      }
  }

And valid_lisp_object_p returns zero for stack-based Lisp objects,
because (AFAIU) it wasn't meant to be used with such objects.

I can reproduce this both on MS-Windows and on GNU/Linux.

In GNU Emacs 28.0.50 (build 563, i686-pc-mingw32)
 of 2020-09-14 built on HOME-C4E4A596F7
Repository revision: 15d2f6af000625640b3c47d2aeec3114ac1ac544
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 5.1.2600
System Description: Microsoft Windows XP Service Pack 3 (v5.1.0.2600)

Configured using:
 'configure -C --prefix=/d/usr --with-wide-int --with-modules
 --enable-checking=yes,glyphs 'CFLAGS=-O0 -gdwarf-4 -g3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY W32NOTIFY ACL GNUTLS LIBXML2
HARFBUZZ ZLIB TOOLKIT_SCROLL_BARS MODULES THREADS JSON PDUMPER LCMS2

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1255

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
rfc822 mml easymenu mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs auth-source cl-seq eieio eieio-core cl-macs
eieio-loaddefs password-cache json map text-property-search time-date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel dos-w32 ls-lisp disp-table term/w32-win w32-win w32-vars
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads w32notify w32 lcms2 multi-tty make-network-process
emacs)

Memory information:
((conses 16 57744 8582)
 (symbols 48 7871 1)
 (strings 16 21145 2417)
 (string-bytes 1 614043)
 (vectors 16 12401)
 (vector-slots 8 167226 11660)
 (floats 8 23 239)
 (intervals 40 249 73)
 (buffers 888 10))