xref: /linux/samples/kdb/kdb_hello.c (revision 762f99f4f3cb41a775b5157dd761217beba65873)
14aad8f51SJason Wessel /*
24aad8f51SJason Wessel  * Created by: Jason Wessel <jason.wessel@windriver.com>
34aad8f51SJason Wessel  *
44aad8f51SJason Wessel  * Copyright (c) 2010 Wind River Systems, Inc.  All Rights Reserved.
54aad8f51SJason Wessel  *
64aad8f51SJason Wessel  * This file is licensed under the terms of the GNU General Public
74aad8f51SJason Wessel  * License version 2. This program is licensed "as is" without any
84aad8f51SJason Wessel  * warranty of any kind, whether express or implied.
94aad8f51SJason Wessel  */
104aad8f51SJason Wessel 
114aad8f51SJason Wessel #include <linux/module.h>
124aad8f51SJason Wessel #include <linux/kdb.h>
134aad8f51SJason Wessel 
144aad8f51SJason Wessel /*
154aad8f51SJason Wessel  * All kdb shell command call backs receive argc and argv, where
164aad8f51SJason Wessel  * argv[0] is the command the end user typed
174aad8f51SJason Wessel  */
kdb_hello_cmd(int argc,const char ** argv)184aad8f51SJason Wessel static int kdb_hello_cmd(int argc, const char **argv)
194aad8f51SJason Wessel {
204aad8f51SJason Wessel 	if (argc > 1)
214aad8f51SJason Wessel 		return KDB_ARGCOUNT;
224aad8f51SJason Wessel 
234aad8f51SJason Wessel 	if (argc)
244aad8f51SJason Wessel 		kdb_printf("Hello %s.\n", argv[1]);
254aad8f51SJason Wessel 	else
264aad8f51SJason Wessel 		kdb_printf("Hello world!\n");
274aad8f51SJason Wessel 
284aad8f51SJason Wessel 	return 0;
294aad8f51SJason Wessel }
304aad8f51SJason Wessel 
31c25abcd6SSumit Garg static kdbtab_t hello_cmd = {
32*e868f0a3SSumit Garg 	.name = "hello",
33*e868f0a3SSumit Garg 	.func = kdb_hello_cmd,
34*e868f0a3SSumit Garg 	.usage = "[string]",
35*e868f0a3SSumit Garg 	.help = "Say Hello World or Hello [string]",
36c25abcd6SSumit Garg };
374aad8f51SJason Wessel 
kdb_hello_cmd_init(void)384aad8f51SJason Wessel static int __init kdb_hello_cmd_init(void)
394aad8f51SJason Wessel {
404aad8f51SJason Wessel 	/*
414aad8f51SJason Wessel 	 * Registration of a dynamically added kdb command is done with
42c25abcd6SSumit Garg 	 * kdb_register().
434aad8f51SJason Wessel 	 */
44c25abcd6SSumit Garg 	kdb_register(&hello_cmd);
454aad8f51SJason Wessel 	return 0;
464aad8f51SJason Wessel }
474aad8f51SJason Wessel 
kdb_hello_cmd_exit(void)484aad8f51SJason Wessel static void __exit kdb_hello_cmd_exit(void)
494aad8f51SJason Wessel {
50c25abcd6SSumit Garg 	kdb_unregister(&hello_cmd);
514aad8f51SJason Wessel }
524aad8f51SJason Wessel 
534aad8f51SJason Wessel module_init(kdb_hello_cmd_init);
544aad8f51SJason Wessel module_exit(kdb_hello_cmd_exit);
554aad8f51SJason Wessel 
564aad8f51SJason Wessel MODULE_AUTHOR("WindRiver");
574aad8f51SJason Wessel MODULE_DESCRIPTION("KDB example to add a hello command");
584aad8f51SJason Wessel MODULE_LICENSE("GPL");
59