Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 May 2015 17:56:52 -0700
From:      NGie Cooper <yaneurabeya@gmail.com>
To:        Dimitry Andric <dim@freebsd.org>
Cc:        Alexander Kabaev <kabaev@gmail.com>,  "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>, Sean Bruno <sbruno@ignoranthack.me>
Subject:   Re: How to get anything useful out of kgdb?
Message-ID:  <CAGHfRMBxPL5G_iPz5RkbNrXkmR22D8xueybxK=OqVjKr_a2DHg@mail.gmail.com>
In-Reply-To: <2CEF3F4B-286C-47C5-B170-6CC017BE9D61@FreeBSD.org>
References:  <554E41EE.2010202@ignoranthack.me> <554E4BD1.1030802@ignoranthack.me> <406EAA27-D825-408B-985E-DC3FFE746473@frob.org> <554E5263.8010205@ignoranthack.me> <20150509190347.10e1e2c2@kan> <CAGHfRMAGTF0oh%2BR0kDxyx7PWSPfcTyZT-cMogF_LrV5pR2J4-w@mail.gmail.com> <CAGHfRMC10JJs7f9yzmNpeHNN8sM9ZFci1gpvqwqhvcGSQS4RXA@mail.gmail.com> <CAGHfRMDWpPdqmGObTGuOT_FMQodbqbqW-gkhjMgca-pjS%2Ba2Jg@mail.gmail.com> <2CEF3F4B-286C-47C5-B170-6CC017BE9D61@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, May 19, 2015 at 3:25 PM, Dimitry Andric <dim@freebsd.org> wrote:
> On 19 May 2015, at 21:32, NGie Cooper <yaneurabeya@gmail.com> wrote:
>>
>> On Mon, May 18, 2015 at 5:29 PM, NGie Cooper <yaneurabeya@gmail.com> wrote:
>>
>>> As a sidenote, this has been broken for over a decade:
>>> https://svnweb.freebsd.org/base?view=revision&revision=127204 :(...
>>
>> -O is synonymous with -O2 (both on clang and gcc) :(...
>
> No, for gcc -O has always meant -O1.  For clang, it means -O2.  If you
> want -O1, please specify it. :)

My bad. I typoed this earlier.

> Though with clang I don't think you will see too much difference
> regarding variables which have been put in registers, or eliminated
> altogether, making it harder to follow for gdb (especially the ancient
> version in base).
>
> If you want to have everything fully traceable, use -O0, and increase
> your kernel stack size, otherwise it is likely to blow up.

But *how* do you do that (especially when the build infrastructure
gets in the way of you setting this)?
Turns out there is a way if you dig deep enough through sys/conf/NOTES
and are willing to abuse a
feature...

  62 #
  63 # The `makeoptions' parameter allows variables to be passed to the
  64 # generated Makefile in the build area.
  65 #
  66 # CONF_CFLAGS gives some extra compiler flags that are added to ${CFLAGS}
  67 # after most other flags.  Here we use it to inhibit use of non-optimal
  68 # gcc built-in functions (e.g., memcmp).
  69 #
  70 # DEBUG happens to be magic.
  71 # The following is equivalent to 'config -g KERNELNAME' and creates
  72 # 'kernel.debug' compiled with -g debugging as well as a normal
  73 # 'kernel'.  Use 'make install.debug' to install the debug kernel
  74 # but that isn't normally necessary as the debug symbols are not loaded
  75 # by the kernel and are not useful there anyway.
  76 #
  77 # KERNEL can be overridden so that you can change the default name of your
  78 # kernel.
  79 #
  80 # MODULES_OVERRIDE can be used to limit modules built to a specific list.
  81 #
  82 makeoptions     CONF_CFLAGS=-fno-builtin  #Don't allow use of memcmp, etc.


 5 makeoptions     CONF_CFLAGS=-O2

I wouldn't expect most folks to figure this out though, and it
requires manual intervention in your kernel
configuration to do this, even though DEBUG is set. This is not
desirable for debug builds out of the box
nor for folks who are trying to use makeoptions DEBUG=-g in their KERNCONFs.

Cheers,
-NGie



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGHfRMBxPL5G_iPz5RkbNrXkmR22D8xueybxK=OqVjKr_a2DHg>