* breakpoint.c, breakpoint.h (breakpoint_init_inferior): New function
[deliverable/binutils-gdb.git] / gdb / exec.c
index eb6a85a12ce185e7c98829982c0ed443509aca4b..444c89ebec04c851f9ce9f2ffed3be68d91243da 100644 (file)
@@ -35,6 +35,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <ctype.h>
 #include <sys/stat.h>
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
 
 /* Prototypes for local functions */
 
@@ -80,7 +83,9 @@ exec_close (quitting)
      int quitting;
 {
   if (exec_bfd) {
+    char *name = bfd_get_filename (exec_bfd);
     bfd_close (exec_bfd);
+    free (name);
     exec_bfd = NULL;
   }
   if (exec_ops.to_sections) {
@@ -135,12 +140,12 @@ exec_file_command (args, from_tty)
       make_cleanup (free, filename);
       
       scratch_chan = openp (getenv ("PATH"), 1, filename, 
-                           write_files? O_RDWR: O_RDONLY, 0,
+                           write_files? O_RDWR|O_BINARY: O_RDONLY|O_BINARY, 0,
                            &scratch_pathname);
       if (scratch_chan < 0)
        perror_with_name (filename);
 
-      exec_bfd = bfd_fdopenr (scratch_pathname, NULL, scratch_chan);
+      exec_bfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
       if (!exec_bfd)
        error ("Could not open `%s' as an executable file: %s",
               scratch_pathname, bfd_errmsg (bfd_error));
@@ -159,7 +164,7 @@ exec_file_command (args, from_tty)
       {
        struct section_table *p;
        for (p = exec_ops.to_sections; p < exec_ops.to_sections_end; p++)
-         if (!strcmp (".text", bfd_section_name (p->bfd, p->sec_ptr)))
+         if (STREQ (".text", bfd_section_name (p->bfd, p->sec_ptr)))
            {
              text_start = p->addr;
              text_end   = p->endaddr;
@@ -233,8 +238,6 @@ build_section_table (some_bfd, start, end)
   unsigned count;
 
   count = bfd_count_sections (some_bfd);
-  if (count == 0)
-    abort();   /* return 1? */
   if (*start)
     free ((PTR)*start);
   *start = (struct section_table *) xmalloc (count * sizeof (**start));
@@ -328,7 +331,7 @@ xfer_memory (memaddr, myaddr, len, write, target)
        wanna_xfer = coredata;
       }
 #endif                         /* REG_STACK_SEGMENT */
-#endif FIXME
+#endif /* FIXME */
 \f
 void
 print_section_info (t, abfd)
@@ -340,7 +343,8 @@ print_section_info (t, abfd)
   printf_filtered ("\t`%s', ", bfd_get_filename(abfd));
   wrap_here ("        ");
   printf_filtered ("file type %s.\n", bfd_get_target(abfd));
-
+  printf_filtered ("\tEntry point: %s\n",
+                  local_hex_string (bfd_get_start_address (exec_bfd)));
   for (p = t->to_sections; p < t->to_sections_end; p++) {
     printf_filtered ("\t%s", local_hex_string_custom (p->addr, "08"));
     printf_filtered (" - %s", local_hex_string_custom (p->endaddr, "08"));
@@ -402,21 +406,34 @@ set_section_command (args, from_tty)
   error ("Section %s not found", secprint);
 }
 
+/* If mourn is being called in all the right places, this could be say
+   `gdb internal error' (since generic_mourn calls mark_breakpoints_out).  */
+
+static int
+ignore (addr, contents)
+     CORE_ADDR addr;
+     char *contents;
+{
+  return 0;
+}
+
 struct target_ops exec_ops = {
        "exec", "Local exec file",
        "Use an executable file as a target.\n\
 Specify the filename of the executable file.",
        exec_file_command, exec_close, /* open, close */
-       child_attach, 0, 0, 0, /* attach, detach, resume, wait, */
+       find_default_attach, 0, 0, 0, /* attach, detach, resume, wait, */
        0, 0, /* fetch_registers, store_registers, */
-       0, 0, 0, /* prepare_to_store, conv_to, conv_from, */
+       0, /* prepare_to_store, */
        xfer_memory, exec_files_info,
-       0, 0, /* insert_breakpoint, remove_breakpoint, */
+       ignore, ignore, /* insert_breakpoint, remove_breakpoint, */
        0, 0, 0, 0, 0, /* terminal stuff */
        0, 0, /* kill, load */
        0, /* lookup sym */
-       child_create_inferior,
+       find_default_create_inferior,
        0, /* mourn_inferior */
+       0, /* can_run */
+       0, /* notice_signals */
        file_stratum, 0, /* next */
        0, 1, 0, 0, 0,  /* all mem, mem, stack, regs, exec */
        0, 0,                   /* section pointers */
@@ -426,20 +443,23 @@ Specify the filename of the executable file.",
 void
 _initialize_exec()
 {
+  struct cmd_list_element *c;
 
-  add_com ("file", class_files, file_command,
-          "Use FILE as program to be debugged.\n\
+  c = add_cmd ("file", class_files, file_command,
+              "Use FILE as program to be debugged.\n\
 It is read for its symbols, for getting the contents of pure memory,\n\
 and it is the program executed when you use the `run' command.\n\
 If FILE cannot be found as specified, your execution directory path\n\
 ($PATH) is searched for a command of that name.\n\
-No arg means to have no executable file and no symbols.");
+No arg means to have no executable file and no symbols.", &cmdlist);
+  c->completer = filename_completer;
 
-  add_com ("exec-file", class_files, exec_file_command,
+  c = add_cmd ("exec-file", class_files, exec_file_command,
           "Use FILE as program for getting contents of pure memory.\n\
 If FILE cannot be found as specified, your execution directory path\n\
 is searched for a command of that name.\n\
-No arg means have no executable file.");
+No arg means have no executable file.", &cmdlist);
+  c->completer = filename_completer;
 
   add_com ("section", class_files, set_section_command,
    "Change the base address of section SECTION of the exec file to ADDR.\n\
This page took 0.02485 seconds and 4 git commands to generate.