On Sat, Jun 13, 2020 at 09:57:37AM -0600, Jim Cromie wrote:
> put pr_debug()s into most functions, to easily see code operate when
> module is loaded and used.
> 
>   #> dmesg -w &
>   #> modprobe kset-example dyndbg=+pfml
>   #> cat /sys/kernel/kset-example/*/*
> ---
>  samples/kobject/kset-example.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
> index c8010f126808..27c9b1beec28 100644
> --- a/samples/kobject/kset-example.c
> +++ b/samples/kobject/kset-example.c
> @@ -56,6 +56,7 @@ static ssize_t foo_attr_show(struct kobject *kobj,
>       struct foo_attribute *attribute;
>       struct foo_obj *foo;
>  
> +     pr_debug("called");
>       attribute = to_foo_attr(attr);
>       foo = to_foo_obj(kobj);
>  
> @@ -76,6 +77,7 @@ static ssize_t foo_attr_store(struct kobject *kobj,
>       struct foo_attribute *attribute;
>       struct foo_obj *foo;
>  
> +     pr_debug("called");
>       attribute = to_foo_attr(attr);
>       foo = to_foo_obj(kobj);
>  
> @@ -102,6 +104,7 @@ static void foo_release(struct kobject *kobj)
>  {
>       struct foo_obj *foo;
>  
> +     pr_debug("called");
>       foo = to_foo_obj(kobj);
>       kfree(foo);
>  }
> @@ -112,6 +115,7 @@ static void foo_release(struct kobject *kobj)
>  static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
>                       char *buf)
>  {
> +     pr_debug("called");
>       return sprintf(buf, "%d\n", foo_obj->foo);
>  }
>  
> @@ -120,6 +124,7 @@ static ssize_t foo_store(struct foo_obj *foo_obj, struct 
> foo_attribute *attr,
>  {
>       int ret;
>  
> +     pr_debug("called");
>       ret = kstrtoint(buf, 10, &foo_obj->foo);
>       if (ret < 0)
>               return ret;
> @@ -140,6 +145,7 @@ static ssize_t b_show(struct foo_obj *foo_obj, struct 
> foo_attribute *attr,
>  {
>       int var;
>  
> +     pr_debug("called");
>       if (strcmp(attr->attr.name, "baz") == 0)
>               var = foo_obj->baz;
>       else
> @@ -152,6 +158,7 @@ static ssize_t b_store(struct foo_obj *foo_obj, struct 
> foo_attribute *attr,
>  {
>       int var, ret;
>  
> +     pr_debug("called");
>       ret = kstrtoint(buf, 10, &var);
>       if (ret < 0)
>               return ret;
> @@ -201,6 +208,7 @@ static struct foo_obj *create_foo_obj(const char *name)
>       struct foo_obj *foo;
>       int retval;
>  
> +     pr_debug("called");
>       /* allocate the memory for the whole object */
>       foo = kzalloc(sizeof(*foo), GFP_KERNEL);
>       if (!foo)
> @@ -235,11 +243,13 @@ static struct foo_obj *create_foo_obj(const char *name)
>  
>  static void destroy_foo_obj(struct foo_obj *foo)
>  {
> +     pr_debug("called");
>       kobject_put(&foo->kobj);
>  }
>  
>  static int __init example_init(void)
>  {
> +     pr_debug("called");

Why???  If you want to do something like this, use ftrace, that is what
it is for.

thanks,

greg k-h

Reply via email to