Lines 62-71
Link Here
|
62 |
|
62 |
|
63 |
#include "kgdb.h" |
63 |
#include "kgdb.h" |
64 |
|
64 |
|
65 |
static int dumpnr; |
|
|
66 |
static int verbose; |
65 |
static int verbose; |
67 |
|
66 |
|
68 |
static char crashdir[PATH_MAX]; |
67 |
static char crashdir[PATH_MAX]; |
|
|
68 |
static char *dumpnr; |
69 |
static char *kernel; |
69 |
static char *kernel; |
70 |
static char *remote; |
70 |
static char *remote; |
71 |
static char *vmcore; |
71 |
static char *vmcore; |
Lines 96-102
Link Here
|
96 |
} |
96 |
} |
97 |
|
97 |
|
98 |
static void |
98 |
static void |
99 |
kernel_from_dumpnr(int nr) |
99 |
kernel_from_dumpnr(const char *nr) |
100 |
{ |
100 |
{ |
101 |
char line[PATH_MAX], path[PATH_MAX]; |
101 |
char line[PATH_MAX], path[PATH_MAX]; |
102 |
FILE *info; |
102 |
FILE *info; |
Lines 110-116
Link Here
|
110 |
* subdirectory kernel.<nr> and called kernel. The latter allows us |
110 |
* subdirectory kernel.<nr> and called kernel. The latter allows us |
111 |
* to collect the modules in the same place. |
111 |
* to collect the modules in the same place. |
112 |
*/ |
112 |
*/ |
113 |
snprintf(path, sizeof(path), "%s/kernel.%d", crashdir, nr); |
113 |
snprintf(path, sizeof(path), "%s/kernel.%s", crashdir, nr); |
114 |
if (stat(path, &st) == 0) { |
114 |
if (stat(path, &st) == 0) { |
115 |
if (S_ISREG(st.st_mode)) { |
115 |
if (S_ISREG(st.st_mode)) { |
116 |
kernel = strdup(path); |
116 |
kernel = strdup(path); |
Lines 117-123
Link Here
|
117 |
return; |
117 |
return; |
118 |
} |
118 |
} |
119 |
if (S_ISDIR(st.st_mode)) { |
119 |
if (S_ISDIR(st.st_mode)) { |
120 |
snprintf(path, sizeof(path), "%s/kernel.%d/kernel", |
120 |
snprintf(path, sizeof(path), "%s/kernel.%s/kernel", |
121 |
crashdir, nr); |
121 |
crashdir, nr); |
122 |
if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { |
122 |
if (stat(path, &st) == 0 && S_ISREG(st.st_mode)) { |
123 |
kernel = strdup(path); |
123 |
kernel = strdup(path); |
Lines 133-139
Link Here
|
133 |
* with debugging info (called either kernel.full or kernel.debug). |
133 |
* with debugging info (called either kernel.full or kernel.debug). |
134 |
* If we have a debug kernel, use it. |
134 |
* If we have a debug kernel, use it. |
135 |
*/ |
135 |
*/ |
136 |
snprintf(path, sizeof(path), "%s/info.%d", crashdir, nr); |
136 |
snprintf(path, sizeof(path), "%s/info.%s", crashdir, nr); |
137 |
info = fopen(path, "r"); |
137 |
info = fopen(path, "r"); |
138 |
if (info == NULL) { |
138 |
if (info == NULL) { |
139 |
warn("%s", path); |
139 |
warn("%s", path); |
Lines 223-229
Link Here
|
223 |
char *s; |
223 |
char *s; |
224 |
int a, ch; |
224 |
int a, ch; |
225 |
|
225 |
|
226 |
dumpnr = -1; |
226 |
dumpnr = NULL; |
227 |
|
227 |
|
228 |
strlcpy(crashdir, "/var/crash", sizeof(crashdir)); |
228 |
strlcpy(crashdir, "/var/crash", sizeof(crashdir)); |
229 |
s = getenv("KGDB_CRASH_DIR"); |
229 |
s = getenv("KGDB_CRASH_DIR"); |
Lines 284-296
Link Here
|
284 |
annotation_level = 1; |
284 |
annotation_level = 1; |
285 |
break; |
285 |
break; |
286 |
case 'n': /* use dump with given number. */ |
286 |
case 'n': /* use dump with given number. */ |
287 |
dumpnr = strtol(optarg, &s, 0); |
287 |
dumpnr = optarg; |
288 |
if (dumpnr < 0 || *s != '\0') { |
|
|
289 |
warnx("option %c: invalid kernel dump number", |
290 |
optopt); |
291 |
usage(); |
292 |
/* NOTREACHED */ |
293 |
} |
294 |
break; |
288 |
break; |
295 |
case 'q': |
289 |
case 'q': |
296 |
kgdb_quiet = 1; |
290 |
kgdb_quiet = 1; |
Lines 317-323
Link Here
|
317 |
} |
311 |
} |
318 |
} |
312 |
} |
319 |
|
313 |
|
320 |
if (((vmcore != NULL) ? 1 : 0) + ((dumpnr >= 0) ? 1 : 0) + |
314 |
if (((vmcore != NULL) ? 1 : 0) + ((dumpnr != NULL) ? 1 : 0) + |
321 |
((remote != NULL) ? 1 : 0) > 1) { |
315 |
((remote != NULL) ? 1 : 0) > 1) { |
322 |
warnx("options -c, -n and -r are mutually exclusive"); |
316 |
warnx("options -c, -n and -r are mutually exclusive"); |
323 |
usage(); |
317 |
usage(); |
Lines 330-342
Link Here
|
330 |
if (argc > optind) |
324 |
if (argc > optind) |
331 |
kernel = strdup(argv[optind++]); |
325 |
kernel = strdup(argv[optind++]); |
332 |
|
326 |
|
333 |
if (argc > optind && (dumpnr >= 0 || remote != NULL)) { |
327 |
if (argc > optind && (dumpnr != NULL || remote != NULL)) { |
334 |
warnx("options -n and -r do not take a core file. Ignored"); |
328 |
warnx("options -n and -r do not take a core file. Ignored"); |
335 |
optind = argc; |
329 |
optind = argc; |
336 |
} |
330 |
} |
337 |
|
331 |
|
338 |
if (dumpnr >= 0) { |
332 |
if (dumpnr != NULL) { |
339 |
snprintf(path, sizeof(path), "%s/vmcore.%d", crashdir, dumpnr); |
333 |
snprintf(path, sizeof(path), "%s/vmcore.%s", crashdir, dumpnr); |
340 |
if (stat(path, &st) == -1) |
334 |
if (stat(path, &st) == -1) |
341 |
err(1, "%s", path); |
335 |
err(1, "%s", path); |
342 |
if (!S_ISREG(st.st_mode)) |
336 |
if (!S_ISREG(st.st_mode)) |
Lines 372-378
Link Here
|
372 |
|
366 |
|
373 |
/* If we don't have a kernel image yet, try to find one. */ |
367 |
/* If we don't have a kernel image yet, try to find one. */ |
374 |
if (kernel == NULL) { |
368 |
if (kernel == NULL) { |
375 |
if (dumpnr >= 0) |
369 |
if (dumpnr != NULL) |
376 |
kernel_from_dumpnr(dumpnr); |
370 |
kernel_from_dumpnr(dumpnr); |
377 |
|
371 |
|
378 |
if (kernel == NULL) |
372 |
if (kernel == NULL) |