Commit:     42e380832a6911c8a3173ee0172fbc0e4864d80b
Parent:     de34ed91c4ffa4727964a832c46e624dd1495cf5
Author:     Robert Peterson <[EMAIL PROTECTED]>
AuthorDate: Mon Apr 30 15:09:48 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Mon Apr 30 16:40:39 2007 -0700

    Extend print_symbol capability
    Today's print_symbol function dumps a kernel symbol with printk.  This
    patch extends the functionality of kallsyms.c so that the symbol lookup
    function may be used without the printk.  This is useful for modules that
    want to dump symbols elsewhere, for example, to debugfs.  I intend to use
    the new function call in the GFS2 file system (which will be a separate
    [EMAIL PROTECTED]: build fix]
    [EMAIL PROTECTED]: sprint_symbol should return length of string like 
    Signed-off-by: Robert Peterson <[EMAIL PROTECTED]>
    Cc: Rusty Russell <[EMAIL PROTECTED]>
    Cc: Roman Zippel <[EMAIL PROTECTED]>
    Cc: "Randy.Dunlap" <[EMAIL PROTECTED]>
    Cc: Sam Ravnborg <[EMAIL PROTECTED]>
    Acked-by: Paulo Marques <[EMAIL PROTECTED]>
    Signed-off-by: Christoph Lameter <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
 include/linux/kallsyms.h |   13 ++++++++++++-
 kernel/kallsyms.c        |   23 +++++++++++++++--------
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
index 1cebcbc..3e3b92d 100644
--- a/include/linux/kallsyms.h
+++ b/include/linux/kallsyms.h
@@ -7,6 +7,8 @@
 #define KSYM_NAME_LEN 127
+#define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN + \
+                        2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1)
 /* Lookup the address for a symbol. Returns 0 if not found. */
@@ -22,7 +24,10 @@ const char *kallsyms_lookup(unsigned long addr,
                            unsigned long *offset,
                            char **modname, char *namebuf);
-/* Replace "%s" in format with address, if found */
+/* Look up a kernel symbol and return it in a text buffer. */
+extern int sprint_symbol(char *buffer, unsigned long address);
+/* Look up a kernel symbol and print it to the kernel messages. */
 extern void __print_symbol(const char *fmt, unsigned long address);
 #else /* !CONFIG_KALLSYMS */
@@ -47,6 +52,12 @@ static inline const char *kallsyms_lookup(unsigned long addr,
        return NULL;
+static inline int sprint_symbol(char *buffer, unsigned long addr)
+       *buffer = '\0';
+       return 0;
 /* Stupid that this does nothing, but I didn't create this mess. */
 #define __print_symbol(fmt, addr)
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 6f294ff..5a0de84 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -267,27 +267,33 @@ const char *kallsyms_lookup(unsigned long addr,
        return NULL;
-/* Replace "%s" in format with address, or returns -errno. */
-void __print_symbol(const char *fmt, unsigned long address)
+/* Look up a kernel symbol and return it in a text buffer. */
+int sprint_symbol(char *buffer, unsigned long address)
        char *modname;
        const char *name;
        unsigned long offset, size;
        char namebuf[KSYM_NAME_LEN+1];
-       char buffer[sizeof("%s+%#lx/%#lx [%s]") + KSYM_NAME_LEN +
-                   2*(BITS_PER_LONG*3/10) + MODULE_NAME_LEN + 1];
        name = kallsyms_lookup(address, &size, &offset, &modname, namebuf);
        if (!name)
-               sprintf(buffer, "0x%lx", address);
+               return sprintf(buffer, "0x%lx", address);
        else {
                if (modname)
-                       sprintf(buffer, "%s+%#lx/%#lx [%s]", name, offset,
+                       return sprintf(buffer, "%s+%#lx/%#lx [%s]", name, 
                                size, modname);
-                       sprintf(buffer, "%s+%#lx/%#lx", name, offset, size);
+                       return sprintf(buffer, "%s+%#lx/%#lx", name, offset, 
+/* Look up a kernel symbol and print it to the kernel messages. */
+void __print_symbol(const char *fmt, unsigned long address)
+       char buffer[KSYM_SYMBOL_LEN];
+       sprint_symbol(buffer, address);
        printk(fmt, buffer);
@@ -452,3 +458,4 @@ static int __init kallsyms_init(void)
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to