compile: Use -Wall, not -w
[deliverable/binutils-gdb.git] / gdb / compile / compile-object-run.c
CommitLineData
bb2ec1b3
TT
1/* Call module for 'compile' command.
2
32d0add0 3 Copyright (C) 2014-2015 Free Software Foundation, Inc.
bb2ec1b3
TT
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
28/* Helper for do_module_cleanup. */
29
30struct do_module_cleanup
31{
32 /* Boolean to set true upon a call of do_module_cleanup.
33 The pointer may be NULL. */
34 int *executedp;
35
36 /* .c file OBJFILE was built from. It needs to be xfree-d. */
37 char *source_file;
38
5c65b58a
JK
39 /* Copy from struct compile_module. */
40 enum compile_i_scope_types scope;
41 void *scope_data;
42
bb2ec1b3
TT
43 /* objfile_name of our objfile. */
44 char objfile_name_string[1];
45};
46
47/* Cleanup everything after the inferior function dummy frame gets
48 discarded. */
49
50static dummy_frame_dtor_ftype do_module_cleanup;
51static void
5e970501 52do_module_cleanup (void *arg, int registers_valid)
bb2ec1b3
TT
53{
54 struct do_module_cleanup *data = arg;
55 struct objfile *objfile;
56
57 if (data->executedp != NULL)
58 *data->executedp = 1;
59
60 ALL_OBJFILES (objfile)
61 if ((objfile->flags & OBJF_USERLOADED) == 0
62 && (strcmp (objfile_name (objfile), data->objfile_name_string) == 0))
63 {
64 free_objfile (objfile);
65
66 /* It may be a bit too pervasive in this dummy_frame dtor callback. */
67 clear_symtab_users (0);
68
69 break;
70 }
71
72 /* Delete the .c file. */
73 unlink (data->source_file);
74 xfree (data->source_file);
75
76 /* Delete the .o file. */
77 unlink (data->objfile_name_string);
78 xfree (data);
79}
80
81/* Perform inferior call of MODULE. This function may throw an error.
82 This function may leave files referenced by MODULE on disk until
83 the inferior call dummy frame is discarded. This function may throw errors.
84 Thrown errors and left MODULE files are unrelated events. Caller must no
85 longer touch MODULE's memory after this function has been called. */
86
87void
88compile_object_run (struct compile_module *module)
89{
90 struct value *func_val;
91 struct frame_id dummy_id;
92 struct cleanup *cleanups;
93 struct do_module_cleanup *data;
bb2ec1b3
TT
94 const char *objfile_name_s = objfile_name (module->objfile);
95 int dtor_found, executed = 0;
96 CORE_ADDR func_addr = module->func_addr;
97 CORE_ADDR regs_addr = module->regs_addr;
98
99 data = xmalloc (sizeof (*data) + strlen (objfile_name_s));
100 data->executedp = &executed;
101 data->source_file = xstrdup (module->source_file);
102 strcpy (data->objfile_name_string, objfile_name_s);
5c65b58a
JK
103 data->scope = module->scope;
104 data->scope_data = module->scope_data;
bb2ec1b3
TT
105
106 xfree (module->source_file);
107 xfree (module);
108
492d29ea 109 TRY
bb2ec1b3
TT
110 {
111 func_val = value_from_pointer
112 (builtin_type (target_gdbarch ())->builtin_func_ptr,
113 func_addr);
114
115 if (regs_addr == 0)
116 call_function_by_hand_dummy (func_val, 0, NULL,
117 do_module_cleanup, data);
118 else
119 {
120 struct value *arg_val;
121
122 arg_val = value_from_pointer
123 (builtin_type (target_gdbarch ())->builtin_func_ptr,
124 regs_addr);
125 call_function_by_hand_dummy (func_val, 1, &arg_val,
126 do_module_cleanup, data);
127 }
128 }
492d29ea 129 CATCH (ex, RETURN_MASK_ERROR)
bb2ec1b3 130 {
7556d4a4 131 /* In the case of DTOR_FOUND or in the case of EXECUTED nothing
bb2ec1b3 132 needs to be done. */
7556d4a4
PA
133 dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
134 if (!executed)
135 data->executedp = NULL;
bb2ec1b3
TT
136 gdb_assert (!(dtor_found && executed));
137 if (!dtor_found && !executed)
5e970501 138 do_module_cleanup (data, 0);
bb2ec1b3
TT
139 throw_exception (ex);
140 }
492d29ea 141 END_CATCH
7556d4a4
PA
142
143 dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
144 gdb_assert (!dtor_found && executed);
bb2ec1b3 145}
This page took 0.060466 seconds and 4 git commands to generate.