1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
39 #include <sys/utsname.h>
48 int print_symbol_address(struct file_addr * fa)
57 sprintf(cmd, "modprobe -l %s", fa->modname);
58 file = popen(cmd, "r");
60 printf("failed to execute %s:%s\n."
61 "Have you installed modules?\n",
62 cmd, strerror(errno));
66 if (fgets(buffer, 4095, file) == NULL) {
67 printf("failed to get modprobe ouput for %s:%s\n",
68 fa->modname, strerror(errno));
74 sprintf(cmd, "nm -n %s", buffer);
75 file = popen(cmd, "r");
77 printf("failed to execute %s:%s\n."
78 "Have you installed modules?\n",
79 cmd, strerror(errno));
83 while (fgets(buffer, 4095, file)) {
84 if (fscanf(file, "%x %s %s\n", &addr, mode, func_name) != 3)
87 /* only list symbol in text section. */
88 if (strcasecmp(mode, "t") == 0) {
89 /* skip __init functoin. How to filter others? */
90 if (strcmp(func_name, "init_module") != 0)
91 printf("%x %s %s\n", fa->base + addr,
100 int generate_symbol_file()
102 static char* cmd = "lctl modules";
105 struct file_addr gfa;
107 memset(&gfa, 0, sizeof(gfa));
108 file = popen(cmd, "r");
110 printf("failed to execute %s: %s\n", cmd, strerror(errno));
114 while ( fscanf(file, "%s %s %lx\n", other, gfa.path, &gfa.base) == 3) {
115 strncpy(gfa.modname, strrchr(gfa.path, '/') + 1,
116 strrchr(gfa.path, '.') - strrchr(gfa.path, '/') - 1);
118 //fprintf(stderr, "%s %s %#x\n", gfa.path, gfa.modname, gfa.base);
120 /* continue going without checking result */
121 print_symbol_address(&gfa);
122 memset(&gfa, 0, sizeof(gfa));
131 return generate_symbol_file();