It occurred to me that we can easily save binary image too,
even if it is deleted - by opening and reading /proc/PID/exe!
This later can be hooked to gdb to get backtrace more reliably.
Here's the patch. Run tested. Please ACK.
--
vda
diff -x '*.po' -d -urpN abrt.0/inc/CrashTypes.h abrt.1/inc/CrashTypes.h
--- abrt.0/inc/CrashTypes.h 2010-05-28 18:55:39.000000000 +0200
+++ abrt.1/inc/CrashTypes.h 2010-06-01 19:26:22.129761826 +0200
@@ -25,6 +25,7 @@
// filled by a hook:
#define FILENAME_ANALYZER "analyzer"
#define FILENAME_EXECUTABLE "executable"
+#define FILENAME_BINARY "binary"
#define FILENAME_CMDLINE "cmdline"
#define FILENAME_REASON "reason"
#define FILENAME_COREDUMP "coredump"
diff -x '*.po' -d -urpN abrt.0/src/Hooks/abrt-hook-ccpp.cpp
abrt.1/src/Hooks/abrt-hook-ccpp.cpp
--- abrt.0/src/Hooks/abrt-hook-ccpp.cpp 2010-05-28 18:55:39.000000000 +0200
+++ abrt.1/src/Hooks/abrt-hook-ccpp.cpp 2010-06-01 19:32:47.427011677 +0200
@@ -132,11 +132,12 @@ static off_t copyfd_sparse(int src_fd, i
return total;
}
-static char* get_executable(pid_t pid)
+static char* get_executable(pid_t pid, int *fd_p)
{
char buf[sizeof("/proc/%lu/exe") + sizeof(long)*3];
sprintf(buf, "/proc/%lu/exe", (long)pid);
+ *fd_p = open(buf, O_RDONLY); /* might fail and return -1, it's ok */
return malloc_readlink(buf);
}
@@ -262,7 +263,8 @@ int main(int argc, char** argv)
error_msg_and_die("pid '%s' or limit '%s' is bogus",
argv[2], argv[5]);
}
- char* executable = get_executable(pid);
+ int src_fd_binary;
+ char* executable = get_executable(pid, &src_fd_binary);
if (executable == NULL)
{
error_msg_and_die("can't read /proc/%lu/exe link", (long)pid);
@@ -391,6 +393,20 @@ int main(int argc, char** argv)
free(cmdline);
free(reason);
+ if (src_fd_binary > 0)
+ {
+ strcpy(path + path_len, "/"FILENAME_BINARY);
+ int dst_fd_binary = xopen3(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ off_t sz = copyfd_eof(src_fd_binary, dst_fd_binary, COPYFD_SPARSE);
+ if (sz < 0 || fsync(dst_fd_binary) != 0)
+ {
+ unlink(path);
+ error_msg_and_die("error saving binary image to %s", path);
+ }
+ close(dst_fd_binary);
+ close(src_fd_binary);
+ }
+
/* We need coredumps to be readable by all, because
* when abrt daemon processes coredump,
* process producing backtrace is run under the same UID
Show replies by date
On Tue, 01 Jun 2010 19:42:37 +0200, Denys Vlasenko wrote:
It occurred to me that we can easily save binary image too,
even if it is deleted - by opening and reading /proc/PID/exe!
Good idea (before GDB PR corefiles/11579 gets hopefully fixed).
Regards,
Jan
On Tue, 2010-06-01 at 19:42 +0200, Denys Vlasenko wrote:
It occurred to me that we can easily save binary image too,
even if it is deleted - by opening and reading /proc/PID/exe!
This later can be hooked to gdb to get backtrace more reliably.
Here's the patch. Run tested. Please ACK.
Updated patch: made dumping of binary optional, controlled by
CCpp.conf directive SaveBinaryImage = yes/no
--
vda
On 06/07/2010 12:07 PM, Denys Vlasenko wrote:
On Tue, 2010-06-01 at 19:42 +0200, Denys Vlasenko wrote:
> It occurred to me that we can easily save binary image too,
> even if it is deleted - by opening and reading /proc/PID/exe!
>
> This later can be hooked to gdb to get backtrace more reliably.
>
> Here's the patch. Run tested. Please ACK.
Updated patch: made dumping of binary optional, controlled by
CCpp.conf directive SaveBinaryImage = yes/no
Apply patch.