Code cleanup: compile: func_addr -> func_sym
[deliverable/binutils-gdb.git] / gdb / compile / compile-object-run.c
1 /* Call module for 'compile' command.
2
3 Copyright (C) 2014-2015 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "compile-object-run.h"
22 #include "value.h"
23 #include "infcall.h"
24 #include "objfiles.h"
25 #include "compile-internal.h"
26 #include "dummy-frame.h"
27 #include "block.h"
28
29 /* Helper for do_module_cleanup. */
30
31 struct do_module_cleanup
32 {
33 /* Boolean to set true upon a call of do_module_cleanup.
34 The pointer may be NULL. */
35 int *executedp;
36
37 /* .c file OBJFILE was built from. It needs to be xfree-d. */
38 char *source_file;
39
40 /* Copy from struct compile_module. */
41 enum compile_i_scope_types scope;
42 void *scope_data;
43
44 /* objfile_name of our objfile. */
45 char objfile_name_string[1];
46 };
47
48 /* Cleanup everything after the inferior function dummy frame gets
49 discarded. */
50
51 static dummy_frame_dtor_ftype do_module_cleanup;
52 static void
53 do_module_cleanup (void *arg, int registers_valid)
54 {
55 struct do_module_cleanup *data = arg;
56 struct objfile *objfile;
57
58 if (data->executedp != NULL)
59 *data->executedp = 1;
60
61 ALL_OBJFILES (objfile)
62 if ((objfile->flags & OBJF_USERLOADED) == 0
63 && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0))
64 {
65 free_objfile (objfile);
66
67 /* It may be a bit too pervasive in this dummy_frame dtor callback. */
68 clear_symtab_users (0);
69
70 break;
71 }
72
73 /* Delete the .c file. */
74 unlink (data->source_file);
75 xfree (data->source_file);
76
77 /* Delete the .o file. */
78 unlink (data->objfile_name_string);
79 xfree (data);
80 }
81
82 /* Perform inferior call of MODULE. This function may throw an error.
83 This function may leave files referenced by MODULE on disk until
84 the inferior call dummy frame is discarded. This function may throw errors.
85 Thrown errors and left MODULE files are unrelated events. Caller must no
86 longer touch MODULE's memory after this function has been called. */
87
88 void
89 compile_object_run (struct compile_module *module)
90 {
91 struct value *func_val;
92 struct frame_id dummy_id;
93 struct cleanup *cleanups;
94 struct do_module_cleanup *data;
95 const char *objfile_name_s = objfile_name (module->objfile);
96 int dtor_found, executed = 0;
97 struct symbol *func_sym = module->func_sym;
98 CORE_ADDR regs_addr = module->regs_addr;
99 struct objfile *objfile = module->objfile;
100
101 data = xmalloc (sizeof (*data) + strlen (objfile_name_s));
102 data->executedp = &executed;
103 data->source_file = xstrdup (module->source_file);
104 strcpy (data->objfile_name_string, objfile_name_s);
105 data->scope = module->scope;
106 data->scope_data = module->scope_data;
107
108 xfree (module->source_file);
109 xfree (module);
110 module = NULL;
111
112 TRY
113 {
114 struct type *func_type = SYMBOL_TYPE (func_sym);
115 htab_t copied_types;
116 int current_arg = 0;
117 struct value **vargs;
118
119 /* OBJFILE may disappear while FUNC_TYPE still will be in use. */
120 copied_types = create_copied_types_hash (objfile);
121 func_type = copy_type_recursive (objfile, func_type, copied_types);
122 htab_delete (copied_types);
123
124 gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC);
125 func_val = value_from_pointer (lookup_pointer_type (func_type),
126 BLOCK_START (SYMBOL_BLOCK_VALUE (func_sym)));
127
128 vargs = alloca (sizeof (*vargs) * TYPE_NFIELDS (func_type));
129 if (TYPE_NFIELDS (func_type) >= 1)
130 {
131 gdb_assert (regs_addr != 0);
132 vargs[current_arg] = value_from_pointer
133 (TYPE_FIELD_TYPE (func_type, current_arg), regs_addr);
134 ++current_arg;
135 }
136 gdb_assert (current_arg == TYPE_NFIELDS (func_type));
137 call_function_by_hand_dummy (func_val, TYPE_NFIELDS (func_type), vargs,
138 do_module_cleanup, data);
139 }
140 CATCH (ex, RETURN_MASK_ERROR)
141 {
142 /* In the case of DTOR_FOUND or in the case of EXECUTED nothing
143 needs to be done. */
144 dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
145 if (!executed)
146 data->executedp = NULL;
147 gdb_assert (!(dtor_found && executed));
148 if (!dtor_found && !executed)
149 do_module_cleanup (data, 0);
150 throw_exception (ex);
151 }
152 END_CATCH
153
154 dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
155 gdb_assert (!dtor_found && executed);
156 }
This page took 0.037589 seconds and 5 git commands to generate.