* configure.tgt (powerpc-*-elf, et al): Define targ_extra_libpath.
[deliverable/binutils-gdb.git] / gdb / cli / cli-interp.c
CommitLineData
4a8f6654
AC
1/* CLI Definitions for GDB, the GNU debugger.
2
0b302171 3 Copyright (c) 2002-2003, 2007-2012 Free Software Foundation, Inc.
4a8f6654
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
4a8f6654
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/>. */
4a8f6654
AC
19
20#include "defs.h"
21#include "interps.h"
4a8f6654
AC
22#include "event-top.h"
23#include "ui-out.h"
24#include "cli-out.h"
25#include "top.h" /* for "execute_command" */
26#include "gdb_string.h"
60250e8b 27#include "exceptions.h"
4a8f6654
AC
28
29struct ui_out *cli_uiout;
30
ebcd3b23
MS
31/* These are the ui_out and the interpreter for the console
32 interpreter. */
4a8f6654 33
4791eb66 34/* Longjmp-safe wrapper for "execute_command". */
71fff37b 35static struct gdb_exception safe_execute_command (struct ui_out *uiout,
ebcd3b23
MS
36 char *command,
37 int from_tty);
4a8f6654
AC
38/* These implement the cli out interpreter: */
39
40static void *
4801a9a3 41cli_interpreter_init (struct interp *self, int top_level)
4a8f6654
AC
42{
43 return NULL;
44}
45
46static int
47cli_interpreter_resume (void *data)
48{
38caaeec
DJ
49 struct ui_file *stream;
50
4a8f6654 51 /*sync_execution = 1; */
38caaeec 52
ebcd3b23
MS
53 /* gdb_setup_readline will change gdb_stdout. If the CLI was
54 previously writing to gdb_stdout, then set it to the new
55 gdb_stdout afterwards. */
38caaeec
DJ
56
57 stream = cli_out_set_stream (cli_uiout, gdb_stdout);
58 if (stream != gdb_stdout)
59 {
60 cli_out_set_stream (cli_uiout, stream);
61 stream = NULL;
62 }
63
4a8f6654 64 gdb_setup_readline ();
38caaeec
DJ
65
66 if (stream != NULL)
67 cli_out_set_stream (cli_uiout, gdb_stdout);
68
4a8f6654
AC
69 return 1;
70}
71
72static int
73cli_interpreter_suspend (void *data)
74{
75 gdb_disable_readline ();
76 return 1;
77}
78
79/* Don't display the prompt if we are set quiet. */
80static int
81cli_interpreter_display_prompt_p (void *data)
82{
83 if (interp_quiet_p (NULL))
84 return 0;
85 else
86 return 1;
87}
88
71fff37b 89static struct gdb_exception
4a8f6654
AC
90cli_interpreter_exec (void *data, const char *command_str)
91{
4a8f6654 92 struct ui_file *old_stream;
71fff37b 93 struct gdb_exception result;
4a8f6654
AC
94
95 /* FIXME: cagney/2003-02-01: Need to const char *propogate
96 safe_execute_command. */
97 char *str = strcpy (alloca (strlen (command_str) + 1), command_str);
98
ebcd3b23
MS
99 /* gdb_stdout could change between the time cli_uiout was
100 initialized and now. Since we're probably using a different
101 interpreter which has a new ui_file for gdb_stdout, use that one
102 instead of the default.
4a8f6654 103
ebcd3b23
MS
104 It is important that it gets reset everytime, since the user
105 could set gdb to use a different interpreter. */
4a8f6654
AC
106 old_stream = cli_out_set_stream (cli_uiout, gdb_stdout);
107 result = safe_execute_command (cli_uiout, str, 1);
108 cli_out_set_stream (cli_uiout, old_stream);
109 return result;
110}
111
71fff37b 112static struct gdb_exception
f9679975 113safe_execute_command (struct ui_out *command_uiout, char *command, int from_tty)
4a8f6654 114{
04bd08de 115 volatile struct gdb_exception e;
f9679975
PA
116 struct ui_out *saved_uiout;
117
118 /* Save and override the global ``struct ui_out'' builder. */
79a45e25
PA
119 saved_uiout = current_uiout;
120 current_uiout = command_uiout;
cdb27c12 121
04bd08de
TT
122 TRY_CATCH (e, RETURN_MASK_ALL)
123 {
124 execute_command (command, from_tty);
125 }
f9679975
PA
126
127 /* Restore the global builder. */
79a45e25 128 current_uiout = saved_uiout;
f9679975 129
8a076db9
AC
130 /* FIXME: cagney/2005-01-13: This shouldn't be needed. Instead the
131 caller should print the exception. */
9cbc821d 132 exception_print (gdb_stderr, e);
8a076db9 133 return e;
4a8f6654
AC
134}
135
4801a9a3
PA
136static struct ui_out *
137cli_ui_out (struct interp *self)
138{
139 return cli_uiout;
140}
4a8f6654 141
4791eb66 142/* Standard gdb initialization hook. */
b9362cc7
AC
143extern initialize_file_ftype _initialize_cli_interp; /* -Wmissing-prototypes */
144
4a8f6654
AC
145void
146_initialize_cli_interp (void)
147{
148 static const struct interp_procs procs = {
149 cli_interpreter_init, /* init_proc */
150 cli_interpreter_resume, /* resume_proc */
151 cli_interpreter_suspend, /* suspend_proc */
152 cli_interpreter_exec, /* exec_proc */
4801a9a3
PA
153 cli_interpreter_display_prompt_p, /* prompt_proc_p */
154 cli_ui_out /* ui_out_proc */
4a8f6654
AC
155 };
156 struct interp *cli_interp;
157
4791eb66 158 /* Create a default uiout builder for the CLI. */
4a8f6654 159 cli_uiout = cli_out_new (gdb_stdout);
4801a9a3 160 cli_interp = interp_new (INTERP_CONSOLE, &procs);
4a8f6654
AC
161
162 interp_add (cli_interp);
163}
This page took 0.909519 seconds and 4 git commands to generate.