• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Revisãobf4692711232eb96cd840f96d88897a2746d8190 (tree)
Hora2017-10-11 00:45:50
AutorPedro Alves <palves@redh...>
CommiterPedro Alves

Mensagem de Log

Eliminate catch_errors

If you want to use catch_errors with a function with parameters, then
currently you have to manually write a "capture" struct wrapping the
arguments and marshall/unmarshall that.

https://sourceware.org/ml/gdb-patches/2017-09/msg00834.html proposed
adjusting catch_errors to use gdb::function_view, which would allow
passing lambdas with automatic captures. However, it seems like using
TRY/CATCH directly instead ends up producing clearer and easier to
debug code. This is what this commit does.

Note that removing catch_errors exposes further cleanup opportunities
around no longer having to follow catch_errors callback type, and also
removes a few cleanups.

I didn't do anything to save/restore current_uiout because I think
that should be the responsibility of the code that changes
current_uiout in the first place.

(Another approach could be to make catch_errors a variadic template
like:

template<typename Function, typename... Args>
int catch_errors (const char *errstring, return_mask mask,

Function &&func, Args... args);

and then with:

extern void function_with_args (int, int);
extern void function_with_no_args ();

calls to the above functions would be wrapped like this:

catch_errors ("some error happened", RETURN_MASK_ERROR,
function_with_args, arg1, arg2);
catch_errors ("some error happened", RETURN_MASK_ERROR,
function_with_no_args);

but I'm thinking that that doesn't improve much if at all either.)

gdb/ChangeLog
2017-10-10 Pedro Alves <palves@redhat.com>
Tom Tromey <tom@tromey.com>

* breakpoint.c (breakpoint_cond_eval): Change return type to bool
and reverse logic.
(WP_DELETED, WP_VALUE_CHANGED, WP_VALUE_NOT_CHANGED, WP_IGNORE):
No longer macros. Instead ...
(enum wp_check_result): They're now values of this new
enumeration.
(watchpoint_check): Change return type to wp_check_result and
parameter type to bpstat.
(bpstat_check_watchpoint): Use TRY/CATCH instead of catch_errors.
(bpstat_check_breakpoint_conditions): Use TRY/CATCH instead of
catch_errors. Reverse logic of watchpoint_check call.
(breakpoint_re_set_one): Now returns void and takes a breakpoint
pointer as parameter.
(breakpoint_re_set): Use TRY/CATCH instead of catch_errors.
* common/common-exceptions.c (throw_exception_sjlj): Update
comments to avoid mentioning catch_errors.
* exceptions.c (catch_errors): Delete.
* exceptions.h: Update comments to avoid mentioning catch_errors.
(catch_errors_ftype, catch_errors): Delete.
* infrun.c (normal_stop): Use TRY/CATCH instead of catch_errors.
(hook_stop_stub): Delete.
(restore_selected_frame): Change return type to void, and
parameter type to const frame_id &.
(restore_infcall_control_state): Use TRY/CATCH instead of
catch_errors.
* main.c (captured_command_loop): Return void and remove
parameter. Remove references to catch_errors.
(captured_main): Use TRY/CATCH instead of catch_errors.
* objc-lang.c (objc_submethod_helper_data)
(find_objc_msgcall_submethod_helper): Delete.
(find_objc_msgcall_submethod): Use TRY/CATCH instead of
catch_errors.
* record-full.c (record_full_message): Return void.
(record_full_message_args, record_full_message_wrapper): Delete.
(record_full_message_wrapper_safe): Return bool and use TRY/CATCH
instead of catch_errors.
* solib-aix.c (solib_aix_open_symbol_file_object): Change
parameter type to int.
* solib-darwin.c (open_symbol_file_object): Ditto.
* solib-dsbt.c (open_symbol_file_object): Ditto.
* solib-frv.c (open_symbol_file_object): Ditto.
* solib-svr4.c (open_symbol_file_object): Ditto.
* solib-target.c (solib_target_open_symbol_file_object): Ditto.
* solib.c (update_solib_list): Use TRY/CATCH instead of
catch_errors.
* solist.h (struct target_so_ops) <open_symbol_file_object>:
Change type.
* symmisc.c (struct print_symbol_args): Remove.
(dump_symtab_1): Use TRY/CATCH instead of catch_errors.
(print_symbol): Change type.
* windows-nat.c (handle_load_dll, handle_unload_dll): Return void
and remove parameters.
(catch_errors): New.
(get_windows_debug_event): Adjust.

gdb/testsuite/ChangeLog:
2017-10-10 Pedro Alves <palves@redhat.com>

* lib/selftest-support.exp (selftest_setup): Update for
captured_command_loop's prototype change.

Mudança Sumário

Diff

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,61 @@
1+2017-10-10 Pedro Alves <palves@redhat.com>
2+ Tom Tromey <tom@tromey.com>
3+
4+ * breakpoint.c (breakpoint_cond_eval): Change return type to bool
5+ and reverse logic.
6+ (WP_DELETED, WP_VALUE_CHANGED, WP_VALUE_NOT_CHANGED, WP_IGNORE):
7+ No longer macros. Instead ...
8+ (enum wp_check_result): They're now values of this new
9+ enumeration.
10+ (watchpoint_check): Change return type to wp_check_result and
11+ parameter type to bpstat.
12+ (bpstat_check_watchpoint): Use TRY/CATCH instead of catch_errors.
13+ (bpstat_check_breakpoint_conditions): Use TRY/CATCH instead of
14+ catch_errors. Reverse logic of watchpoint_check call.
15+ (breakpoint_re_set_one): Now returns void and takes a breakpoint
16+ pointer as parameter.
17+ (breakpoint_re_set): Use TRY/CATCH instead of catch_errors.
18+ * common/common-exceptions.c (throw_exception_sjlj): Update
19+ comments to avoid mentioning catch_errors.
20+ * exceptions.c (catch_errors): Delete.
21+ * exceptions.h: Update comments to avoid mentioning catch_errors.
22+ (catch_errors_ftype, catch_errors): Delete.
23+ * infrun.c (normal_stop): Use TRY/CATCH instead of catch_errors.
24+ (hook_stop_stub): Delete.
25+ (restore_selected_frame): Change return type to void, and
26+ parameter type to const frame_id &.
27+ (restore_infcall_control_state): Use TRY/CATCH instead of
28+ catch_errors.
29+ * main.c (captured_command_loop): Return void and remove
30+ parameter. Remove references to catch_errors.
31+ (captured_main): Use TRY/CATCH instead of catch_errors.
32+ * objc-lang.c (objc_submethod_helper_data)
33+ (find_objc_msgcall_submethod_helper): Delete.
34+ (find_objc_msgcall_submethod): Use TRY/CATCH instead of
35+ catch_errors.
36+ * record-full.c (record_full_message): Return void.
37+ (record_full_message_args, record_full_message_wrapper): Delete.
38+ (record_full_message_wrapper_safe): Return bool and use TRY/CATCH
39+ instead of catch_errors.
40+ * solib-aix.c (solib_aix_open_symbol_file_object): Change
41+ parameter type to int.
42+ * solib-darwin.c (open_symbol_file_object): Ditto.
43+ * solib-dsbt.c (open_symbol_file_object): Ditto.
44+ * solib-frv.c (open_symbol_file_object): Ditto.
45+ * solib-svr4.c (open_symbol_file_object): Ditto.
46+ * solib-target.c (solib_target_open_symbol_file_object): Ditto.
47+ * solib.c (update_solib_list): Use TRY/CATCH instead of
48+ catch_errors.
49+ * solist.h (struct target_so_ops) <open_symbol_file_object>:
50+ Change type.
51+ * symmisc.c (struct print_symbol_args): Remove.
52+ (dump_symtab_1): Use TRY/CATCH instead of catch_errors.
53+ (print_symbol): Change type.
54+ * windows-nat.c (handle_load_dll, handle_unload_dll): Return void
55+ and remove parameters.
56+ (catch_errors): New.
57+ (get_windows_debug_event): Adjust.
58+
159 2017-10-09 Tom Tromey <tom@tromey.com>
260
361 * mi/mi-main.c (free_splay_tree): Remove.
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -103,8 +103,6 @@ static void map_breakpoint_numbers (const char *,
103103
104104 static void ignore_command (char *, int);
105105
106-static int breakpoint_re_set_one (void *);
107-
108106 static void breakpoint_re_set_default (struct breakpoint *);
109107
110108 static void
@@ -178,8 +176,6 @@ static void info_breakpoints_command (char *, int);
178176
179177 static void info_watchpoints_command (char *, int);
180178
181-static int breakpoint_cond_eval (void *);
182-
183179 static void cleanup_executing_breakpoints (void *);
184180
185181 static void commands_command (char *, int);
@@ -191,8 +187,6 @@ static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason);
191187
192188 static enum print_stop_action print_bp_stop_message (bpstat bs);
193189
194-static int watchpoint_check (void *);
195-
196190 static int hw_breakpoint_used_count (void);
197191
198192 static int hw_watchpoint_use_count (struct breakpoint *);
@@ -4842,21 +4836,16 @@ bpstat_print (bpstat bs, int kind)
48424836 return PRINT_UNKNOWN;
48434837 }
48444838
4845-/* Evaluate the expression EXP and return 1 if value is zero.
4846- This returns the inverse of the condition because it is called
4847- from catch_errors which returns 0 if an exception happened, and if an
4848- exception happens we want execution to stop.
4849- The argument is a "struct expression *" that has been cast to a
4850- "void *" to make it pass through catch_errors. */
4839+/* Evaluate the boolean expression EXP and return the result. */
48514840
4852-static int
4853-breakpoint_cond_eval (void *exp)
4841+static bool
4842+breakpoint_cond_eval (expression *exp)
48544843 {
48554844 struct value *mark = value_mark ();
4856- int i = !value_true (evaluate_expression ((struct expression *) exp));
4845+ bool res = value_true (evaluate_expression (exp));
48574846
48584847 value_free_to_mark (mark);
4859- return i;
4848+ return res;
48604849 }
48614850
48624851 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */
@@ -4966,30 +4955,31 @@ watchpoints_triggered (struct target_waitstatus *ws)
49664955 return 1;
49674956 }
49684957
4969-/* Possible return values for watchpoint_check (this can't be an enum
4970- because of check_errors). */
4971-/* The watchpoint has been deleted. */
4972-#define WP_DELETED 1
4973-/* The value has changed. */
4974-#define WP_VALUE_CHANGED 2
4975-/* The value has not changed. */
4976-#define WP_VALUE_NOT_CHANGED 3
4977-/* Ignore this watchpoint, no matter if the value changed or not. */
4978-#define WP_IGNORE 4
4958+/* Possible return values for watchpoint_check. */
4959+enum wp_check_result
4960+ {
4961+ /* The watchpoint has been deleted. */
4962+ WP_DELETED = 1,
4963+
4964+ /* The value has changed. */
4965+ WP_VALUE_CHANGED = 2,
4966+
4967+ /* The value has not changed. */
4968+ WP_VALUE_NOT_CHANGED = 3,
4969+
4970+ /* Ignore this watchpoint, no matter if the value changed or not. */
4971+ WP_IGNORE = 4,
4972+ };
49794973
49804974 #define BP_TEMPFLAG 1
49814975 #define BP_HARDWAREFLAG 2
49824976
49834977 /* Evaluate watchpoint condition expression and check if its value
4984- changed.
4985-
4986- P should be a pointer to struct bpstat, but is defined as a void *
4987- in order for this function to be usable with catch_errors. */
4978+ changed. */
49884979
4989-static int
4990-watchpoint_check (void *p)
4980+static wp_check_result
4981+watchpoint_check (bpstat bs)
49914982 {
4992- bpstat bs = (bpstat) p;
49934983 struct watchpoint *b;
49944984 struct frame_info *fr;
49954985 int within_current_scope;
@@ -5185,13 +5175,29 @@ bpstat_check_watchpoint (bpstat bs)
51855175
51865176 if (must_check_value)
51875177 {
5188- char *message
5189- = xstrprintf ("Error evaluating expression for watchpoint %d\n",
5190- b->number);
5191- struct cleanup *cleanups = make_cleanup (xfree, message);
5192- int e = catch_errors (watchpoint_check, bs, message,
5193- RETURN_MASK_ALL);
5194- do_cleanups (cleanups);
5178+ wp_check_result e;
5179+
5180+ TRY
5181+ {
5182+ e = watchpoint_check (bs);
5183+ }
5184+ CATCH (ex, RETURN_MASK_ALL)
5185+ {
5186+ exception_fprintf (gdb_stderr, ex,
5187+ "Error evaluating expression "
5188+ "for watchpoint %d\n",
5189+ b->number);
5190+
5191+ SWITCH_THRU_ALL_UIS ()
5192+ {
5193+ printf_filtered (_("Watchpoint %d deleted.\n"),
5194+ b->number);
5195+ }
5196+ watchpoint_del_at_next_stop (b);
5197+ e = WP_DELETED;
5198+ }
5199+ END_CATCH
5200+
51955201 switch (e)
51965202 {
51975203 case WP_DELETED:
@@ -5287,18 +5293,6 @@ bpstat_check_watchpoint (bpstat bs)
52875293 break;
52885294 default:
52895295 /* Can't happen. */
5290- case 0:
5291- /* Error from catch_errors. */
5292- {
5293- SWITCH_THRU_ALL_UIS ()
5294- {
5295- printf_filtered (_("Watchpoint %d deleted.\n"),
5296- b->number);
5297- }
5298- watchpoint_del_at_next_stop (b);
5299- /* We've already printed what needs to be printed. */
5300- bs->print_it = print_it_done;
5301- }
53025296 break;
53035297 }
53045298 }
@@ -5324,7 +5318,8 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
53245318 {
53255319 const struct bp_location *bl;
53265320 struct breakpoint *b;
5327- int value_is_zero = 0;
5321+ /* Assume stop. */
5322+ bool condition_result = true;
53285323 struct expression *cond;
53295324
53305325 gdb_assert (bs->stop);
@@ -5420,23 +5415,30 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
54205415 within_current_scope = 0;
54215416 }
54225417 if (within_current_scope)
5423- value_is_zero
5424- = catch_errors (breakpoint_cond_eval, cond,
5425- "Error in testing breakpoint condition:\n",
5426- RETURN_MASK_ALL);
5418+ {
5419+ TRY
5420+ {
5421+ condition_result = breakpoint_cond_eval (cond);
5422+ }
5423+ CATCH (ex, RETURN_MASK_ALL)
5424+ {
5425+ exception_fprintf (gdb_stderr, ex,
5426+ "Error in testing breakpoint condition:\n");
5427+ }
5428+ END_CATCH
5429+ }
54275430 else
54285431 {
54295432 warning (_("Watchpoint condition cannot be tested "
54305433 "in the current scope"));
54315434 /* If we failed to set the right context for this
54325435 watchpoint, unconditionally report it. */
5433- value_is_zero = 0;
54345436 }
54355437 /* FIXME-someday, should give breakpoint #. */
54365438 value_free_to_mark (mark);
54375439 }
54385440
5439- if (cond && value_is_zero)
5441+ if (cond && !condition_result)
54405442 {
54415443 bs->stop = 0;
54425444 }
@@ -14148,21 +14150,16 @@ prepare_re_set_context (struct breakpoint *b)
1414814150 return make_cleanup (null_cleanup, NULL);
1414914151 }
1415014152
14151-/* Reset a breakpoint given it's struct breakpoint * BINT.
14152- The value we return ends up being the return value from catch_errors.
14153- Unused in this case. */
14153+/* Reset a breakpoint. */
1415414154
14155-static int
14156-breakpoint_re_set_one (void *bint)
14155+static void
14156+breakpoint_re_set_one (breakpoint *b)
1415714157 {
14158- /* Get past catch_errs. */
14159- struct breakpoint *b = (struct breakpoint *) bint;
1416014158 struct cleanup *cleanups;
1416114159
1416214160 cleanups = prepare_re_set_context (b);
1416314161 b->ops->re_set (b);
1416414162 do_cleanups (cleanups);
14165- return 0;
1416614163 }
1416714164
1416814165 /* Re-set breakpoint locations for the current program space.
@@ -14188,12 +14185,17 @@ breakpoint_re_set (void)
1418814185
1418914186 ALL_BREAKPOINTS_SAFE (b, b_tmp)
1419014187 {
14191- /* Format possible error msg. */
14192- char *message = xstrprintf ("Error in re-setting breakpoint %d: ",
14193- b->number);
14194- struct cleanup *cleanups = make_cleanup (xfree, message);
14195- catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
14196- do_cleanups (cleanups);
14188+ TRY
14189+ {
14190+ breakpoint_re_set_one (b);
14191+ }
14192+ CATCH (ex, RETURN_MASK_ALL)
14193+ {
14194+ exception_fprintf (gdb_stderr, ex,
14195+ "Error in re-setting breakpoint %d: ",
14196+ b->number);
14197+ }
14198+ END_CATCH
1419714199 }
1419814200 set_language (save_language);
1419914201 input_radix = save_input_radix;
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -264,16 +264,16 @@ gdb_exception_sliced_copy (struct gdb_exception *to, const struct gdb_exception
264264
265265 #endif /* !GDB_XCPT_SJMP */
266266
267-/* Return EXCEPTION to the nearest containing catch_errors(). */
267+/* Return EXCEPTION to the nearest containing CATCH_SJLJ block. */
268268
269269 void
270270 throw_exception_sjlj (struct gdb_exception exception)
271271 {
272272 do_cleanups (all_cleanups ());
273273
274- /* Jump to the containing catch_errors() call, communicating REASON
275- to that call via setjmp's return value. Note that REASON can't
276- be zero, by definition in defs.h. */
274+ /* Jump to the nearest CATCH_SJLJ block, communicating REASON to
275+ that call via setjmp's return value. Note that REASON can't be
276+ zero, by definition in common-exceptions.h. */
277277 exceptions_state_mc (CATCH_THROWING);
278278 current_catcher->exception = exception;
279279 longjmp (current_catcher->buf, exception.reason);
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -217,45 +217,6 @@ catch_exceptions_with_msg (struct ui_out *func_uiout,
217217 return val;
218218 }
219219
220-/* This function is superseded by catch_exceptions(). */
221-
222-int
223-catch_errors (catch_errors_ftype *func, void *func_args,
224- const char *errstring, return_mask mask)
225-{
226- struct gdb_exception exception = exception_none;
227- volatile int val = 0;
228- struct ui_out *saved_uiout;
229-
230- /* Save the global ``struct ui_out'' builder. */
231- saved_uiout = current_uiout;
232-
233- TRY
234- {
235- val = func (func_args);
236- }
237- CATCH (ex, RETURN_MASK_ALL)
238- {
239- exception = ex;
240- }
241- END_CATCH
242-
243- /* Restore the global builder. */
244- current_uiout = saved_uiout;
245-
246- if (exception.reason < 0 && (mask & RETURN_MASK (exception.reason)) == 0)
247- {
248- /* The caller didn't request that the event be caught.
249- Rethrow. */
250- throw_exception (exception);
251- }
252-
253- exception_fprintf (gdb_stderr, exception, "%s", errstring);
254- if (exception.reason != 0)
255- return 0;
256- return val;
257-}
258-
259220 /* See exceptions.h. */
260221
261222 int
--- a/gdb/exceptions.h
+++ b/gdb/exceptions.h
@@ -48,21 +48,16 @@ extern void exception_fprintf (struct ui_file *file, struct gdb_exception e,
4848 copy of the gdb error message. This is used when a silent error is
4949 issued and the caller wants to manually issue the error message.
5050
51- MASK specifies what to catch; it is normally set to
52- RETURN_MASK_ALL, if for no other reason than that the code which
53- calls catch_errors might not be set up to deal with a quit which
54- isn't caught. But if the code can deal with it, it generally
55- should be RETURN_MASK_ERROR, unless for some reason it is more
56- useful to abort only the portion of the operation inside the
57- catch_errors. Note that quit should return to the command line
51+ MASK specifies what to catch; it is normally set to RETURN_MASK_ALL
52+ if the code which calls catch_exceptions is not set up to deal with
53+ a quit which isn't caught. But if the code can deal with it, it
54+ generally should be RETURN_MASK_ERROR, unless for some reason it is
55+ more useful to abort only the portion of the operation inside the
56+ catch_exceptions. Note that quit should return to the command line
5857 fairly quickly, even if some further processing is being done.
5958
6059 FIXME; cagney/2001-08-13: The need to override the global UIOUT
61- builder variable should just go away.
62-
63- This function supersedes catch_errors().
64-
65- This function uses SETJMP() and LONGJUMP(). */
60+ builder variable should just go away. */
6661
6762 struct ui_out;
6863 typedef int (catch_exceptions_ftype) (struct ui_out *ui_out, void *args);
@@ -76,19 +71,6 @@ extern int catch_exceptions_with_msg (struct ui_out *uiout,
7671 char **gdberrmsg,
7772 return_mask mask);
7873
79-/* If CATCH_ERRORS_FTYPE throws an error, catch_errors() returns zero
80- otherwize the result from CATCH_ERRORS_FTYPE is returned. It is
81- probably useful for CATCH_ERRORS_FTYPE to always return a non-zero
82- value. It's unfortunate that, catch_errors() does not return an
83- indication of the exact exception that it caught - quit_flag might
84- help.
85-
86- This function is superseded by catch_exceptions(). */
87-
88-typedef int (catch_errors_ftype) (void *);
89-extern int catch_errors (catch_errors_ftype *, void *,
90- const char *, return_mask);
91-
9274 /* Compare two exception objects for print equality. */
9375 extern int exception_print_same (struct gdb_exception e1,
9476 struct gdb_exception e2);
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -80,10 +80,6 @@ static void sig_print_header (void);
8080
8181 static void resume_cleanups (void *);
8282
83-static int hook_stop_stub (void *);
84-
85-static int restore_selected_frame (void *);
86-
8783 static int follow_fork (void);
8884
8985 static int follow_fork_inferior (int follow_child, int detach_fork);
@@ -8314,8 +8310,16 @@ normal_stop (void)
83148310 struct cleanup *old_chain
83158311 = make_cleanup (release_stop_context_cleanup, saved_context);
83168312
8317- catch_errors (hook_stop_stub, stop_command,
8318- "Error while running hook_stop:\n", RETURN_MASK_ALL);
8313+ TRY
8314+ {
8315+ execute_cmd_pre_hook (stop_command);
8316+ }
8317+ CATCH (ex, RETURN_MASK_ALL)
8318+ {
8319+ exception_fprintf (gdb_stderr, ex,
8320+ "Error while running hook_stop:\n");
8321+ }
8322+ END_CATCH
83198323
83208324 /* If the stop hook resumes the target, then there's no point in
83218325 trying to notify about the previous stop; its context is
@@ -8356,13 +8360,6 @@ normal_stop (void)
83568360
83578361 return 0;
83588362 }
8359-
8360-static int
8361-hook_stop_stub (void *cmd)
8362-{
8363- execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
8364- return (0);
8365-}
83668363
83678364 int
83688365 signal_stop_state (int signo)
@@ -8983,25 +8980,20 @@ save_infcall_control_state (void)
89838980 return inf_status;
89848981 }
89858982
8986-static int
8987-restore_selected_frame (void *args)
8983+static void
8984+restore_selected_frame (const frame_id &fid)
89888985 {
8989- struct frame_id *fid = (struct frame_id *) args;
8990- struct frame_info *frame;
8991-
8992- frame = frame_find_by_id (*fid);
8986+ frame_info *frame = frame_find_by_id (fid);
89938987
89948988 /* If inf_status->selected_frame_id is NULL, there was no previously
89958989 selected frame. */
89968990 if (frame == NULL)
89978991 {
89988992 warning (_("Unable to restore previously selected frame."));
8999- return 0;
8993+ return;
90008994 }
90018995
90028996 select_frame (frame);
9003-
9004- return (1);
90058997 }
90068998
90078999 /* Restore inferior session state to INF_STATUS. */
@@ -9031,16 +9023,22 @@ restore_infcall_control_state (struct infcall_control_state *inf_status)
90319023
90329024 if (target_has_stack)
90339025 {
9034- /* The point of catch_errors is that if the stack is clobbered,
9026+ /* The point of the try/catch is that if the stack is clobbered,
90359027 walking the stack might encounter a garbage pointer and
90369028 error() trying to dereference it. */
9037- if (catch_errors
9038- (restore_selected_frame, &inf_status->selected_frame_id,
9039- "Unable to restore previously selected frame:\n",
9040- RETURN_MASK_ERROR) == 0)
9041- /* Error in restoring the selected frame. Select the innermost
9042- frame. */
9043- select_frame (get_current_frame ());
9029+ TRY
9030+ {
9031+ restore_selected_frame (inf_status->selected_frame_id);
9032+ }
9033+ CATCH (ex, RETURN_MASK_ERROR)
9034+ {
9035+ exception_fprintf (gdb_stderr, ex,
9036+ "Unable to restore previously selected frame:\n");
9037+ /* Error in restoring the selected frame. Select the
9038+ innermost frame. */
9039+ select_frame (get_current_frame ());
9040+ }
9041+ END_CATCH
90449042 }
90459043
90469044 xfree (inf_status);
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -305,11 +305,10 @@ setup_alternate_signal_stack (void)
305305 #endif
306306 }
307307
308-/* Call command_loop. If it happens to return, pass that through as a
309- non-zero return status. */
308+/* Call command_loop. */
310309
311-static int
312-captured_command_loop (void *data)
310+static void
311+captured_command_loop ()
313312 {
314313 struct ui *ui = current_ui;
315314
@@ -333,11 +332,9 @@ captured_command_loop (void *data)
333332 check to detect bad FUNCs code. */
334333 do_cleanups (all_cleanups ());
335334 /* If the command_loop returned, normally (rather than threw an
336- error) we try to quit. If the quit is aborted, catch_errors()
337- which called this catch the signal and restart the command
338- loop. */
335+ error) we try to quit. If the quit is aborted, our caller
336+ catches the signal and restarts the command loop. */
339337 quit_command (NULL, ui->instream == ui->stdin_stream);
340- return 1;
341338 }
342339
343340 /* Handle command errors thrown from within catch_command_errors. */
@@ -1145,7 +1142,15 @@ captured_main (void *data)
11451142 change - SET_TOP_LEVEL() - has been eliminated. */
11461143 while (1)
11471144 {
1148- catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL);
1145+ TRY
1146+ {
1147+ captured_command_loop ();
1148+ }
1149+ CATCH (ex, RETURN_MASK_ALL)
1150+ {
1151+ exception_print (gdb_stderr, ex);
1152+ }
1153+ END_CATCH
11491154 }
11501155 /* No exit -- exit is through quit_command. */
11511156 }
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -1310,43 +1310,25 @@ find_objc_msgsend (void)
13101310 * dependent modules.
13111311 */
13121312
1313-struct objc_submethod_helper_data {
1314- int (*f) (CORE_ADDR, CORE_ADDR *);
1315- CORE_ADDR pc;
1316- CORE_ADDR *new_pc;
1317-};
1318-
1319-static int
1320-find_objc_msgcall_submethod_helper (void * arg)
1321-{
1322- struct objc_submethod_helper_data *s =
1323- (struct objc_submethod_helper_data *) arg;
1324-
1325- if (s->f (s->pc, s->new_pc) == 0)
1326- return 1;
1327- else
1328- return 0;
1329-}
1330-
13311313 static int
13321314 find_objc_msgcall_submethod (int (*f) (CORE_ADDR, CORE_ADDR *),
13331315 CORE_ADDR pc,
13341316 CORE_ADDR *new_pc)
13351317 {
1336- struct objc_submethod_helper_data s;
1337-
1338- s.f = f;
1339- s.pc = pc;
1340- s.new_pc = new_pc;
1318+ TRY
1319+ {
1320+ if (f (pc, new_pc) == 0)
1321+ return 1;
1322+ }
1323+ CATCH (ex, RETURN_MASK_ALL)
1324+ {
1325+ exception_fprintf (gdb_stderr, ex,
1326+ "Unable to determine target of "
1327+ "Objective-C method call (ignoring):\n");
1328+ }
1329+ END_CATCH
13411330
1342- if (catch_errors (find_objc_msgcall_submethod_helper,
1343- (void *) &s,
1344- "Unable to determine target of "
1345- "Objective-C method call (ignoring):\n",
1346- RETURN_MASK_ALL) == 0)
1347- return 1;
1348- else
1349- return 0;
1331+ return 0;
13501332 }
13511333
13521334 int
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -565,7 +565,7 @@ record_full_arch_list_cleanups (void *ignore)
565565 record the running message of inferior and set them to
566566 record_full_arch_list, and add it to record_full_list. */
567567
568-static int
568+static void
569569 record_full_message (struct regcache *regcache, enum gdb_signal signal)
570570 {
571571 int ret;
@@ -633,36 +633,24 @@ record_full_message (struct regcache *regcache, enum gdb_signal signal)
633633 record_full_list_release_first ();
634634 else
635635 record_full_insn_num++;
636-
637- return 1;
638-}
639-
640-struct record_full_message_args {
641- struct regcache *regcache;
642- enum gdb_signal signal;
643-};
644-
645-static int
646-record_full_message_wrapper (void *args)
647-{
648- struct record_full_message_args *record_full_args
649- = (struct record_full_message_args *) args;
650-
651- return record_full_message (record_full_args->regcache,
652- record_full_args->signal);
653636 }
654637
655-static int
638+static bool
656639 record_full_message_wrapper_safe (struct regcache *regcache,
657640 enum gdb_signal signal)
658641 {
659- struct record_full_message_args args;
660-
661- args.regcache = regcache;
662- args.signal = signal;
642+ TRY
643+ {
644+ record_full_message (regcache, signal);
645+ }
646+ CATCH (ex, RETURN_MASK_ALL)
647+ {
648+ exception_print (gdb_stderr, ex);
649+ return false;
650+ }
651+ END_CATCH
663652
664- return catch_errors (record_full_message_wrapper, &args, "",
665- RETURN_MASK_ALL);
653+ return true;
666654 }
667655
668656 /* Set to 1 if record_full_store_registers and record_full_xfer_partial
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -589,7 +589,7 @@ solib_aix_current_sos (void)
589589 /* Implement the "open_symbol_file_object" target_so_ops method. */
590590
591591 static int
592-solib_aix_open_symbol_file_object (void *from_ttyp)
592+solib_aix_open_symbol_file_object (int from_tty)
593593 {
594594 return 0;
595595 }
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -222,7 +222,7 @@ find_program_interpreter (void)
222222 Note that darwin-nat.c implements pid_to_exec_file. */
223223
224224 static int
225-open_symbol_file_object (void *from_ttyp)
225+open_symbol_file_object (int from_tty)
226226 {
227227 return 0;
228228 }
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -507,16 +507,10 @@ scan_dyntag (int dyntag, bfd *abfd, CORE_ADDR *ptr)
507507 return 0;
508508 }
509509
510-/* If no open symbol file, attempt to locate and open the main symbol
511- file.
512-
513- If FROM_TTYP dereferences to a non-zero integer, allow messages to
514- be printed. This parameter is a pointer rather than an int because
515- open_symbol_file_object is called via catch_errors and
516- catch_errors requires a pointer argument. */
510+/* See solist.h. */
517511
518512 static int
519-open_symbol_file_object (void *from_ttyp)
513+open_symbol_file_object (int from_tty)
520514 {
521515 /* Unimplemented. */
522516 return 0;
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -246,7 +246,7 @@ static int enable_break2 (void);
246246 /* Implement the "open_symbol_file_object" target_so_ops method. */
247247
248248 static int
249-open_symbol_file_object (void *from_ttyp)
249+open_symbol_file_object (int from_tty)
250250 {
251251 /* Unimplemented. */
252252 return 0;
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -984,20 +984,14 @@ svr4_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
984984 return (name_lm >= vaddr && name_lm < vaddr + size);
985985 }
986986
987-/* Implement the "open_symbol_file_object" target_so_ops method.
988-
989- If no open symbol file, attempt to locate and open the main symbol
990- file. On SVR4 systems, this is the first link map entry. If its
991- name is here, we can open it. Useful when attaching to a process
992- without first loading its symbol file. */
987+/* See solist.h. */
993988
994989 static int
995-open_symbol_file_object (void *from_ttyp)
990+open_symbol_file_object (int from_tty)
996991 {
997992 CORE_ADDR lm, l_name;
998993 char *filename;
999994 int errcode;
1000- int from_tty = *(int *)from_ttyp;
1001995 struct link_map_offsets *lmo = svr4_fetch_link_map_offsets ();
1002996 struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
1003997 int l_name_size = TYPE_LENGTH (ptr_type);
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -452,7 +452,7 @@ Could not relocate shared library \"%s\": bad offsets"), so->so_name);
452452 }
453453
454454 static int
455-solib_target_open_symbol_file_object (void *from_ttyp)
455+solib_target_open_symbol_file_object (int from_tty)
456456 {
457457 /* We can't locate the main symbol file based on the target's
458458 knowledge; the user has to specify it. */
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -760,9 +760,19 @@ update_solib_list (int from_tty)
760760 have not opened a symbol file, we may be able to get its
761761 symbols now! */
762762 if (inf->attach_flag && symfile_objfile == NULL)
763- catch_errors (ops->open_symbol_file_object, &from_tty,
764- "Error reading attached process's symbol file.\n",
765- RETURN_MASK_ALL);
763+ {
764+ TRY
765+ {
766+ ops->open_symbol_file_object (from_tty);
767+ }
768+ CATCH (ex, RETURN_MASK_ALL)
769+ {
770+ exception_fprintf (gdb_stderr, ex,
771+ "Error reading attached "
772+ "process's symbol file.\n");
773+ }
774+ END_CATCH
775+ }
766776 }
767777
768778 /* GDB and the inferior's dynamic linker each maintain their own
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -121,11 +121,8 @@ struct target_so_ops
121121 struct so_list *(*current_sos) (void);
122122
123123 /* Find, open, and read the symbols for the main executable. If
124- FROM_TTYP dereferences to a non-zero integer, allow messages to
125- be printed. This parameter is a pointer rather than an int
126- because open_symbol_file_object is called via catch_errors and
127- catch_errors requires a pointer argument. */
128- int (*open_symbol_file_object) (void *from_ttyp);
124+ FROM_TTY is non-zero, allow messages to be printed. */
125+ int (*open_symbol_file_object) (int from_ttyp);
129126
130127 /* Determine if PC lies in the dynamic symbol resolution code of
131128 the run time loader. */
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -54,15 +54,8 @@ FILE *std_err;
5454
5555 static int block_depth (struct block *);
5656
57-struct print_symbol_args
58- {
59- struct gdbarch *gdbarch;
60- struct symbol *symbol;
61- int depth;
62- struct ui_file *outfile;
63- };
64-
65-static int print_symbol (void *);
57+static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
58+ int depth, ui_file *outfile);
6659
6760
6861 void
@@ -357,14 +350,16 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
357350 block, not any blocks from included symtabs. */
358351 ALL_DICT_SYMBOLS (BLOCK_DICT (b), iter, sym)
359352 {
360- struct print_symbol_args s;
361-
362- s.gdbarch = gdbarch;
363- s.symbol = sym;
364- s.depth = depth + 1;
365- s.outfile = outfile;
366- catch_errors (print_symbol, &s, "Error printing symbol:\n",
367- RETURN_MASK_ERROR);
353+ TRY
354+ {
355+ print_symbol (gdbarch, sym, depth + 1, outfile);
356+ }
357+ CATCH (ex, RETURN_MASK_ERROR)
358+ {
359+ exception_fprintf (gdb_stderr, ex,
360+ "Error printing symbol:\n");
361+ }
362+ END_CATCH
368363 }
369364 }
370365 fprintf_filtered (outfile, "\n");
@@ -515,18 +510,12 @@ maintenance_print_symbols (const char *args, int from_tty)
515510 }
516511 }
517512
518-/* Print symbol ARGS->SYMBOL on ARGS->OUTFILE. ARGS->DEPTH says how
519- far to indent. ARGS is really a struct print_symbol_args *, but is
520- declared as char * to get it past catch_errors. Returns 0 for error,
521- 1 for success. */
513+/* Print symbol SYMBOL on OUTFILE. DEPTH says how far to indent. */
522514
523-static int
524-print_symbol (void *args)
515+static void
516+print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
517+ int depth, ui_file *outfile)
525518 {
526- struct gdbarch *gdbarch = ((struct print_symbol_args *) args)->gdbarch;
527- struct symbol *symbol = ((struct print_symbol_args *) args)->symbol;
528- int depth = ((struct print_symbol_args *) args)->depth;
529- struct ui_file *outfile = ((struct print_symbol_args *) args)->outfile;
530519 struct obj_section *section;
531520
532521 if (SYMBOL_OBJFILE_OWNED (symbol))
@@ -546,8 +535,9 @@ print_symbol (void *args)
546535 section->the_bfd_section));
547536 else
548537 fprintf_filtered (outfile, "\n");
549- return 1;
538+ return;
550539 }
540+
551541 if (SYMBOL_DOMAIN (symbol) == STRUCT_DOMAIN)
552542 {
553543 if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
@@ -694,7 +684,6 @@ print_symbol (void *args)
694684 }
695685 }
696686 fprintf_filtered (outfile, "\n");
697- return 1;
698687 }
699688
700689 static void
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
1+2017-10-10 Pedro Alves <palves@redhat.com>
2+
3+ * lib/selftest-support.exp (selftest_setup): Update for
4+ captured_command_loop's prototype change.
5+
16 2017-10-09 Pedro Alves <palves@redhat.com>
27
38 Test both arch1=>arch2 and arch2=>arch1.
--- a/gdb/testsuite/lib/selftest-support.exp
+++ b/gdb/testsuite/lib/selftest-support.exp
@@ -88,10 +88,10 @@ proc selftest_setup { executable function } {
8888
8989 set description "run until breakpoint at $function"
9090 gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
91- -re "Starting program.*Breakpoint \[0-9\]+,.*$function .data.* at .*main.c:.*$gdb_prompt $" {
91+ -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(\\).* at .*main.c:.*$gdb_prompt $" {
9292 pass "$description"
9393 }
94- -re "Starting program.*Breakpoint \[0-9\]+,.*$function .data.*$gdb_prompt $" {
94+ -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(\\).*$gdb_prompt $" {
9595 xfail "$description (line numbers scrambled?)"
9696 }
9797 -re "Starting program.*Breakpoint \[0-9\]+,.* at .*main.c:.*$function.*$gdb_prompt $" {
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -756,8 +756,8 @@ get_image_name (HANDLE h, void *address, int unicode)
756756 do_initial_windows_stuff and windows_add_all_dlls for more info
757757 on how we handle DLL loading during that phase). */
758758
759-static int
760-handle_load_dll (void *dummy)
759+static void
760+handle_load_dll ()
761761 {
762762 LOAD_DLL_DEBUG_INFO *event = &current_event.u.LoadDll;
763763 char *dll_name;
@@ -770,7 +770,7 @@ handle_load_dll (void *dummy)
770770 dll_name = get_image_name (current_process_handle,
771771 event->lpImageName, event->fUnicode);
772772 if (!dll_name)
773- return 1;
773+ return;
774774
775775 solib_end->next = windows_make_so (dll_name, event->lpBaseOfDll);
776776 solib_end = solib_end->next;
@@ -779,8 +779,6 @@ handle_load_dll (void *dummy)
779779
780780 DEBUG_EVENTS (("gdb: Loading dll \"%s\" at %s.\n", solib_end->so_name,
781781 host_address_to_string (li->load_addr)));
782-
783- return 1;
784782 }
785783
786784 static void
@@ -800,8 +798,8 @@ windows_free_so (struct so_list *so)
800798 do_initial_windows_stuff and windows_add_all_dlls for more info
801799 on how we handle DLL loading during that phase). */
802800
803-static int
804-handle_unload_dll (void *dummy)
801+static void
802+handle_unload_dll ()
805803 {
806804 LPVOID lpBaseOfDll = current_event.u.UnloadDll.lpBaseOfDll;
807805 struct so_list *so;
@@ -820,7 +818,7 @@ handle_unload_dll (void *dummy)
820818 DEBUG_EVENTS (("gdb: Unloading dll \"%s\".\n", sodel->so_name));
821819
822820 windows_free_so (sodel);
823- return 1;
821+ return;
824822 }
825823 }
826824
@@ -833,8 +831,23 @@ handle_unload_dll (void *dummy)
833831 32bit and 64bit worlds). */
834832 complaint (&symfile_complaints, _("dll starting at %s not found."),
835833 host_address_to_string (lpBaseOfDll));
834+}
836835
837- return 0;
836+/* Call FUNC wrapped in a TRY/CATCH that swallows all GDB
837+ exceptions. */
838+
839+static void
840+catch_errors (void (*func) ())
841+{
842+ TRY
843+ {
844+ func ();
845+ }
846+ CATCH (ex, RETURN_MASK_ALL)
847+ {
848+ exception_print (gdb_stderr, ex);
849+ }
850+ END_CATCH
838851 }
839852
840853 /* Clear list of loaded DLLs. */
@@ -1542,7 +1555,7 @@ get_windows_debug_event (struct target_ops *ops,
15421555 CloseHandle (current_event.u.LoadDll.hFile);
15431556 if (saw_create != 1 || ! windows_initialization_done)
15441557 break;
1545- catch_errors (handle_load_dll, NULL, (char *) "", RETURN_MASK_ALL);
1558+ catch_errors (handle_load_dll);
15461559 ourstatus->kind = TARGET_WAITKIND_LOADED;
15471560 ourstatus->value.integer = 0;
15481561 thread_id = main_thread_id;
@@ -1555,7 +1568,7 @@ get_windows_debug_event (struct target_ops *ops,
15551568 "UNLOAD_DLL_DEBUG_EVENT"));
15561569 if (saw_create != 1 || ! windows_initialization_done)
15571570 break;
1558- catch_errors (handle_unload_dll, NULL, (char *) "", RETURN_MASK_ALL);
1571+ catch_errors (handle_unload_dll);
15591572 ourstatus->kind = TARGET_WAITKIND_LOADED;
15601573 ourstatus->value.integer = 0;
15611574 thread_id = main_thread_id;