public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Cort Dougan <cort@fsmlabs.com>
To: linux-kernel@vger.kernel.org
Subject: Print symbolic address of kernel and modules without extra data
Date: Mon, 18 Mar 2002 14:43:32 -0700	[thread overview]
Message-ID: <20020318144332.F4783@host110.fsmlabs.com> (raw)

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 */

                 reply	other threads:[~2002-03-18 21:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20020318144332.F4783@host110.fsmlabs.com \
    --to=cort@fsmlabs.com \
    --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