| OLD | NEW |
| 1 /* Copyright (c) 2008, Google Inc. | 1 /* Copyright (c) 2008, Google Inc. |
| 2 * All rights reserved. | 2 * All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 #include <stdio.h> | 42 #include <stdio.h> |
| 43 #include <stdlib.h> | 43 #include <stdlib.h> |
| 44 | 44 |
| 45 #include <windows.h> | 45 #include <windows.h> |
| 46 #include <dbghelp.h> | 46 #include <dbghelp.h> |
| 47 | 47 |
| 48 #define SEARCH_CAP (1024*1024) | 48 #define SEARCH_CAP (1024*1024) |
| 49 #define WEBSYM "SRV*c:\\websymbols*http://msdl.microsoft.com/download/symbols" | 49 #define WEBSYM "SRV*c:\\websymbols*http://msdl.microsoft.com/download/symbols" |
| 50 | 50 |
| 51 void usage() { |
| 52 fprintf(stderr, "usage: " |
| 53 "addr2line-pdb [-f|--functions] [-C|--demangle] [-e filename]\n"); |
| 54 fprintf(stderr, "(Then list the hex addresses on stdin, one per line)\n"); |
| 55 } |
| 56 |
| 51 int main(int argc, char *argv[]) { | 57 int main(int argc, char *argv[]) { |
| 52 DWORD error; | 58 DWORD error; |
| 53 HANDLE process; | 59 HANDLE process; |
| 54 ULONG64 module_base; | 60 ULONG64 module_base; |
| 55 int i; | 61 int i; |
| 56 char* search; | 62 char* search; |
| 57 char buf[256]; /* Enough to hold one hex address, I trust! */ | 63 char buf[256]; /* Enough to hold one hex address, I trust! */ |
| 58 int rv = 0; | 64 int rv = 0; |
| 59 /* We may add SYMOPT_UNDNAME if --demangle is specified: */ | 65 /* We may add SYMOPT_UNDNAME if --demangle is specified: */ |
| 60 DWORD symopts = SYMOPT_DEFERRED_LOADS | SYMOPT_DEBUG | SYMOPT_LOAD_LINES; | 66 DWORD symopts = SYMOPT_DEFERRED_LOADS | SYMOPT_DEBUG | SYMOPT_LOAD_LINES; |
| 61 char* filename = "a.out"; /* The default if -e isn't specified */ | 67 char* filename = "a.out"; /* The default if -e isn't specified */ |
| 62 int print_function_name = 0; /* Set to 1 if -f is specified */ | 68 int print_function_name = 0; /* Set to 1 if -f is specified */ |
| 63 | 69 |
| 64 for (i = 1; i < argc; i++) { | 70 for (i = 1; i < argc; i++) { |
| 65 if (strcmp(argv[i], "--functions") == 0 || strcmp(argv[i], "-f") == 0) { | 71 if (strcmp(argv[i], "--functions") == 0 || strcmp(argv[i], "-f") == 0) { |
| 66 print_function_name = 1; | 72 print_function_name = 1; |
| 67 } else if (strcmp(argv[i], "--demangle") == 0 || | 73 } else if (strcmp(argv[i], "--demangle") == 0 || |
| 68 strcmp(argv[i], "-C") == 0) { | 74 strcmp(argv[i], "-C") == 0) { |
| 69 symopts |= SYMOPT_UNDNAME; | 75 symopts |= SYMOPT_UNDNAME; |
| 70 } else if (strcmp(argv[i], "-e") == 0) { | 76 } else if (strcmp(argv[i], "-e") == 0) { |
| 71 if (i + 1 >= argc) { | 77 if (i + 1 >= argc) { |
| 72 fprintf(stderr, "FATAL ERROR: -e must be followed by a filename\n"); | 78 fprintf(stderr, "FATAL ERROR: -e must be followed by a filename\n"); |
| 73 return 1; | 79 return 1; |
| 74 } | 80 } |
| 75 filename = argv[i+1]; | 81 filename = argv[i+1]; |
| 76 i++; /* to skip over filename too */ | 82 i++; /* to skip over filename too */ |
| 83 } else if (strcmp(argv[i], "--help") == 0) { |
| 84 usage(); |
| 85 exit(0); |
| 77 } else { | 86 } else { |
| 78 fprintf(stderr, "usage: " | 87 usage(); |
| 79 "addr2line-pdb [-f|--functions] [-C|--demangle] [-e filename]\n"); | |
| 80 fprintf(stderr, "(Then list the hex addresses on stdin, one per line)\n"); | |
| 81 exit(1); | 88 exit(1); |
| 82 } | 89 } |
| 83 } | 90 } |
| 84 | 91 |
| 85 process = GetCurrentProcess(); | 92 process = GetCurrentProcess(); |
| 86 | 93 |
| 87 if (!SymInitialize(process, NULL, FALSE)) { | 94 if (!SymInitialize(process, NULL, FALSE)) { |
| 88 error = GetLastError(); | 95 error = GetLastError(); |
| 89 fprintf(stderr, "SymInitialize returned error : %d\n", error); | 96 fprintf(stderr, "SymInitialize returned error : %d\n", error); |
| 90 return 1; | 97 return 1; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 if (SymGetLineFromAddr64(process, (DWORD64)addr, &dummy, &line)) { | 154 if (SymGetLineFromAddr64(process, (DWORD64)addr, &dummy, &line)) { |
| 148 printf("%s:%d\n", line.FileName, (int)line.LineNumber); | 155 printf("%s:%d\n", line.FileName, (int)line.LineNumber); |
| 149 } else { | 156 } else { |
| 150 printf("??:0\n"); | 157 printf("??:0\n"); |
| 151 } | 158 } |
| 152 } | 159 } |
| 153 SymUnloadModule64(process, module_base); | 160 SymUnloadModule64(process, module_base); |
| 154 SymCleanup(process); | 161 SymCleanup(process); |
| 155 return rv; | 162 return rv; |
| 156 } | 163 } |
| OLD | NEW |