3 #include <sys/utsname.h>
12 int print_symbol_address(struct file_addr * fa)
21 sprintf(cmd, "modprobe -l %s", fa->modname);
22 file = popen(cmd, "r");
24 printf("failed to execute %s:%s\n."
25 "Have you installed modules?\n",
26 cmd, strerror(errno));
30 if (fgets(buffer, 4095, file) == NULL) {
31 printf("failed to get modprobe ouput for %s:%s\n",
32 fa->modname, strerror(errno));
38 sprintf(cmd, "nm -n %s", buffer);
39 file = popen(cmd, "r");
41 printf("failed to execute %s:%s\n."
42 "Have you installed modules?\n",
43 cmd, strerror(errno));
47 while (fgets(buffer, 4095, file)) {
48 if (fscanf(file, "%x %s %s\n", &addr, mode, func_name) != 3)
51 /* only list symbol in text section. */
52 if (strcasecmp(mode, "t") == 0) {
53 /* skip __init functoin. How to filter others? */
54 if (strcmp(func_name, "init_module") != 0)
55 printf("%x %s %s\n", fa->base + addr,
64 int generate_symbol_file()
66 static char* cmd = "lctl modules";
71 memset(&gfa, 0, sizeof(gfa));
72 file = popen(cmd, "r");
74 printf("failed to execute %s: %s\n", cmd, strerror(errno));
78 while ( fscanf(file, "%s %s %lx\n", other, gfa.path, &gfa.base) == 3) {
79 strncpy(gfa.modname, strrchr(gfa.path, '/') + 1,
80 strrchr(gfa.path, '.') - strrchr(gfa.path, '/') - 1);
82 //fprintf(stderr, "%s %s %#x\n", gfa.path, gfa.modname, gfa.base);
84 /* continue going without checking result */
85 print_symbol_address(&gfa);
86 memset(&gfa, 0, sizeof(gfa));
95 return generate_symbol_file();