KernelNewbies
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Kernel Hacking

  • Frontpage

  • Kernel Hacking

  • Kernel Documentation

  • Kernel Glossary

  • FAQ

  • Found a bug?

  • Kernel Changelog

  • Upstream Merge Guide

Projects

  • KernelJanitors

  • KernelMentors

  • KernelProjects

Community

  • Why a community?

  • Regional Kernelnewbies

  • Personal Pages

  • Upcoming Events

References

  • Mailing Lists

  • Related Sites

  • Programming Links

Wiki

  • Recent Changes

  • Site Editors

  • Side Bar

  • Tips for Editors

  • Hosted by WikiWall

Navigation

  • RecentChanges
  • FindPage
  • HelpContents

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

KernelNewbies:
  • FAQ
  • LinuxKernelDebug101

Whats the easiest way to debug ?

The easiest way is the one you know. For most of us thats printf(), or its kernel version:

#include <device.h>
...
     printk(KERN_INFO DRVNAME "%s %s\n", info1, info2);
     printk(KERN_ERR DRVNAME "something bad: %s\n", errstr);
     printk("logged at (what?) default\n");

In lines 1,2, note the lack of comma after KERN_INFO and DRVNAME. These are string values that are catenated, per C language spec, to the front of the format string.

KERN_INFO and friends are defined here: https://elixir.bootlin.com/linux/v5.10/source/include/linux/kern_levels.h#L14

The logging system reads the numbers, and steers the message accorgingly.

Anything with less typing ?

For drivers with a struct device, device.h provides an easier way:

#include <device.h>
...
     dev_info("%s %s\n", info1, info2);
     dev_err("something bad: %s\n", errstr);

Messages issued by these statements include driver name, etc.

dev_dbg()

This symbol has additional feature - the statement typically disappears at compile-time, allowing developer to keep debug code w/o runtime penalties.

#define DEBUG 1
#include <device.h>
...
     dev_dbg("%s %s\n", info1, info2);

I'm still not seeing the debug messages !

If you're looking at the console for messages, may be you need to raise its verbosity:

     echo 8 > /proc/sys/kernel/printk

this will cause dev_dbg() messages, which are logged at level "<7>", to be reported to the console.

  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01