mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Try to read 'core.PID' if can or fallback on 'core'.
This commit is contained in:
parent
b19a713bdf
commit
1cc61c1d29
@ -15,6 +15,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -125,7 +126,11 @@ static void collect_info_once(void) {
|
|||||||
TempFile tmp;
|
TempFile tmp;
|
||||||
tmp.set_auto_delete(true);
|
tmp.set_auto_delete(true);
|
||||||
|
|
||||||
if(gdb_output_generate(pdetails->path, tmp))
|
int pid = -1;
|
||||||
|
if(pdetails->pid)
|
||||||
|
pid = atoi(pdetails->pid);
|
||||||
|
|
||||||
|
if(gdb_output_generate(pdetails->path, tmp, pid))
|
||||||
txt_buf->appendfile(tmp.name());
|
txt_buf->appendfile(tmp.name());
|
||||||
|
|
||||||
info_was_collected = true;
|
info_was_collected = true;
|
||||||
|
@ -37,7 +37,7 @@ static int write_str(int fd, const char *str) {
|
|||||||
return ::write(fd, str, len);
|
return ::write(fd, str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gdb_output_generate(const char *path, TempFile &t) {
|
bool gdb_output_generate(const char *path, TempFile &t, int pid) {
|
||||||
E_RETURN_VAL_IF_FAIL(path != NULL, false);
|
E_RETURN_VAL_IF_FAIL(path != NULL, false);
|
||||||
|
|
||||||
int tfd = -1;
|
int tfd = -1;
|
||||||
@ -71,18 +71,41 @@ bool gdb_output_generate(const char *path, TempFile &t) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_test(CORE_FILE, FILE_TEST_IS_REGULAR)) {
|
/*
|
||||||
write_str(tfd, "Unable to find '"CORE_FILE"'. Backtrace will not be done.");
|
* to find core file, we will try these strategies: first try to open 'core.PID' if
|
||||||
|
* we got PID (default on linux); if does not exists, try to open 'core'; everything is
|
||||||
|
* assumed current folder, whatever it was set
|
||||||
|
*/
|
||||||
|
bool core_found = false;
|
||||||
|
String core_path;
|
||||||
|
if(pid > -1) {
|
||||||
|
core_path.printf("%s.%i", CORE_FILE, pid);
|
||||||
|
if(file_test(core_path.c_str(), FILE_TEST_IS_REGULAR))
|
||||||
|
core_found = true;
|
||||||
|
else
|
||||||
|
E_WARNING(E_STRLOC ": Unable to find %s. Trying 'core'\n", core_path.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!core_found) {
|
||||||
|
core_path = CORE_FILE;
|
||||||
|
if(file_test(core_path.c_str(), FILE_TEST_IS_REGULAR))
|
||||||
|
core_found = true;
|
||||||
|
else
|
||||||
|
E_WARNING(E_STRLOC ": Unable to find core. Balling out\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!core_found) {
|
||||||
|
write_str(tfd, "Unable to find core file. Backtrace will not be done.");
|
||||||
/* see it as valid, so dialog could be shown */
|
/* see it as valid, so dialog could be shown */
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t gdb_pid = fork();
|
||||||
|
|
||||||
if(pid == -1) {
|
if(gdb_pid == -1) {
|
||||||
E_WARNING(E_STRLOC ": Unable to fork the process\n");
|
E_WARNING(E_STRLOC ": Unable to fork the process\n");
|
||||||
return false;
|
return false;
|
||||||
} else if(pid == 0) {
|
} else if(gdb_pid == 0) {
|
||||||
/* child; redirect to the file */
|
/* child; redirect to the file */
|
||||||
dup2(tfd, 1);
|
dup2(tfd, 1);
|
||||||
t.close();
|
t.close();
|
||||||
@ -96,7 +119,7 @@ bool gdb_output_generate(const char *path, TempFile &t) {
|
|||||||
argv[3] = (char*)"-x";
|
argv[3] = (char*)"-x";
|
||||||
argv[4] = (char*)scr.name();
|
argv[4] = (char*)scr.name();
|
||||||
argv[5] = (char*)path;
|
argv[5] = (char*)path;
|
||||||
argv[6] = (char*)CORE_FILE;
|
argv[6] = (char*)core_path.c_str();
|
||||||
argv[7] = 0;
|
argv[7] = 0;
|
||||||
|
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
@ -104,12 +127,12 @@ bool gdb_output_generate(const char *path, TempFile &t) {
|
|||||||
} else {
|
} else {
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if(waitpid(pid, &status, 0) != pid) {
|
if(waitpid(gdb_pid, &status, 0) != gdb_pid) {
|
||||||
E_WARNING(E_STRLOC ": Failed to execute waitpid() properly\n");
|
E_WARNING(E_STRLOC ": Failed to execute waitpid() properly\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file_remove(CORE_FILE);
|
file_remove(core_path.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
#ifndef __GDBOUTPUT_H__
|
#ifndef __GDBOUTPUT_H__
|
||||||
#define __GDBOUTPUT_H__
|
#define __GDBOUTPUT_H__
|
||||||
|
|
||||||
bool gdb_output_generate(const char *path, edelib::TempFile &t);
|
bool gdb_output_generate(const char *path, edelib::TempFile &t, int pid = -1);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user