To open Pr_debug and dev_dbg.

Source: Internet
Author: User

The log that uses the Pr_debug and dev_dbg print drivers is often seen during Linux drivers, and if you select the Config_dynamic_debug macro in the kernel configuration, you can use the following command to open the log of the corresponding file:

" file xxx.c +p " >/sys/kernel/debug/dynamic_debug/control

But sometimes we need to see the log of this file on the inside of the activate stage, so what do we do?

There are two ways to do this:

Method one revision internal nuclear

Modify the bootloader to kernel Bootargs, if you use the tree, you can modify the value of Bootargs in the chosen, the method of internal nuclear files: documentation/ Dynamic-debug-howto.txt

The advantage of this option is that you do not need to change the drive code.

Method Two at the beginning of the drive file that requires the log to be opened define macro debug

So the Pr_debug and dev_dbg in the drivers file can be opened.

For example, the name of the drivers file is tfa98xx.c, then add the definition of the debug macro in its first non-registered line:

/** TFA98XX.C TFA98XX Codec module * * Copyright (c) NXP Semiconductors * * Author:sebastien Jan <[email PR otected]> * * This program was free software; You can redistribute it and/or modify it * under the terms of the GNU general public License as published by the * Fre  e software Foundation; Either version 2 of the License, or (at your * option) any later version. */ #define DEBUG#definePR_FMT (FMT) "%s ():" FMT, __func__#include<linux/module.h>#include<linux/i2c.h>#include<sound/core.h>#include<sound/pcm.h>#include<sound/pcm_params.h>#include<sound/soc.h>#include<linux/of_gpio.h>......

Why do you do this? Let's take pr_debug as a simple analysis.

After the Config_dynamic_debug is configured in the internal nucleus, the definition of Pr_debug is as follows:

#define pr_debug (FMT, ...) \    dynamic_pr_debug (FMT, # #__VA_ARGS__)

The definition of Dynamic_pr_debug is as follows:

#define dynamic_pr_debug (FMT, ...)                 Do {                                    Define_dynamic_debug_metadata (descriptor, FMT);             if (Unlikely (Descriptor.flags & _dprintk_flags_print))            __dynamic_pr_debug (&Descriptor, PR _FMT (FMT),                       # #__VA_ARGS__);          while (0)

This uses the macro define_dynamic_debug_metadata, the definition is as follows:

#defineDefine_dynamic_debug_metadata (name, FMT)Static struct_ddebug __aligned (8) __attribute__ (section ("__verbose"))) name ={. ModName=kbuild_modname,. function=__func__,. FileName=__file__,. Format=(FMT),. Lineno=__line__,. Flags=_dprintk_flags_default,}

The definition of __dynamic_pr_debug is as follows:

void__dynamic_pr_debug (struct_ddebug *descriptor,Const Char*FMT, ...)    {va_list args; structVa_format VAF; CharBuf[prefix_size]; BUG_ON (!descriptor); BUG_ON (!FMT);    Va_start (args, FMT); Vaf.fmt=FMT; Vaf.va= &args; PRINTK (Kern_debug"%S%PV", Dynamic_emit_prefix (descriptor, BUF), &VAF); Va_end (args);}

As you can see from the code above, each pr_debug is called descriptor, and the type is the variable of the struct _ddebug , stored in the __verbose segment of kernel. Deciding whether this pr_debug can output log is Descriptor.flags & _dprintk_flags_print true.

In the definition of descriptor , the value of its FLAGS to _dprintk_flags_default, look at the definition of these two macros:

#if defined DEBUG#define _dprintk_flags_default _dprintk_flags_print#else#define _dprintk_flags_default 0#endif

It can be seen that if the definition of macro debug, then _dprintk_flags_default is actually _dprintk_flags_print, so the default is to print. If there is no definition, then the _dprintk_flags_default is 0, the above article will not be set up, it can not print.

To open Pr_debug and dev_dbg.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.