Subject: bug#16068: 24.3; Printing doesn't work

From: Eli Zaretskii <[email-masked]>
Date: Fri, 06 Dec 2013 16:53:19 +0200

> From: Андрей Парамонов <[email-masked]>
> Date: Fri, 6 Dec 2013 16:00:34 +0400
> Cc: [email-masked]
> 
> > Is it possible for you to step through default-printer-name with GDB
> > and see what happens there?  I can send you detailed instructions, if
> > you need them.
> >
> 
> Please do.

See below, and thanks in advance.

> Is it correct that default-printer-name is implemented in C (which is why I
> need GDB)?

Yes, this is correct.

I see that you are using Emacs 24.3, which is an official release.  I
suspect that this binary has been stripped of debugging symbols, so
you will be unable to debug it on the C source level.  So the first
thing I suggest to do after installing GDB (let me know if you need a
link for a Windows port of GDB) is type this from the shell prompt:

  gdb /path/to/emacs.exe

If GDB says something like this:

 Reading symbols from D:\foo\bar\emacs.exe...(no debugging symbols found)...done.
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^
then indeed the binary is stripped.  In that case, please download a
recent snapshot from here:

  https://sourceforge.net/projects/emacs-bin/files/snapshots/

and start by verifying that the same problem still exists there.  (It
could be that it was somehow fixed since 24.3 was released, although I
doubt that.)

Once you establish that the problem still exists in the snapshot,
here's the sequence of commands I'd like you to perform:

  gdb /path/to/emacs.exe

After GDB starts and displays its startup blurb, do this:

  (gdb) break Fdefault_printer_name
  (gdb) run -Q

The last command runs Emacs.  When Emacs starts up, it will show the
*scratch* buffer.  Type into that buffer:

  (default-printer-name)

Then go to the right parenthesis and type C-j.  This evaluates the
expression.  (Please forgive me if I'm telling you things you know
very well.)

When you evaluate that expression, the breakpoint you have set will
break, Emacs will stop, and GDB will take control.  Switch to the
window where you run GDB, you should see there something like this:

  Breakpoint 1, Fdefault_printer_name () at w32fns.c:7217
  7217      PRINTER_INFO_2 *ppi2 = NULL;
  (gdb)

(Since you don't have the sources, you will probably not see the
second line.)

If you want to see the source code of default-printer-name, you can
find it here:

  http://bzr.savannah.gnu.org/lh/emacs/trunk/annotate/head:/src/w32fns.c

(The function's source starts around line 7210 in that file.)

We want to get to line #7252, which is marked in the snippet below:

  err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned);
  ClosePrinter (hPrn);
  if (!err)
    {
      xfree (ppi2);
      return Qnil;
    }

  if (ppi2)  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    {
      if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName)
        {

The GDB command to do that is:

  (gdb) until 7252

(The "(gdb)" part is GDB's prompt, you don't need to type it.)

GDB will step Emacs till that line, and respond like this:

  Fdefault_printer_name () at w32fns.c:7252
  7252      if (ppi2)
  (gdb)

Now please tell GDB to display the contents of the ppi2 structure,
which holds the printer information Windows returned due to the call
to GetPrinter API:

  (gdb) print *ppi2

And post here everything you see.

If you will do this in Emacs 24.3 (in case it does have the debugging
symbols), then please use "until 6943" instead of 7252 above, because
the source line numbers of the snippet I show above are different in
that version.

Thanks again for your help.