linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Print symbolic address of kernel and modules without extra data
@ 2002-03-18 21:43 Cort Dougan
  0 siblings, 0 replies; only message in thread
From: Cort Dougan @ 2002-03-18 21:43 UTC (permalink / raw)
  To: linux-kernel

I just added this to the PPC debugger and the strongARM panic code when I
realized that I'm going to have to add this to MIPS, too.  Rather than
that, I'll send it here with the hope that someone finds it useful.

Consider this my contribution at the kernel-debugger and other dangerous
technologies altar.

Given an address, it prints out the symbolic name for it by digging
through the module symbol table rather than stuffing gobs of system.map
data into the kernel image.  It'll only pick up on EXPORT_SYMBOL() symbols
but it's a lot better than having to figure out what has happened in a
module that I've loaded on an embedded board with now r/w filesystem.

#if defined(CONFIG_MODULES)
#include <linux/module.h>

static void lookup_print_addr(unsigned long addr)
{
	extern unsigned long *_end;
	unsigned long best_match = 0; /* so far */
	char best_match_string[60] = {0, }; /* so far */
#if defined(CONFIG_MODULES)
	struct module *mod;
	struct module_symbol *sym;
	int j;
#endif

	/* user addresses - just print user and return -- Cort */
	if ( addr < PAGE_OFFSET )
	{
		printk("(user)");
		return;
	}

	for (mod = module_list; mod; mod = mod->next)
	{
		for ( j = 0, sym = mod->syms; j < mod->nsyms; ++j, ++sym)
		{
			/* is this a better match than what we've
			 * found so far? -- Cort */
			if ( (sym->value < addr) &&
			     ((addr - sym->value) < (addr - best_match)) )
			{
				best_match = sym->value;
				/* kernelmodule.name is "" so we
				 * have a special case -- Cort */
				if ( mod->name[0] == 0 )
					sprintf(best_match_string, "%s",
						sym->name);
				else
					sprintf(best_match_string, "%s:%s",
						sym->name, mod->name);
			}
		}
	}

	if ( best_match )
		printk("(%s + 0x%x)", best_match_string, addr - best_match);
	else
		printk("(???)");
}
#endif /* CONFIG_MODULES */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-03-18 21:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-18 21:43 Print symbolic address of kernel and modules without extra data Cort Dougan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).