简体   繁体   English

对c有点生锈,如何打印此结构的有用信息?

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

So I'm trying to debug a linux module someone else wrote and it's a while since I wrote anything in c/c++ 所以我试图调试别人写的linux模块,这是一段时间了,因为我用c / c ++编写了任何东西

I get an error here (this question is indirectly related to the error): 我在这里收到一个错误(此问题与该错误间接相关):

video_register_device(usbMightex->vdev, VFL_TYPE_GRABBER, video_nr)

so I wanted to try and find out what usbMightex->vdev is. 所以我想尝试找出usbMightex->vdev是什么。

This it's structure: 这是它的结构:

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

struct video_device 结构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

I already have a pr_err statement that is used to print information but not sure how to use it. 我已经有一个pr_err语句,该语句用于打印信息,但不确定如何使用它。 Not sure where it's defined. 不知道在哪里定义。 I think I'll be happy with a simple printf statement or smth similar so I can then pick up the output with dmesg 我想我对简单的printf语句或类似的命令会很满意,因此我可以使用dmesg提取输出

Thank you. 谢谢。

UPDATE 更新

A commenter asked for some more information with regards to the error: 评论者要求提供有关该错误的更多信息:

I have posted a different question about the problem generally here: 我在这里对这个问题发布了另一个不同的问题:

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

This question is NOT about the error, it was merely about how to print some information that would potentially be useful in solving the error. 这个问题与错误无关,仅与如何打印一些可能对解决错误有用的信息有关。 Thank you to all that responded. 感谢您的答复。

The most obvious answer is, use a debugger and put a breakpoint where you want to see the variables. 最明显的答案是,使用调试器,然后在要查看变量的位置放置一个断点。

To print out in code then, assuming your linked page is correct (you should verify this by checking the header file, otherwise nonsense output may ensue): 要在代码中打印出来,请假设您的链接页面是正确的(您应通过检查头文件来验证这一点,否则可能会产生废话):

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);

where v is the pointer to the instance of the structure. 其中v是指向结构实例的指针。

If it is compiled as kernel module (*.ko), you could probably insert and remove it multiple times without reboot 如果将其编译为内核模块(* .ko),则可能需要多次插入和删除它,而无需重新启动

lsmod , modprobe , insmod etc lsmodmodprobeinsmod

And you might find useful printk() functions, they output to syslog which goes into dmesg IIRC 您可能会发现有用的printk()函数,它们会输出到syslog中,并进入dmesg IIRC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM