162
158
return g_quark_from_static_string ("gdb_buddy_error");
162
get_process_executable (int pid)
165
GError *error = NULL;
167
#if defined (__linux__)
168
link = g_strdup_printf ("/proc/%d/exe", pid);
169
#elif defined (sun) && defined (__SVR4)
170
link = g_strdup_printf ("/proc/%d/path/a.out", pid);
172
/* if someone knows how to do this on BSD, please send a patch */
175
exe = g_file_read_link (link, &error);
178
g_warning ("Could not read %s: %s\n", link, error->message);
179
g_error_free (error);
166
186
* @app: the executable name of the program that crashed
167
187
* @pid: the process id of the application that crashed
209
228
/* apply a SIGCONT to the process */
210
229
kill (pid, SIGCONT);
212
/* check for absolute or relative path */
213
if (app[0] == G_DIR_SEPARATOR) {
231
/* to get the application path do the following:
232
* - if the path is absolute, it has been provided by the user, so just use it.
233
* - otherwise look for it in /proc based on its pid.
234
* - if that fails, look for the program in path.
235
* - finally, use $libexecdir as fallback.
238
if (g_path_is_absolute (app)) {
214
239
long_app = g_strdup (app);
215
short_app = strrchr (app, G_DIR_SEPARATOR) + 1;
217
/* app is a relative path... get absolute path in long_app */
241
long_app = get_process_executable (pid);
218
245
long_app = g_find_program_in_path (app);
220
/* Applets are not in path... */
221
long_app = g_strconcat(GNOMELIBEXECDIR,"/", app, NULL);
247
/* this should never fail */
248
long_app = g_strconcat (GNOMELIBEXECDIR,"/", app, NULL);
227
g_set_error (err, GDB_BUDDY_ERROR, GDB_BUDDY_BINARY_NOT_FOUND,
228
_("The binary file could not be found. Try using an absolute path."));
232
252
args[0] = g_find_program_in_path ("gdb");