• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Linux Device Driver example for dump_stack() to print the stack trace of module loading

by admin

One of the useful options in debugging is to print the call trace/stack trace. Linux kernel provides a function to print the stack trace: dump_stack(). The dump_stack function produces a stack trace much like panic and oops, but causes no problems and we return to the normal control flow.

Calling dump_stack() function will print the stack trace at that point.

Code:

#include <linux/module.h>
#include <linux/kernel.h>

static int myinit(void)
{
	pr_info("dump_stack myinit\n");
	dump_stack();
	pr_info("dump_stack after\n");
	return 0;
}

static void myexit(void)
{
	pr_info("panic myexit\n");
}

module_init(myinit)
module_exit(myexit)
MODULE_LICENSE("GPL");

Output:

dump_stack() to print the stack trace of module loading

Filed Under: C, C Library

Some more articles you might also be interested in …

  1. C Pointers
  2. C Operators and Type Conversion
  3. C File Input Output
  4. Basics of C programming
  5. printk and console log level
  6. Introduction to Array in C Programming
  7. File Handling in C Programming
  8. Serial Port Programming – Reading/Writing Status of Control Lines: DTR/RTS/CTS/DSR
  9. C Looping Statements
  10. pthread_yield example in c

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright