On Mon, 22 Nov 2010 17:28:21 +0100
Richard Guenther <richard.guent...@gmail.com> wrote:

> On Mon, Nov 22, 2010 at 4:43 PM, Basile Starynkevitch
> <bas...@starynkevitch.net> wrote:
> > Hello All,
> >
> > While debugging a MELT pass, I am sigsegv in debug_bb.
> >
> > The culprit is check_bb_profile which starts with
> >  if (profile_status == PROFILE_ABSENT)
> >    return;
> > and we have in basic-block.h
> > #define profile_status          (cfun->cfg->x_profile_status)
> >
> > and unfortunately, my pass is a SIMPLE IPA pass so don't have any cfun.
> >
> > Would a patch defining
> >
> > #define profile_status  (cfun?(cfun->cfg->x_profile_status):PROFILE_ABSENT)
> >
> > be acceptable?
> 
> Huh, no.  Just watch were you are calling debug_bb from (or
> even better, rewrite it with python).


I'm calling debug_bb from MELT code, so python is not really possible
(and I guess you mean python inside gdb). [the details are probably in
comments inside the gcc/testsuite/melt/topengpu-1.c file of the MELT
branch and the debug_bb is called from opengpudetect_exec function
inside gcc/melt/xtramelt-opengpu.melt rev 167035 of the melt branch]

My feeling is that debug printing routines are not mainly for gurus
like Richard Guenther or Diego Novillo or any other global reviewer or
top GCC expert (I would imagine neither Richard nor Diego needs them or
uses them), but for newbies.  And newbies make bugs. We can't change
that sad fact (unless you consider unethical solutions like killing
newbies, but I am against such solutions :-) because I might be the
victim!).

And debug printing is a common way to help find bugs.

Also, by definition, debug printing (& also dump printing) routines are
never called when GCC is used normally. They are only useful for people
hunting bugs (e.g. inside their plugins) or for newbies trying to
understand the internals of GCC.

A huge "production" compilation (e.g. by people compiling the kernel,
LibreOffice, Mozilla or Google proprietary code) never call any debug_*
debug-printing or dump_* dump-printing routine.

But people (e.g. newbies) making bugs are, perhaps naively, expecting
the debug printing routines to be robust, and not crash when given data
comming from inside GCC. 

Or can we consider adding something like
  if (!cfun) 
    return;
at start of check_bb_profile () in cfg.c, or at least replacing the last
     check_bb_profile (bb, buffer->buffer->stream);
in function dump_bb_header of gimple-pretty-print.c with
     if (cfun)
             check_bb_profile (bb, buffer->buffer->stream);

If we require a valid cfun from debug_bb, we should at least add a
gcc_assert in it.

BTW, I am just trying to understand how to code a SIMPLE IPA pass (and
where to place it).


Please GCC gurus, accept the sad fact that some people (me included)
understand GCC less than you, and precisely these people need debug
printing. You probably don't need these routines, they are to help
newbies! So they need to be reasonably robust. Don't forget that
newbies make bugs, more than you do.

Otherwise, please add at least a comment in header files explaining
when a debug_* or dump_* routine can be used (and even more when it
cannot be used)! I am not able to explain that!

Cheers.
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

Reply via email to