How can I disable compile optimization in kernel for friendly debugging, Thanks

Yubin Ruan ablacktshirt at gmail.com
Sat Apr 21 09:15:10 EDT 2018


On 2018-04-20 16:08, valdis.kletnieks at vt.edu wrote:
> On Fri, 20 Apr 2018 23:39:10 +0800, Yubin Ruan said:
> > On 2018-04-19 13:28, valdis.kletnieks at vt.edu wrote:
> > > On Thu, 19 Apr 2018 16:58:40 +0800, sizel said:
> > > >  How can I disable compile optimization in kernel for friendly  debugging, Thanks
> > >
> > > First off, there are parts of the kernel that *WILL* explode if you try to build
> > > with -O0 - in particular, any code that expects static inlines to be treated as
> > > part of the unit they are inlined into for the purposes of __builtin_return_address()
> > > and similar.
> >
> > Can you elaborate more on that?
> 
> grep for __builtin_return_address.  Look where it's used. What does it return
> if it's inlined? What does it return if it's called as  not inlined?
> 
> For a simple example, consider this code from lib/smp_processor_id.c: in
> function check_preemption_disabled():
> 
>         printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
>                 what1, what2, preempt_count() - 1, current->comm, current->pid);
> 
>         printk("caller is %pS\n", __builtin_return_address(0));
>         dump_stack();
> 
> If __builtin_return_address is not inlined, that call points at the printk()
> call. If it *is* inlined, it points at the return point in the function that
> called check_preemption_disabled().

Thanks! I tested it and found that __builtin_return_addres's behavior is
indeed as you described.

>From this, I have a related question, can I treat __builtin_return_address()
as a "builtin" stack unwinder (but only check for return addresses, or, where
a function is called).

Yubin



More information about the Kernelnewbies mailing list