+static struct mod_paths {
+ char *name, *path;
+} mod_paths[] = {
+ { .name = "libcfs", .path = "libcfs/libcfs" },
+ { .name = "lnet", .path = "lnet/lnet" },
+ { .name = "ko2iblnd", .path = "lnet/klnds/o2iblnd" },
+ { .name = "kgnilnd", .path = "lnet/klnds/gnilnd"},
+ { .name = "ksocklnd", .path = "lnet/klnds/socklnd" },
+ { .name = "obdclass", .path = "lustre/obdclass" },
+ { .name = "llog_test", .path = "lustre/obdclass" },
+ { .name = "ptlrpc_gss", .path = "lustre/ptlrpc/gss" },
+ { .name = "ptlrpc", .path = "lustre/ptlrpc" },
+ { .name = "gks", .path = "lustre/sec/gks" },
+ { .name = "gkc", .path = "lustre/sec/gks" },
+ { .name = "ost", .path = "lustre/ost" },
+ { .name = "osc", .path = "lustre/osc" },
+ { .name = "mds", .path = "lustre/mds" },
+ { .name = "mdc", .path = "lustre/mdc" },
+ { .name = "lustre", .path = "lustre/llite" },
+ { .name = "ldiskfs", .path = "ldiskfs" },
+ { .name = "obdecho", .path = "lustre/obdecho" },
+ { .name = "ldlm", .path = "lustre/ldlm" },
+ { .name = "obdfilter", .path = "lustre/obdfilter" },
+ { .name = "lov", .path = "lustre/lov" },
+ { .name = "lmv", .path = "lustre/lmv" },
+ { .name = "lquota", .path = "lustre/quota" },
+ { .name = "mgs", .path = "lustre/mgs" },
+ { .name = "mgc", .path = "lustre/mgc" },
+ { .name = "mdt", .path = "lustre/mdt" },
+ { .name = "mdd", .path = "lustre/mdd" },
+ { .name = "osd", .path = "lustre/osd" },
+ { .name = "cmm", .path = "lustre/cmm" },
+ { .name = "fid", .path = "lustre/fid"},
+ { .name = "fld", .path = "lustre/fld"},
+ { .name = "lod", .path = "lustre/lod"},
+ { .name = "osp", .path = "lustre/osp"},
+ { .name = "lfsck", .path = "lustre/lfsck" },
+ { .name = NULL }
+};
+
+int jt_dbg_modules(int argc, char **argv)
+{
+ struct mod_paths *mp;
+ char *path = "";
+ const char *proc = "/proc/modules";
+ char modname[128];
+ char buf[4096];
+ unsigned long modaddr;
+ FILE *file;
+
+ if (argc >= 2)
+ path = argv[1];
+ if (argc > 3) {
+ printf("%s [path] [kernel]\n", argv[0]);
+ return 0;
+ }
+
+ file = fopen(proc, "r");
+ if (!file) {
+ printf("failed open %s: %s\n", proc, strerror(errno));
+ return 0;
+ }
+
+ while (fgets(buf, sizeof(buf), file) != NULL) {
+ if (sscanf(buf, "%s %*s %*s %*s %*s %lx",
+ modname, &modaddr) == 2) {
+ for (mp = mod_paths; mp->name != NULL; mp++) {
+ if (!strcmp(mp->name, modname))
+ break;
+ }
+ if (mp->name) {
+ printf("add-symbol-file %s%s%s/%s.o 0x%0lx\n",
+ path, path[0] ? "/" : "",
+ mp->path, mp->name, modaddr);
+ }
+ }
+ }
+
+ fclose(file);
+ return 0;