xref: /OK3568_Linux_fs/kernel/samples/kdb/kdb_hello.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Created by: Jason Wessel <jason.wessel@windriver.com>
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (c) 2010 Wind River Systems, Inc.  All Rights Reserved.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This file is licensed under the terms of the GNU General Public
7*4882a593Smuzhiyun  * License version 2. This program is licensed "as is" without any
8*4882a593Smuzhiyun  * warranty of any kind, whether express or implied.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/module.h>
12*4882a593Smuzhiyun #include <linux/kdb.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /*
15*4882a593Smuzhiyun  * All kdb shell command call backs receive argc and argv, where
16*4882a593Smuzhiyun  * argv[0] is the command the end user typed
17*4882a593Smuzhiyun  */
kdb_hello_cmd(int argc,const char ** argv)18*4882a593Smuzhiyun static int kdb_hello_cmd(int argc, const char **argv)
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun 	if (argc > 1)
21*4882a593Smuzhiyun 		return KDB_ARGCOUNT;
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 	if (argc)
24*4882a593Smuzhiyun 		kdb_printf("Hello %s.\n", argv[1]);
25*4882a593Smuzhiyun 	else
26*4882a593Smuzhiyun 		kdb_printf("Hello world!\n");
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	return 0;
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun 
kdb_hello_cmd_init(void)32*4882a593Smuzhiyun static int __init kdb_hello_cmd_init(void)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	/*
35*4882a593Smuzhiyun 	 * Registration of a dynamically added kdb command is done with
36*4882a593Smuzhiyun 	 * kdb_register() with the arguments being:
37*4882a593Smuzhiyun 	 *   1: The name of the shell command
38*4882a593Smuzhiyun 	 *   2: The function that processes the command
39*4882a593Smuzhiyun 	 *   3: Description of the usage of any arguments
40*4882a593Smuzhiyun 	 *   4: Descriptive text when you run help
41*4882a593Smuzhiyun 	 *   5: Number of characters to complete the command
42*4882a593Smuzhiyun 	 *      0 == type the whole command
43*4882a593Smuzhiyun 	 *      1 == match both "g" and "go" for example
44*4882a593Smuzhiyun 	 */
45*4882a593Smuzhiyun 	kdb_register("hello", kdb_hello_cmd, "[string]",
46*4882a593Smuzhiyun 		     "Say Hello World or Hello [string]", 0);
47*4882a593Smuzhiyun 	return 0;
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun 
kdb_hello_cmd_exit(void)50*4882a593Smuzhiyun static void __exit kdb_hello_cmd_exit(void)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun 	kdb_unregister("hello");
53*4882a593Smuzhiyun }
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun module_init(kdb_hello_cmd_init);
56*4882a593Smuzhiyun module_exit(kdb_hello_cmd_exit);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun MODULE_AUTHOR("WindRiver");
59*4882a593Smuzhiyun MODULE_DESCRIPTION("KDB example to add a hello command");
60*4882a593Smuzhiyun MODULE_LICENSE("GPL");
61