/sys/ kernel /debug/ dynamic_debug/control 打開usbcore模塊中所有的動態(tài)輸出語句 # echo 'module usbcore +p' > /sys/ kernel /debug/ dynamic_debug/control 打開svc_process()函數中所有的動態(tài)輸出語句 # echo 'func svc_process() +p' > /sys/ kernel /debug/ dynamic_debug/control 打開文件路徑包含usb的文件里所有的動態(tài)輸出語句 # echo -n '*usb* +p' > /sys/ kernel /debug/ dynamic_debug/control 打開系統(tǒng)所有的動態(tài)輸出語句 # echo -n '+p' > /sys/ kernel" />

欧美性猛交xxxx免费看_牛牛在线视频国产免费_天堂草原电视剧在线观看免费_国产粉嫩高清在线观看_国产欧美日本亚洲精品一5区

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

Linux內核基礎:動態(tài)輸出使用

麥辣雞腿堡 ? 來源:嵌入式Linux充電站 ? 作者:Vincent ? 2023-09-27 15:51 ? 次閱讀

動態(tài)輸出使用

打開svcsock.c文件中所有的動態(tài)輸出語句

# echo 'file svcsock.c +p' > /sys/kernel/debug/dynamic_debug/control

打開usbcore模塊中所有的動態(tài)輸出語句

# echo 'module usbcore +p' > /sys/kernel/debug/dynamic_debug/control

打開svc_process()函數中所有的動態(tài)輸出語句

# echo 'func svc_process() +p' > /sys/kernel/debug/dynamic_debug/control

打開文件路徑包含usb的文件里所有的動態(tài)輸出語句

# echo -n '*usb* +p' > /sys/kernel/debug/dynamic_debug/control

打開系統(tǒng)所有的動態(tài)輸出語句

# echo -n '+p' > /sys/kernel/debug/dynamic_debug/control

上面是打開動態(tài)輸出語句的例子,除了能輸出pr_debug()/dev_dbg()函數中定義的輸出信息外,還能輸出一些額外信息,如函數名、行號、模塊名字以及線程ID等

  • p:打開動態(tài)輸出語句
  • f:輸出函數名
  • l:輸出行號
  • m:輸出模塊名字
  • t:輸出線程ID

另外,還可以在各個子系統(tǒng)的Makefile中添加ccflags來打開動態(tài)輸出語句

< ../Makefile >

ccflags-y += -DDEBUG
ccflags-y += -DVERBOSE_DEBUG

實際案例

例如在一個led驅動中的open()、write()等函數開頭添加一句pr_debug("%s entern",
**func **** ** );

#include < linux/module.h >
#include < linux/fs.h >
#include < linux/errno.h >
#include < linux/miscdevice.h >
#include < linux/kernel.h >
#include < linux/major.h >
#include < linux/mutex.h >
#include < linux/proc_fs.h >
#include < linux/seq_file.h >
#include < linux/stat.h >
#include < linux/init.h >
#include < linux/device.h >
#include < linux/tty.h >
#include < linux/kmod.h >
#include < linux/gfp.h >

static int major = 0;
static char kernel_buf[1024];
static struct class *hello_class;

#define MIN(a, b) (a < b ? a : b)

static ssize_t hello_drv_read (struct file *file, char __user *buf, size_t size, loff_t *offset)
{
 int err;
 pr_debug("%s entern", __func__);

 err = copy_to_user(buf, kernel_buf, MIN(1024, size));
 return MIN(1024, size);
}

static ssize_t hello_drv_write (struct file *file, const char __user *buf, size_t size, loff_t *offset)
{
 int err;
 pr_debug("%s entern", __func__);
 err = copy_from_user(kernel_buf, buf, MIN(1024, size));
 return MIN(1024, size);
}

static int hello_drv_open (struct inode *node, struct file *file)
{
 pr_debug("%s entern", __func__);
 return 0;
}

static int hello_drv_close (struct inode *node, struct file *file)
{
 pr_debug("%s entern", __func__);
 return 0;
}

/* 2. 定義自己的file_operations結構體                                              */
static struct file_operations hello_drv = {
 .owner  = THIS_MODULE,
 .open    = hello_drv_open,
 .read    = hello_drv_read,
 .write   = hello_drv_write,
 .release = hello_drv_close,
};

static int __init hello_init(void)
{
 int err;
 
 pr_debug("%s entern", __func__);
 major = register_chrdev(0, "hello", &hello_drv);  /* /dev/hello */

 hello_class = class_create(THIS_MODULE, "hello_class");
 err = PTR_ERR(hello_class);
 if (IS_ERR(hello_class)) {
  unregister_chrdev(major, "hello");
  return -1;
 }
 
 device_create(hello_class, NULL, MKDEV(major, 0), NULL, "hello"); /* /dev/hello */
 
 return 0;
}

static void __exit hello_exit(void)
{
 pr_debug("%s entern", __func__);
 device_destroy(hello_class, MKDEV(major, 0));
 class_destroy(hello_class);
 unregister_chrdev(major, "hello");
}

module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");

為了方面查看,先清除內核輸出:

# dmesg -c

然后加載驅動,執(zhí)行dmesg查看是否有打?。?/p>

# insmod hello_drv.ko
# dmesg

圖片

此時沒有pr_debug()的打印。這時再使用動態(tài)輸出打開hello_drv模塊的動態(tài)輸出:

# echo 'module hello_drv +p' > /sys/kernel/debug/dynamic_debug/control

然后執(zhí)行該驅動的應用層程序,使其調用到驅動的open、write、close函數,從而執(zhí)行pr_debug():

# ./hello_drv_test -w 10

再查看demsg內容:

圖片

可以看到,當打開了hello_drv模塊的動態(tài)輸出后,驅動中的pr_debug()語句就可以正常打印了。

再看看debugfs的control節(jié)點:

# cat /sys/kernel/debug/dynamic_debug/control

圖片

control節(jié)點記錄了剛剛執(zhí)行pr_debug()時的文件名、所在行號、模塊名、函數名和輸出語句(p表示動態(tài)輸出的語句)。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規(guī)問題,請聯系本站處理。 舉報投訴
  • 內核
    +關注

    關注

    3

    文章

    1384

    瀏覽量

    40442
  • 驅動
    +關注

    關注

    12

    文章

    1853

    瀏覽量

    85691
  • Linux
    +關注

    關注

    87

    文章

    11351

    瀏覽量

    210512
  • 輸出
    +關注

    關注

    0

    文章

    93

    瀏覽量

    21876
收藏 人收藏

    評論

    相關推薦

    Linux內核學習筆記:動態(tài)輸出調試

    上篇說到printk調試,但printk是全局的,只能設置輸出等級。而動態(tài)輸出可以動態(tài)選擇打開某個內核子系統(tǒng)的
    發(fā)表于 06-01 15:16 ?606次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>內核</b>學習筆記:<b class='flag-5'>動態(tài)</b><b class='flag-5'>輸出</b>調試

    嵌入式Linux系統(tǒng)中內核抽象的動態(tài)擴展技術

    擴展性的意義。然后,討論目前幾種主要的核心動態(tài)擴展技術,以及各種技術在嵌入式系統(tǒng)上的優(yōu)缺點。最后,分析嵌入式Linux動態(tài)擴展性研究所面臨的挑戰(zhàn)和發(fā)展趨勢。 1、幾種主要的內核
    發(fā)表于 10-26 09:22

    嵌入式Linux系統(tǒng)中內核抽象的動態(tài)擴展技術

    擴展性的意義。然后,討論目前幾種主要的核心動態(tài)擴展技術,以及各種技術在嵌入式系統(tǒng)上的優(yōu)缺點。最后,分析嵌入式Linux動態(tài)擴展性研究所面臨的挑戰(zhàn)和發(fā)展趨勢?!?、幾種主要的內核
    發(fā)表于 10-28 09:53

    嵌入式Linux系統(tǒng)中內核抽象的動態(tài)擴展技術

    嵌入式Linux系統(tǒng)中內核抽象的動態(tài)擴展技術隨著嵌入式技術的快速發(fā)展和嵌入式設備的普及,嵌入式應用發(fā)展的一個關鍵趨勢是從靜態(tài)的、固定的系統(tǒng)功能到動態(tài)的、可擴展的系統(tǒng)功能。首先,介紹嵌入
    發(fā)表于 04-04 17:12

    Linux嵌入式系統(tǒng)中內核技術的可動態(tài)拓展技術有哪些

    值后要重新編譯內核,對普通用戶而言難以實現。通信的發(fā)展使得嵌入式操作系統(tǒng)的動態(tài)擴展成為可能,可以在遠程控制的基礎上增加嵌入式系統(tǒng)的靈活性,延長嵌入式系統(tǒng)的壽命;同時,由于嵌入式Linux的應用日益廣泛
    發(fā)表于 08-06 06:39

    Linux內核教程

    本章學習目標掌握LINUX內核版本的含義理解并掌握進程的概念掌握管道的概念及實現了解內核的數據結構了解LINUX內核的算法掌握
    發(fā)表于 04-10 16:59 ?0次下載

    Linux內核配置系統(tǒng)詳解

    隨著 Linux 操作系統(tǒng)的廣泛應用,特別是 Linux 在嵌入式領域的發(fā)展,越來越多的人開始投身到 Linux 內核級的開發(fā)中。面對日益龐大的 L
    發(fā)表于 11-01 15:45 ?4次下載

    如何配置和使用Linux內核printk功能

    了解如何配置和使用Linux內核printk功能,包括其動態(tài)調試功能。 這樣可以選擇性地打印調試消息,而無需重新編譯內核。
    的頭像 發(fā)表于 11-27 06:40 ?3147次閱讀

    linux內核是什么_linux內核學習路線

    Linux內核是一個操作系統(tǒng)(OS)內核,本質上定義為類Unix。它用于不同的操作系統(tǒng),主要是以不同的Linux發(fā)行版的形式。Linux
    發(fā)表于 09-16 15:49 ?2679次閱讀

    linux內核參數設置_linux內核的功能有哪些

    本文主要闡述了linux內核參數設置及linux內核的功能。
    發(fā)表于 09-17 14:40 ?1407次閱讀
    <b class='flag-5'>linux</b><b class='flag-5'>內核</b>參數設置_<b class='flag-5'>linux</b><b class='flag-5'>內核</b>的功能有哪些

    最硬核的Linux內核文章

    來源 :頭條號@Linux學習教程,冰凌塊兒 01 前言 本文主要講解什么是Linux內核,以及通過多張圖片展示Linux內核的作用與功能,
    的頭像 發(fā)表于 10-19 17:46 ?2173次閱讀
    最硬核的<b class='flag-5'>Linux</b><b class='flag-5'>內核</b>文章

    快速理解什么是Linux內核以及Linux內核的內容

    01 前言 本文主要講解什么是Linux內核,以及通過多張圖片展示Linux內核的作用與功能,以便于讀者能快速理解什么是Linux
    的頭像 發(fā)表于 10-21 12:02 ?4348次閱讀
    快速理解什么是<b class='flag-5'>Linux</b><b class='flag-5'>內核</b>以及<b class='flag-5'>Linux</b><b class='flag-5'>內核</b>的內容

    使用動態(tài)輸出打印內核的DEBUG信息

    printk()是很多嵌入式開發(fā)者喜歡用的調試手段之一,但是,使用printk()每次都要重新編譯內核,很不方便。使用動態(tài)輸出在不需要重新編譯內核的情況下,方便的打印出
    的頭像 發(fā)表于 01-06 10:46 ?954次閱讀

    Linux內核動態(tài)輸出調試

    動態(tài)輸出可以動態(tài)選擇打開某個內核子系統(tǒng)的輸出,可以有選擇性地打開某些模塊的輸出。 配置
    的頭像 發(fā)表于 09-27 15:45 ?589次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>內核</b><b class='flag-5'>動態(tài)</b><b class='flag-5'>輸出</b>調試

    linux驅動程序如何加載進內核

    ,需要了解Linux內核的基本概念和API。以下是一些關鍵概念: 1.1 內核模塊:Linux內核模塊是一種
    的頭像 發(fā)表于 08-30 15:02 ?607次閱讀