aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2015-04-17 09:47:30 +0100
committerGary Benson <gbenson@redhat.com>2015-04-17 09:47:30 +0100
commita10de6046fbd50e99742af428a815dcd94e2fba8 (patch)
tree86cf6669c963b4a71d35b3f92591698e7ade8ee0
parent92209ddfdc725c51d0368716ee316193deb24e8a (diff)
downloadgdb-a10de6046fbd50e99742af428a815dcd94e2fba8.zip
gdb-a10de6046fbd50e99742af428a815dcd94e2fba8.tar.gz
gdb-a10de6046fbd50e99742af428a815dcd94e2fba8.tar.bz2
Introduce exec_file_locate_attach
This commit adds a new function, exec_file_locate_attach, which works like exec_file_attach except that, instead of a filename argument, it takes an integer process ID and attempts to determine the executable filename from that. gdb/ChangeLog: * gdbcore.h (exec_file_locate_attach): New declaration. * exec.c (exec_file_locate_attach): New function, factored out from... * infcmd.c (attach_command_post_wait): ...here.
-rw-r--r--gdb/ChangeLog7
-rw-r--r--gdb/exec.c31
-rw-r--r--gdb/gdbcore.h7
-rw-r--r--gdb/infcmd.c25
4 files changed, 47 insertions, 23 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 20b5bf1..0de7554 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2015-04-17 Gary Benson <gbenson@redhat.com>
+
+ * gdbcore.h (exec_file_locate_attach): New declaration.
+ * exec.c (exec_file_locate_attach): New function, factored
+ out from...
+ * infcmd.c (attach_command_post_wait): ...here.
+
2015-04-17 Mike Frysinger <vapier@gentoo.org>
* MAINTAINERS: Add myself for Blackfin/write-after-approval.
diff --git a/gdb/exec.c b/gdb/exec.c
index 44c8480..9d4ad90 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -134,6 +134,37 @@ exec_file_clear (int from_tty)
printf_unfiltered (_("No executable file now.\n"));
}
+/* See gdbcore.h. */
+
+void
+exec_file_locate_attach (int pid, int from_tty)
+{
+ char *exec_file, *full_exec_path = NULL;
+
+ /* Do nothing if we already have an executable filename. */
+ exec_file = (char *) get_exec_file (0);
+ if (exec_file != NULL)
+ return;
+
+ /* Try to determine a filename from the process itself. */
+ exec_file = target_pid_to_exec_file (pid);
+ if (exec_file == NULL)
+ return;
+
+ /* It's possible we don't have a full path, but rather just a
+ filename. Some targets, such as HP-UX, don't provide the
+ full path, sigh.
+
+ Attempt to qualify the filename against the source path.
+ (If that fails, we'll just fall back on the original
+ filename. Not much more we can do...) */
+ if (!source_full_path_of (exec_file, &full_exec_path))
+ full_exec_path = xstrdup (exec_file);
+
+ exec_file_attach (full_exec_path, from_tty);
+ symbol_file_add_main (full_exec_path, from_tty);
+}
+
/* Set FILENAME as the new exec file.
This function is intended to be behave essentially the same
diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h
index 63a75f0..a437c8a 100644
--- a/gdb/gdbcore.h
+++ b/gdb/gdbcore.h
@@ -150,6 +150,13 @@ extern void core_file_command (char *filename, int from_tty);
extern void exec_file_attach (const char *filename, int from_tty);
+/* If the filename of the main executable is unknown, attempt to
+ determine it. If a filename is determined, proceed as though
+ it was just specified with the "file" command. Do nothing if
+ the filename of the main executable is already known. */
+
+extern void exec_file_locate_attach (int pid, int from_tty);
+
extern void exec_file_clear (int from_tty);
extern void validate_files (void);
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 6caa878..7e2484b 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2462,8 +2462,6 @@ proceed_after_attach (int pid)
static void
attach_command_post_wait (char *args, int from_tty, int async_exec)
{
- char *exec_file;
- char *full_exec_path = NULL;
struct inferior *inferior;
inferior = current_inferior ();
@@ -2471,27 +2469,8 @@ attach_command_post_wait (char *args, int from_tty, int async_exec)
/* If no exec file is yet known, try to determine it from the
process itself. */
- exec_file = (char *) get_exec_file (0);
- if (!exec_file)
- {
- exec_file = target_pid_to_exec_file (ptid_get_pid (inferior_ptid));
- if (exec_file)
- {
- /* It's possible we don't have a full path, but rather just a
- filename. Some targets, such as HP-UX, don't provide the
- full path, sigh.
-
- Attempt to qualify the filename against the source path.
- (If that fails, we'll just fall back on the original
- filename. Not much more we can do...) */
-
- if (!source_full_path_of (exec_file, &full_exec_path))
- full_exec_path = xstrdup (exec_file);
-
- exec_file_attach (full_exec_path, from_tty);
- symbol_file_add_main (full_exec_path, from_tty);
- }
- }
+ if (get_exec_file (0) == NULL)
+ exec_file_locate_attach (ptid_get_pid (inferior_ptid), from_tty);
else
{
reopen_exec_file ();