gdb/compile/compile-object-run.c - gdb

Global variables defined

Data types defined

Functions defined

Source code

  1. /* Call module for 'compile' command.

  2.    Copyright (C) 2014-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "compile-object-run.h"
  16. #include "value.h"
  17. #include "infcall.h"
  18. #include "objfiles.h"
  19. #include "compile-internal.h"
  20. #include "dummy-frame.h"

  21. /* Helper for do_module_cleanup.  */

  22. struct do_module_cleanup
  23. {
  24.   /* Boolean to set true upon a call of do_module_cleanup.
  25.      The pointer may be NULL.  */
  26.   int *executedp;

  27.   /* .c file OBJFILE was built from.  It needs to be xfree-d.  */
  28.   char *source_file;

  29.   /* objfile_name of our objfile.  */
  30.   char objfile_name_string[1];
  31. };

  32. /* Cleanup everything after the inferior function dummy frame gets
  33.    discarded.  */

  34. static dummy_frame_dtor_ftype do_module_cleanup;
  35. static void
  36. do_module_cleanup (void *arg)
  37. {
  38.   struct do_module_cleanup *data = arg;
  39.   struct objfile *objfile;

  40.   if (data->executedp != NULL)
  41.     *data->executedp = 1;

  42.   ALL_OBJFILES (objfile)
  43.     if ((objfile->flags & OBJF_USERLOADED) == 0
  44.         && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0))
  45.       {
  46.         free_objfile (objfile);

  47.         /* It may be a bit too pervasive in this dummy_frame dtor callback.  */
  48.         clear_symtab_users (0);

  49.         break;
  50.       }

  51.   /* Delete the .c file.  */
  52.   unlink (data->source_file);
  53.   xfree (data->source_file);

  54.   /* Delete the .o file.  */
  55.   unlink (data->objfile_name_string);
  56.   xfree (data);
  57. }

  58. /* Perform inferior call of MODULE.  This function may throw an error.
  59.    This function may leave files referenced by MODULE on disk until
  60.    the inferior call dummy frame is discarded.  This function may throw errors.
  61.    Thrown errors and left MODULE files are unrelated events.  Caller must no
  62.    longer touch MODULE's memory after this function has been called.  */

  63. void
  64. compile_object_run (struct compile_module *module)
  65. {
  66.   struct value *func_val;
  67.   struct frame_id dummy_id;
  68.   struct cleanup *cleanups;
  69.   struct do_module_cleanup *data;
  70.   volatile struct gdb_exception ex;
  71.   const char *objfile_name_s = objfile_name (module->objfile);
  72.   int dtor_found, executed = 0;
  73.   CORE_ADDR func_addr = module->func_addr;
  74.   CORE_ADDR regs_addr = module->regs_addr;

  75.   data = xmalloc (sizeof (*data) + strlen (objfile_name_s));
  76.   data->executedp = &executed;
  77.   data->source_file = xstrdup (module->source_file);
  78.   strcpy (data->objfile_name_string, objfile_name_s);

  79.   xfree (module->source_file);
  80.   xfree (module);

  81.   TRY_CATCH (ex, RETURN_MASK_ERROR)
  82.     {
  83.       func_val = value_from_pointer
  84.                  (builtin_type (target_gdbarch ())->builtin_func_ptr,
  85.                   func_addr);

  86.       if (regs_addr == 0)
  87.         call_function_by_hand_dummy (func_val, 0, NULL,
  88.                                      do_module_cleanup, data);
  89.       else
  90.         {
  91.           struct value *arg_val;

  92.           arg_val = value_from_pointer
  93.                     (builtin_type (target_gdbarch ())->builtin_func_ptr,
  94.                      regs_addr);
  95.           call_function_by_hand_dummy (func_val, 1, &arg_val,
  96.                                        do_module_cleanup, data);
  97.         }
  98.     }
  99.   dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
  100.   if (!executed)
  101.     data->executedp = NULL;
  102.   if (ex.reason >= 0)
  103.     gdb_assert (!dtor_found && executed);
  104.   else
  105.     {
  106.       /* In the case od DTOR_FOUND or in the case of EXECUTED nothing
  107.          needs to be done.  */
  108.       gdb_assert (!(dtor_found && executed));
  109.       if (!dtor_found && !executed)
  110.         do_module_cleanup (data);
  111.       throw_exception (ex);
  112.     }
  113. }