Re: How to set a breakpoint on imported Win32 function?

Ruslan Kabatsayev <[email protected]> Fri, 17 Jan 2020 11:41:02 +0300
Newsgroups gmane.comp.gdb.devel,gmane.comp.gdb.general
Message-ID <CAHEcG95i9v0FV0TroM2i5GtF+q+g4SBT6M+Qt2C61f=h0VcsRw@mail.gmail.com>
On Fri, 17 Jan 2020 at 10:46, Eli Zaretskii <[email protected]> wrote:
>
> > From: Ruslan Kabatsayev <[email protected]>
> > Date: Thu, 16 Jan 2020 23:00:04 +0300
> > Cc: Luis Machado <[email protected]>, [email protected]
> >
> > > If I start a MinGW program under GDB, and then put a breakpoint on
> > > ExitProcess, I get this:
> > >
> > >   Temporary breakpoint 2, main (argc=2, argv=0xa42848) at emacs.c:934
> > >   934       bool no_loadup = false;
> > >   (gdb) break ExitProcess
> > >   Breakpoint 3 at 0x7c81bfa7
> > >   (gdb) info breakpoints
> > >   Num     Type           Disp Enb Address    What
> > >   3       breakpoint     keep y   0x7c81bfa7 <KERNEL32!ExitProcess+5>
> > >
> > > So it seems that GDB already knows how to put breakpoints on such
> > > functions: you just need to name them without the DLL-name part.
> > > However, I'm not sure I understand what is meant above by "functions
> > > imported by name".  How exactly were they imported?  Does the above
> > > technique work for you?
> >
> > They were imported as named functions usually are, i.e. not by
> > ordinal. I just said this to emphasize that GDB should be able to find
> > these symbols.
>
> Doesn't the fact that "break ExitProcess" works mean GDB _is_ able to
> find the symbol?  Maybe I'm missing something, but I always considered
> the "KERNEL32!" part some kind of decoration, not really part of the
> symbol.

Well, the problem was that "break ExitProcess" failed to locate the
symbol and suggested to wait for a shared library load, after which
the breakpoint got missed, as if kernel32.dll hadn't been loaded.
But unfortunately, now after I've tried to reproduce the problem on
the original machine where I had it with the original app I debugged,
I can't reproduce it. Must have been my own mistake. GDB successfully
finds the symbols, and breakpoints trap as they should.

Thanks anyway, and sorry for the noise.