From: Tom Rini <trini@kernel.crashing.org>
To: Andrew Morton <akpm@osdl.org>
Cc: Tom Rini <trini@kernel.crashing.org>,
lkml <linux-kernel@vger.kernel.org>
Subject: [PATCH,RFC 2.6.14 15/15] KGDB: Better support for loaded modules
Date: Thu, 10 Nov 2005 11:45:14 -0500 [thread overview]
Message-ID: <20051110164530.20950.84541.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20051110163906.20950.45704.sendpatchset@localhost.localdomain>
This allows for KGDB to better deal with autoloaded modules. The way this
works, requires a patch to GDB. This patch can be found at
ftp://source.mvista.com/pub/kgdb/gdb-6.3-kgdb-module-notification.patch
The way this works is that the solib-search-path must contain the location of
any module to be debugged, and then when a module is loaded GDB acts like a
shared library has been loaded now, and can be used that way.
include/linux/module.h | 16 ++++++++++++++
kernel/module.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
Index: linux-2.6.14/include/linux/module.h
===================================================================
--- linux-2.6.14.orig/include/linux/module.h
+++ linux-2.6.14/include/linux/module.h
@@ -210,8 +210,17 @@ enum module_state
MODULE_STATE_LIVE,
MODULE_STATE_COMING,
MODULE_STATE_GOING,
+ MODULE_STATE_GONE,
};
+#ifdef CONFIG_KGDB
+#define MAX_SECTNAME 31
+struct mod_section {
+ void *address;
+ char name[MAX_SECTNAME + 1];
+};
+#endif
+
/* Similar stuff for section attributes. */
#define MODULE_SECT_NAME_LEN 32
struct module_sect_attr
@@ -239,6 +248,13 @@ struct module
/* Unique handle for this module */
char name[MODULE_NAME_LEN];
+#ifdef CONFIG_KGDB
+ /* keep kgdb info at the begining so that gdb doesn't have a chance to
+ * miss out any fields */
+ unsigned long num_sections;
+ struct mod_section *mod_sections;
+#endif
+
/* Sysfs stuff. */
struct module_kobject mkobj;
struct module_param_attrs *param_attrs;
Index: linux-2.6.14/kernel/module.c
===================================================================
--- linux-2.6.14.orig/kernel/module.c
+++ linux-2.6.14/kernel/module.c
@@ -624,6 +624,12 @@ sys_delete_module(const char __user *nam
if (ret != 0)
goto out;
+ down(¬ify_mutex);
+ notifier_call_chain(&module_notify_list, MODULE_STATE_GOING,
+ mod);
+ up(¬ify_mutex);
+
+
/* Never wait if forced. */
if (!forced && module_refcount(mod) != 0)
wait_for_zero_refcount(mod);
@@ -636,6 +642,11 @@ sys_delete_module(const char __user *nam
}
free_module(mod);
+ down(¬ify_mutex);
+ notifier_call_chain(&module_notify_list, MODULE_STATE_GONE,
+ NULL);
+ up(¬ify_mutex);
+
out:
up(&module_mutex);
return ret;
@@ -1174,6 +1185,11 @@ static void free_module(struct module *m
/* Arch-specific cleanup. */
module_arch_cleanup(mod);
+#ifdef CONFIG_KGDB
+ /* kgdb info */
+ vfree(mod->mod_sections);
+#endif
+
/* Module unload stuff */
module_unload_free(mod);
@@ -1408,6 +1424,31 @@ static void setup_modinfo(struct module
}
#endif
+#ifdef CONFIG_KGDB
+int add_modsects (struct module *mod, Elf_Ehdr *hdr, Elf_Shdr *sechdrs, const
+ char *secstrings)
+{
+ int i;
+
+ mod->num_sections = hdr->e_shnum - 1;
+ mod->mod_sections = vmalloc((hdr->e_shnum - 1)*
+ sizeof (struct mod_section));
+
+ if (mod->mod_sections == NULL) {
+ return -ENOMEM;
+ }
+
+ for (i = 1; i < hdr->e_shnum; i++) {
+ mod->mod_sections[i - 1].address = (void *)sechdrs[i].sh_addr;
+ strncpy(mod->mod_sections[i - 1].name, secstrings +
+ sechdrs[i].sh_name, MAX_SECTNAME);
+ mod->mod_sections[i - 1].name[MAX_SECTNAME] = '\0';
+ }
+
+ return 0;
+}
+#endif
+
#ifdef CONFIG_KALLSYMS
int is_exported(const char *name, const struct module *mod)
{
@@ -1777,6 +1818,12 @@ static struct module *load_module(void _
add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
+#ifdef CONFIG_KGDB
+ if ((err = add_modsects(mod, hdr, sechdrs, secstrings)) < 0) {
+ goto nomodsectinfo;
+ }
+#endif
+
err = module_finalize(hdr, sechdrs, mod);
if (err < 0)
goto cleanup;
@@ -1842,6 +1889,11 @@ static struct module *load_module(void _
arch_cleanup:
module_arch_cleanup(mod);
cleanup:
+
+#ifdef CONFIG_KGDB
+nomodsectinfo:
+ vfree(mod->mod_sections);
+#endif
module_unload_free(mod);
module_free(mod, mod->module_init);
free_core:
@@ -1915,6 +1967,10 @@ sys_init_module(void __user *umod,
/* Init routine failed: abort. Try to protect us from
buggy refcounters. */
mod->state = MODULE_STATE_GOING;
+ down(¬ify_mutex);
+ notifier_call_chain(&module_notify_list, MODULE_STATE_GOING,
+ mod);
+ up(¬ify_mutex);
synchronize_sched();
if (mod->unsafe)
printk(KERN_ERR "%s: module is now stuck!\n",
--
Tom
prev parent reply other threads:[~2005-11-10 16:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-10 16:38 [PATCH,RFC 2.6.14 00/15] KGDB Support Tom Rini
2005-11-10 16:39 ` [PATCH,RFC 2.6.14 01/15] KGDB: core infrastructure Tom Rini
2005-11-10 16:39 ` [PATCH,RFC 2.6.14 03/15] KGDB: ppc32-specific changes Tom Rini
2005-11-10 16:39 ` [PATCH,RFC 2.6.14 02/15] KGDB: i386-specific changes Tom Rini
2005-11-10 16:40 ` [PATCH,RFC 2.6.14 04/15] KGDB: 8250-like UART driver Tom Rini
2005-11-10 16:41 ` [PATCH,RFC 2.6.14 06/15] KGDB: IA64-specific changes Tom Rini
2005-11-10 16:41 ` [PATCH,RFC 2.6.14 05/15] KGDB: MIPS-specific changes Tom Rini
2005-11-10 16:41 ` [PATCH,RFC 2.6.14 08/15] KGDB: x86_64-specific changes Tom Rini
2005-11-10 16:41 ` [PATCH,RFC 2.6.14 07/15] x86_64: Add a notifier hook to the "no context" part of do_page_fault Tom Rini
2005-11-10 16:42 ` [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes Tom Rini
2005-11-10 16:42 ` [PATCH,RFC 2.6.14 10/15] KGDB: ARM-specific changes Tom Rini
2005-11-10 16:43 ` [PATCH,RFC 2.6.14 11/15] KGDB: ppc64-specific changes Tom Rini
2005-11-11 0:55 ` Paul Mackerras
2005-11-11 1:13 ` Tom Rini
2005-11-10 16:44 ` [PATCH,RFC 2.6.14 13/15] KGDB: CFI annotations for better unwinding Tom Rini
2005-11-10 16:44 ` [PATCH,RFC 2.6.14 12/15] KGDB: netpoll-based ethernet driver Tom Rini
2005-11-10 16:45 ` [PATCH,RFC 2.6.14 14/15] KGDB: Fix for 'lost' SysRq events Tom Rini
2005-11-10 16:45 ` Tom Rini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051110164530.20950.84541.sendpatchset@localhost.localdomain \
--to=trini@kernel.crashing.org \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox