Don't call set_current_source_symtab_and_line from TUI
[deliverable/binutils-gdb.git] / gdb / exceptions.c
CommitLineData
60250e8b
AC
1/* Exception (throw catch) mechanism, for GDB, the GNU debugger.
2
42a4f53d 3 Copyright (C) 1986-2019 Free Software Foundation, Inc.
60250e8b
AC
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
60250e8b
AC
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
60250e8b
AC
19
20#include "defs.h"
d55e5aa6 21#include "exceptions.h"
4de283e4
TT
22#include "breakpoint.h"
23#include "target.h"
60250e8b 24#include "inferior.h"
4de283e4
TT
25#include "annotate.h"
26#include "ui-out.h"
e06e2353 27#include "serial.h"
4de283e4 28#include "gdbthread.h"
694ec099 29#include "top.h"
268a13a5 30#include "gdbsupport/gdb_optional.h"
60250e8b 31
6b1b7650 32static void
c6da7a6d 33print_flush (void)
6b1b7650 34{
694ec099 35 struct ui *ui = current_ui;
e06e2353
AC
36 struct serial *gdb_stdout_serial;
37
c6da7a6d
AC
38 if (deprecated_error_begin_hook)
39 deprecated_error_begin_hook ();
5df43998 40
223ffa71 41 gdb::optional<target_terminal::scoped_restore_terminal_state> term_state;
f6ac5f3d
PA
42 /* While normally there's always something pushed on the target
43 stack, the NULL check is needed here because we can get here very
44 early during startup, before the target stack is first
45 initialized. */
8b88a78e 46 if (current_top_target () != NULL && target_supports_terminal_ours ())
481ac8c9 47 {
223ffa71
TT
48 term_state.emplace ();
49 target_terminal::ours_for_output ();
481ac8c9 50 }
e06e2353
AC
51
52 /* We want all output to appear now, before we print the error. We
53 have 3 levels of buffering we have to flush (it's possible that
54 some of these should be changed to flush the lower-level ones
55 too): */
56
57 /* 1. The _filtered buffer. */
5df43998
GB
58 if (filtered_printing_initialized ())
59 wrap_here ("");
e06e2353
AC
60
61 /* 2. The stdio buffer. */
c6da7a6d 62 gdb_flush (gdb_stdout);
e06e2353
AC
63 gdb_flush (gdb_stderr);
64
65 /* 3. The system-level buffer. */
694ec099 66 gdb_stdout_serial = serial_fdopen (fileno (ui->outstream));
cade9e54
PB
67 if (gdb_stdout_serial)
68 {
69 serial_drain_output (gdb_stdout_serial);
70 serial_un_fdopen (gdb_stdout_serial);
71 }
e06e2353 72
c6da7a6d 73 annotate_error_begin ();
6b1b7650
AC
74}
75
9cbc821d 76static void
94aeb44b 77print_exception (struct ui_file *file, const struct gdb_exception &e)
9cbc821d 78{
85102364 79 /* KLUDGE: cagney/2005-01-13: Write the string out one line at a time
9cbc821d
AC
80 as that way the MI's behavior is preserved. */
81 const char *start;
82 const char *end;
d7f9d729 83
3d6e9d23 84 for (start = e.what (); start != NULL; start = end)
9cbc821d
AC
85 {
86 end = strchr (start, '\n');
87 if (end == NULL)
88 fputs_filtered (start, file);
89 else
90 {
91 end++;
92 ui_file_write (file, start, end - start);
93 }
94 }
c6da7a6d 95 fprintf_filtered (file, "\n");
e48f5bee
AC
96
97 /* Now append the annotation. */
98 switch (e.reason)
99 {
100 case RETURN_QUIT:
101 annotate_quit ();
102 break;
103 case RETURN_ERROR:
104 /* Assume that these are all errors. */
105 annotate_error ();
106 break;
107 default:
108 internal_error (__FILE__, __LINE__, _("Bad switch."));
109 }
9cbc821d
AC
110}
111
8a076db9 112void
94aeb44b 113exception_print (struct ui_file *file, const struct gdb_exception &e)
8a076db9
AC
114{
115 if (e.reason < 0 && e.message != NULL)
116 {
c6da7a6d 117 print_flush ();
9cbc821d 118 print_exception (file, e);
9cbc821d
AC
119 }
120}
8a076db9 121
9cbc821d 122void
94aeb44b 123exception_fprintf (struct ui_file *file, const struct gdb_exception &e,
9cbc821d
AC
124 const char *prefix, ...)
125{
126 if (e.reason < 0 && e.message != NULL)
127 {
128 va_list args;
c6da7a6d
AC
129
130 print_flush ();
9cbc821d
AC
131
132 /* Print the prefix. */
133 va_start (args, prefix);
134 vfprintf_filtered (file, prefix, args);
135 va_end (args);
136
137 print_exception (file, e);
8a076db9
AC
138 }
139}
140
ecf45d2c
SL
141/* See exceptions.h. */
142
143int
94aeb44b
TT
144exception_print_same (const struct gdb_exception &e1,
145 const struct gdb_exception &e2)
ecf45d2c 146{
3d6e9d23
TT
147 const char *msg1 = e1.message == nullptr ? "" : e1.what ();
148 const char *msg2 = e2.message == nullptr ? "" : e2.what ();
ecf45d2c
SL
149
150 return (e1.reason == e2.reason
151 && e1.error == e2.error
152 && strcmp (msg1, msg2) == 0);
153}
This page took 1.701051 seconds and 4 git commands to generate.