Sunday, February 19, 2017

Some of Kernel Debugging techniques - Compile time flags

To enable all logs in a specific file by compile time:

CFLAGS_amdgpu_amdkfd_gpuvm.o := -DDEBUG

Adding below flag in make file will make sure all the logs from amdgpu_amdkfd_gpuvm.c will be available at dmesg.


Trace function calls in a specific file by compile time options:

CFLAGS_amdgpu_amdkfd_gpuvm.o := -DDEBUG  -finstrument-functions

Generate instrumentation calls for entry and exit to functions. Just after function entry and just before function exit,

the following profiling functions will be called with the address of the current function and its call site. […]

          void __cyg_profile_func_enter (void *this_fn,
                                         void *call_site);
          void __cyg_profile_func_exit  (void *this_fn,
                                         void *call_site);
[…]

FTRACE will not provide information about static function calls. But -finstrument-functions
will allow to print all function calls executed in that file.

Need to define these 2 functions as -finstrument-functions will include
__cyg_profile_func_enter at entry and at exit __cyg_profile_func_exit.

void __cyg_profile_func_enter (void *this_fn, void *call_site) {
    printk( "entering %pS\n", this_fn );
}

void __cyg_profile_func_exit (void *this_fn, void *call_site) {
    printk( "leaving %pS\n", this_fn );
}

%pS will print function name from function pointer.

Adding below information just for refresh:

ltrace is used to trace a process's library call.

strace is used to trace system call.

pstack - print a stack trace of running processes

suppose a program stops at a point , we would like to know the call stack

$ sudo pstack `pidof glxgears`