How to get anything useful out of kgdb?
NGie Cooper
yaneurabeya at gmail.com
Wed May 20 00:56:53 UTC 2015
On Tue, May 19, 2015 at 3:25 PM, Dimitry Andric <dim at freebsd.org> wrote:
> On 19 May 2015, at 21:32, NGie Cooper <yaneurabeya at gmail.com> wrote:
>>
>> On Mon, May 18, 2015 at 5:29 PM, NGie Cooper <yaneurabeya at 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
More information about the freebsd-hackers
mailing list