bug-buddy r2725 - in trunk: . src
- From: cosimoc svn gnome org
- To: svn-commits-list gnome org
- Subject: bug-buddy r2725 - in trunk: . src
- Date: Thu, 25 Sep 2008 14:48:00 +0000 (UTC)
Author: cosimoc
Date: Thu Sep 25 14:48:00 2008
New Revision: 2725
URL: http://svn.gnome.org/viewvc/bug-buddy?rev=2725&view=rev
Log:
2008-09-25 Cosimo Cecchi <cosimoc gnome org>
* src/gdb-buddy.c: (get_process_executable), (gdb_get_trace):
Take the real path of the process from /proc, on supported platforms
(Linux and Solaris).
Thanks to Sam Morris and Matt Keenan (#172394).
Modified:
trunk/ChangeLog
trunk/src/gdb-buddy.c
Modified: trunk/src/gdb-buddy.c
==============================================================================
--- trunk/src/gdb-buddy.c (original)
+++ trunk/src/gdb-buddy.c Thu Sep 25 14:48:00 2008
@@ -33,10 +33,6 @@
#include "gdb-buddy.h"
-#if 0
-#include <libart_lgpl/libart.h>
-#endif
-
#define d(x)
typedef struct {
@@ -162,6 +158,30 @@
return g_quark_from_static_string ("gdb_buddy_error");
}
+static char *
+get_process_executable (int pid)
+{
+ char *link, *exe;
+ GError *error = NULL;
+
+#if defined (__linux__)
+ link = g_strdup_printf ("/proc/%d/exe", pid);
+#elif defined (sun) && defined (__SVR4)
+ link = g_strdup_printf ("/proc/%d/path/a.out", pid);
+#else
+ /* if someone knows how to do this on BSD, please send a patch */
+ return NULL;
+#endif
+ exe = g_file_read_link (link, &error);
+
+ if (error) {
+ g_warning ("Could not read %s: %s\n", link, error->message);
+ g_error_free (error);
+ }
+
+ return exe;
+}
+
/**
* @app: the executable name of the program that crashed
* @pid: the process id of the application that crashed
@@ -183,7 +203,6 @@
gdb_get_trace (const gchar *app, int pid, gpointer user_data, GdbCallback gdb_finish, GError **err)
{
char *s;
- const char *short_app;
char *long_app;
int gdb_pid;
int fd;
@@ -209,24 +228,25 @@
/* apply a SIGCONT to the process */
kill (pid, SIGCONT);
- /* check for absolute or relative path */
- if (app[0] == G_DIR_SEPARATOR) {
+ /* to get the application path do the following:
+ * - if the path is absolute, it has been provided by the user, so just use it.
+ * - otherwise look for it in /proc based on its pid.
+ * - if that fails, look for the program in path.
+ * - finally, use $libexecdir as fallback.
+ */
+
+ if (g_path_is_absolute (app)) {
long_app = g_strdup (app);
- short_app = strrchr (app, G_DIR_SEPARATOR) + 1;
} else {
- /* app is a relative path... get absolute path in long_app */
+ long_app = get_process_executable (pid);
+ }
+
+ if (!long_app) {
long_app = g_find_program_in_path (app);
if (!long_app) {
- /* Applets are not in path... */
- long_app = g_strconcat(GNOMELIBEXECDIR,"/", app, NULL);
+ /* this should never fail */
+ long_app = g_strconcat (GNOMELIBEXECDIR,"/", app, NULL);
}
- short_app = app;
- }
-
- if (!long_app) {
- g_set_error (err, GDB_BUDDY_ERROR, GDB_BUDDY_BINARY_NOT_FOUND,
- _("The binary file could not be found. Try using an absolute path."));
- return 0;
}
args[0] = g_find_program_in_path ("gdb");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]