簡體   English   中英

對c有點生銹,如何打印此結構的有用信息?

[英]A bit rusty on c, how do I print useful information of this structure?

所以我試圖調試別人寫的linux模塊,這是一段時間了,因為我用c / c ++編寫了任何東西

我在這里收到一個錯誤(此問題與該錯誤間接相關):

video_register_device(usbMightex->vdev, VFL_TYPE_GRABBER, video_nr)

所以我想嘗試找出usbMightex->vdev是什么。

這是它的結構:

http://www.linuxtv.org/downloads/legacy/video4linux/v4l2dwgNew.html

結構video_device

char name[32]                              :Canonical name for this device.
int type                                   :Type of V4L2 device
(use type2 as well, look at videodev2.h for details on type2)
int minor                                  :The device's minor number
struct file_operations *fops;              :File operations used, which are displayed below
void (*release)(struct video_device *vfd); :Release function used by the driver to release
void *priv:                                :Can be used by the driver

我已經有一個pr_err語句,該語句用於打印信息,但不確定如何使用它。 不知道在哪里定義。 我想我對簡單的printf語句或類似的命令會很滿意,因此我可以使用dmesg提取輸出

謝謝。

更新

評論者要求提供有關該錯誤的更多信息:

我在這里對這個問題發布了另一個不同的問題:

https://askubuntu.com/questions/565700/how-do-i-load-a-module-that-has-no-signature-in-ubuntu-12-04

這個問題與錯誤無關,僅與如何打印一些可能對解決錯誤有用的信息有關。 感謝您的答復。

最明顯的答案是,使用調試器,然后在要查看變量的位置放置一個斷點。

要在代碼中打印出來,請假設您的鏈接頁面是正確的(您應通過檢查頭文件來驗證這一點,否則可能會產生廢話):

printf("%31s\n", v->name);
printf("%d\n", v->type);
printf("%d\n", v->minor);
printf("%p\n", (void *)v->fops);
printf(PRIxMAX "\n", (uintmax_t)v->release);
printf("%p\n", priv);

其中v是指向結構實例的指針。

如果將其編譯為內核模塊(* .ko),則可能需要多次插入和刪除它,而無需重新啟動

lsmodmodprobeinsmod

您可能會發現有用的printk()函數,它們會輸出到syslog中,並進入dmesg IIRC

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM