[nemiver] Let inferior use launch terminal (Closes: #602072)
- From: Dodji Seketeli <dodji src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nemiver] Let inferior use launch terminal (Closes: #602072)
- Date: Tue, 24 Nov 2009 15:46:26 +0000 (UTC)
commit 7643c579f35efbb3012c9b23002b3a649f5f0455
Author: Tom Hughes <tom compton nu>
Date: Sun Nov 22 00:50:10 2009 +0100
Let inferior use launch terminal (Closes: #602072)
* src/dbgengine/nmv-i-debugger.h (IDebugger::set_tty_path): Declare
new interface entry point.
* src/dbgengine/nmv-gdb-engine.h (GDBEngine::set_tty_path): Likewise.
* src/dbgengine/nmv-gdb-engine.cc (GDBEngine::Priv::set_tty_path): New
method.
(GDBEngine::load_program, GDBEngine::attach_to_target,): Use it.
(GDBEngine::set_tty_path): Implementation of the new
IDebugger::set_tty_path interface. Uses GDBEngine::Priv::set_tty_path.
* src/main.cc (static GOptionEntry entries): Add a new entry for a new
--use-launch-terminal command line option.
(process_gui_options): Let the debug perspective be aware when the
user wants the inferior to use the terminal from which Nemiver was
launched.
(main): Try to release the current controlling terminal when we want the
inferior to use it.
* src/persp/dbgperspective/nmv-conf-keys.h
(CONF_KEY_USE_LAUNCH_TERMINAL): Declare constant for the 'use launch
terminal' conf key.
* src/persp/dbgperspective/nmv-dbg-perspective.h:
(IDBGPerspective::uses_launch_terminal): Declare new accessors.
* src/persp/dbgperspective/nmv-dbg-perspective.cc
(CONF_KEY_USE_LAUNCH_TERMINAL): Define conf key constant.
(DBGPerspective::get_terminal_name,
DBGPerspective::uses_launch_terminal): New accessors.
(DBGPerspective::on_conf_key_changed_signal,
DBGPerspective::read_default_config): Handle
CONF_KEY_USE_LAUNCH_TERMINAL key.
(DBGPerspective::execute_program, DBGPerspective::attach_to_program):
Use the terminal path the user wants, not necessarily the one of the
graphical terminal embedded in the GUI.
* src/persp/dbgperspective/glade/preferencesdialog.glade: Add a UI to
set the "use launch terminal" key.
* src/persp/dbgperspective/nmv-preferences-dialog.cc:
(PreferencesDialog::Priv::on_launch_terminal_toggled_signal,
PreferencesDialog::Priv::update_use_launch_terminal_key): New
methods.
(PreferencesDialog::Priv::init): When the 'use launch terminal'
check button is checked, set the 'use launch terminal' conf key
accordingly.
(PreferencesDialog::Priv::update_widget_from_editor_keys):
Populate the 'use launch terminal' check button state according to the
'use launch terminal' conf key. Set it to false by default.
* src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas:
(apps/nemiver/dbgperspective/use-launch-terminal): New key. Set to
false by defaulf.
src/dbgengine/nmv-gdb-engine.cc | 21 ++++++---
src/dbgengine/nmv-gdb-engine.h | 2 +
src/dbgengine/nmv-i-debugger.h | 2 +
src/main.cc | 44 +++++++++++++++++-
.../dbgperspective/glade/preferencesdialog.glade | 40 +++++++++++++++++
src/persp/dbgperspective/nmv-conf-keys.h | 1 +
src/persp/dbgperspective/nmv-dbg-perspective.cc | 47 +++++++++++++++++++-
src/persp/dbgperspective/nmv-dbg-perspective.h | 4 ++
src/persp/dbgperspective/nmv-preferences-dialog.cc | 37 +++++++++++++++-
.../schemas/nemiver-dbgperspective.schemas | 12 +++++
10 files changed, 198 insertions(+), 12 deletions(-)
---
diff --git a/src/dbgengine/nmv-gdb-engine.cc b/src/dbgengine/nmv-gdb-engine.cc
index cf8f9df..84b5b77 100644
--- a/src/dbgengine/nmv-gdb-engine.cc
+++ b/src/dbgengine/nmv-gdb-engine.cc
@@ -772,6 +772,12 @@ public:
a_cookie));
}
+ void set_tty_path (const UString &a_tty_path)
+ {
+ LOG_FUNCTION_SCOPE_NORMAL_DD;
+ if (!a_tty_path.empty ())
+ queue_command (Command ("set inferior-tty " + a_tty_path));
+ }
bool on_gdb_stdout_has_data_signal (Glib::IOCondition a_cond)
{
@@ -2546,9 +2552,7 @@ GDBEngine::load_program (const UString &a_prog,
queue_command (command);
}
}
- if (!a_tty_path.empty ()) {
- queue_command (Command ("set inferior-tty " + a_tty_path));
- }
+ set_tty_path (a_tty_path);
}
void
@@ -2600,9 +2604,7 @@ GDBEngine::attach_to_target (unsigned int a_pid,
queue_command (Command ("attach-to-program",
"attach " + UString::from_int (a_pid)));
queue_command (Command ("info proc"));
- if (a_tty_path != "") {
- queue_command (Command ("tty " + a_tty_path));
- }
+ set_tty_path (a_tty_path);
return true;
}
@@ -2647,6 +2649,13 @@ GDBEngine::set_attached_to_target (bool a_is_attached)
}
void
+GDBEngine::set_tty_path (const UString &a_tty_path)
+{
+ LOG_FUNCTION_SCOPE_NORMAL_DD;
+ m_priv->set_tty_path (a_tty_path);
+}
+
+void
GDBEngine::add_env_variables (const map<UString, UString> &a_vars)
{
LOG_FUNCTION_SCOPE_NORMAL_DD;
diff --git a/src/dbgengine/nmv-gdb-engine.h b/src/dbgengine/nmv-gdb-engine.h
index e3654c0..14f7154 100644
--- a/src/dbgengine/nmv-gdb-engine.h
+++ b/src/dbgengine/nmv-gdb-engine.h
@@ -265,6 +265,8 @@ public:
void set_attached_to_target (bool a_is_attached);
+ void set_tty_path (const UString &a_tty_path);
+
void add_env_variables (const map<UString, UString> &a_vars);
map<UString, UString>& get_env_variables () ;
diff --git a/src/dbgengine/nmv-i-debugger.h b/src/dbgengine/nmv-i-debugger.h
index a55ac32..dab0164 100644
--- a/src/dbgengine/nmv-i-debugger.h
+++ b/src/dbgengine/nmv-i-debugger.h
@@ -1010,6 +1010,8 @@ public:
virtual bool is_attached_to_target () const =0;
+ virtual void set_tty_path (const UString &a_tty_path) = 0;
+
virtual void add_env_variables (const map<UString, UString> &a_vars) = 0;
virtual map<UString, UString>& get_env_variables () = 0;
diff --git a/src/main.cc b/src/main.cc
index a9da383..abb5e4a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -23,6 +23,7 @@
*See COPYRIGHT file copyright information.
*/
#include <signal.h>
+#include <unistd.h>
#include <iostream>
#include <gtkmm/window.h>
#include <libglademm.h>
@@ -55,6 +56,7 @@ static bool gv_last_session=false;
static gchar *gv_log_domains=0;
static bool gv_log_debugger_output=false;
static bool gv_show_version=false;
+static bool gv_use_launch_terminal=false;
static GOptionEntry entries[] =
{
@@ -124,6 +126,14 @@ static GOptionEntry entries[] =
_("Log the debugger output"),
NULL
},
+ { "use-launch-terminal",
+ 0,
+ 0,
+ G_OPTION_ARG_NONE,
+ &gv_use_launch_terminal,
+ _("Use this terminal as the debugee's terminal"),
+ NULL
+ },
{ "version",
0,
0,
@@ -330,6 +340,7 @@ process_gui_options (int& a_argc, char** a_argv)
<< endl;
return false;
} else {
+ debug_persp->uses_launch_terminal (gv_use_launch_terminal);
debug_persp->attach_to_program (pid);
}
}
@@ -368,6 +379,7 @@ process_gui_options (int& a_argc, char** a_argv)
list<ISessMgr::Session>& sessions =
debug_persp->session_manager ().sessions ();
bool found_session=false;
+ debug_persp->uses_launch_terminal (gv_use_launch_terminal);
for (session_iter = sessions.begin ();
session_iter != sessions.end ();
++session_iter) {
@@ -398,6 +410,7 @@ process_gui_options (int& a_argc, char** a_argv)
list<ISessMgr::Session>& sessions =
debug_persp->session_manager ().sessions ();
if (!sessions.empty ()) {
+ debug_persp->uses_launch_terminal (gv_use_launch_terminal);
list<ISessMgr::Session>::iterator session_iter,
latest_session_iter;
glong time_val = 0;
@@ -457,10 +470,12 @@ process_gui_options (int& a_argc, char** a_argv)
env[name] = value;
}
}
- if (!prog_path.empty ())
+ if (!prog_path.empty ()) {
+ debug_persp->uses_launch_terminal (gv_use_launch_terminal);
debug_persp->execute_program (prog_path,
prog_args,
env);
+ }
} else {
cerr << "Could not find the debugger perspective plugin\n";
return false;
@@ -486,7 +501,6 @@ main (int a_argc, char *a_argv[])
return -1;
}
-
//********************************************
//load and init the workbench dynamic module
//********************************************
@@ -508,6 +522,32 @@ main (int a_argc, char *a_argv[])
//intercept ctrl-c/SIGINT
signal (SIGINT, sigint_handler);
+
+ if (gv_use_launch_terminal) {
+ // So the user wants the inferior to use the terminal Nemiver was
+ // launched from, for input/output.
+ //
+ // Letting the inferior use the terminal from which Nemiver was
+ // launched from implies calling the "set inferior-tty" GDB command,
+ // when we are using the GDB backend.
+ // That command is implemented using the TIOCSCTTY ioctl. It sets the
+ // terminal as the controlling terminal of the inferior process. But that
+ // ioctl requires (among other things) that the terminal shall _not_ be
+ // the controlling terminal of any other process in another process
+ // session already. Otherwise, GDB spits the error:
+ // "GDB: Failed to set controlling terminal: operation not
+ // permitted"
+ // The problem is, Nemiver itself uses that terminal as a
+ // controlling terminal. So Nemiver itself must relinquish its
+ // controlling terminal to avoid letting the ioctl fail.
+ // We do so by calling the setsid function below.
+ // The problem is that setsid will fail with EPERM if Nemiver is
+ // started as a process group leader already.
+ // Trying ioctl (tty_fd, TIOCNOTTY, 0) does not seem to properly
+ // disconnect Nemiver from its terminal either. Sigh.
+ setsid ();
+ }
+
gtk_kit.run (s_workbench->get_root_window ());
NEMIVER_CATCH_NOX
diff --git a/src/persp/dbgperspective/glade/preferencesdialog.glade b/src/persp/dbgperspective/glade/preferencesdialog.glade
index 5047e7b..d5f53b3 100644
--- a/src/persp/dbgperspective/glade/preferencesdialog.glade
+++ b/src/persp/dbgperspective/glade/preferencesdialog.glade
@@ -217,6 +217,46 @@
</packing>
</child>
<child>
+ <widget class="GtkFrame" id="frame6">
+ <property name="visible">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">GTK_SHADOW_NONE</property>
+ <child>
+ <widget class="GtkAlignment" id="alignment7">
+ <property name="visible">True</property>
+ <property name="top_padding">6</property>
+ <property name="left_padding">12</property>
+ <child>
+ <widget class="GtkCheckButton" id="launchterminalcheckbutton">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Use launch terminal</property>
+ <property name="use_underline">True</property>
+ <property name="response_id">0</property>
+ <property name="active">False</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label10">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes"><b>Terminal</b></property>
+ <property name="use_markup">True</property>
+ </widget>
+ <packing>
+ <property name="type">label_item</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkFrame" id="frame4">
<property name="visible">True</property>
<property name="label_xalign">0</property>
diff --git a/src/persp/dbgperspective/nmv-conf-keys.h b/src/persp/dbgperspective/nmv-conf-keys.h
index a648255..d95ab30 100644
--- a/src/persp/dbgperspective/nmv-conf-keys.h
+++ b/src/persp/dbgperspective/nmv-conf-keys.h
@@ -38,6 +38,7 @@ extern const char* CONF_KEY_SOURCE_FILE_ENCODING_LIST;
extern const char* CONF_KEY_USE_SYSTEM_FONT;
extern const char* CONF_KEY_CUSTOM_FONT_NAME;
extern const char* CONF_KEY_SYSTEM_FONT_NAME;
+extern const char* CONF_KEY_USE_LAUNCH_TERMINAL;
extern const char* CONF_KEY_STATUS_WIDGET_MINIMUM_WIDTH;
extern const char* CONF_KEY_STATUS_WIDGET_MINIMUM_HEIGHT;
extern const char* CONF_KEY_STATUS_PANE_LOCATION;
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.cc b/src/persp/dbgperspective/nmv-dbg-perspective.cc
index b3e5ad2..afc1f2f 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.cc
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.cc
@@ -151,6 +151,8 @@ const char* CONF_KEY_CUSTOM_FONT_NAME=
"/apps/nemiver/dbgperspective/custom-font-name";
const char* CONF_KEY_SYSTEM_FONT_NAME=
"/desktop/gnome/interface/monospace_font_name";
+const char* CONF_KEY_USE_LAUNCH_TERMINAL =
+ "/apps/nemiver/dbgperspective/use-launch-terminal";
const char* CONF_KEY_STATUS_WIDGET_MINIMUM_WIDTH=
"/apps/nemiver/dbgperspective/status-widget-minimum-width";
const char* CONF_KEY_STATUS_WIDGET_MINIMUM_HEIGHT=
@@ -634,6 +636,8 @@ public:
Gtk::Box& get_terminal_box ();
+ UString get_terminal_name ();
+
Gtk::ScrolledWindow& get_breakpoints_scrolled_win ();
BreakpointsView& get_breakpoints_view ();
@@ -680,6 +684,11 @@ public:
void unset_where ();
Gtk::Widget* get_contextual_menu ();
+
+ bool uses_launch_terminal () const;
+
+ void uses_launch_terminal (bool a_flag);
+
Gtk::Widget* get_call_stack_menu ();
void read_default_config ();
@@ -857,6 +866,7 @@ struct DBGPerspective::Priv {
bool enable_syntax_highlight;
UString custom_font_name;
UString system_font_name;
+ bool use_launch_terminal;
#ifdef WITH_SOURCEVIEWMM2
Glib::RefPtr<gtksourceview::SourceStyleScheme> editor_style;
#endif // WITH_SOURCEVIEWMM2
@@ -922,6 +932,7 @@ struct DBGPerspective::Priv {
confirm_before_reload_source (true),
allow_auto_reload_source (true),
enable_syntax_highlight (true),
+ use_launch_terminal (false),
mouse_in_source_editor_x (0),
mouse_in_source_editor_y (0),
in_show_var_value_at_pos_transaction (false),
@@ -2046,6 +2057,11 @@ DBGPerspective::on_conf_key_changed_signal (const UString &a_key,
if (m_priv->use_system_font && !m_priv->system_font_name.empty ()) {
m_priv->modify_source_editor_fonts (m_priv->system_font_name);
}
+ } else if (a_key == CONF_KEY_USE_LAUNCH_TERMINAL) {
+ m_priv->use_launch_terminal = boost::get<bool> (a_value);
+ if (m_priv->debugger_engine_alive) {
+ debugger ()->set_tty_path (get_terminal_name ());
+ }
#ifdef WITH_SOURCEVIEWMM2
} else if (a_key == CONF_KEY_EDITOR_STYLE_SCHEME) {
UString style_id = boost::get<UString> (a_value);
@@ -4091,6 +4107,21 @@ DBGPerspective::get_contextual_menu ()
return m_priv->contextual_menu;
}
+bool
+DBGPerspective::uses_launch_terminal () const
+{
+ THROW_IF_FAIL (m_priv);
+ return m_priv->use_launch_terminal;
+}
+
+void
+DBGPerspective::uses_launch_terminal (bool a_flag)
+{
+ THROW_IF_FAIL (m_priv);
+ m_priv->use_launch_terminal = a_flag;
+}
+
+
ThreadList&
DBGPerspective::get_thread_list ()
{
@@ -4271,6 +4302,8 @@ DBGPerspective::read_default_config ()
m_priv->custom_font_name);
conf_mgr.get_key_value (CONF_KEY_SYSTEM_FONT_NAME,
m_priv->system_font_name);
+ conf_mgr.get_key_value (CONF_KEY_USE_LAUNCH_TERMINAL,
+ m_priv->use_launch_terminal);
NEMIVER_CATCH_NOX
#ifdef WITH_SOURCEVIEWMM2
@@ -5453,7 +5486,7 @@ DBGPerspective::execute_program
LOG_DD ("load program");
// now really load the inferior program (i.e: the one to be debugged)
dbg_engine->load_program (prog, a_args, a_cwd, source_search_dirs,
- get_terminal ().slave_pts_name ());
+ get_terminal_name ());
m_priv->debugger_engine_alive = true;
@@ -5548,7 +5581,7 @@ DBGPerspective::attach_to_program (unsigned int a_pid,
return;
}
if (!debugger ()->attach_to_target (a_pid,
- get_terminal ().slave_pts_name ())) {
+ get_terminal_name ())) {
ui_utils::display_warning (_("You cannot attach to the "
"underlying debugger engine"));
}
@@ -6729,6 +6762,16 @@ DBGPerspective::get_terminal_box ()
return *m_priv->terminal_box;
}
+UString
+DBGPerspective::get_terminal_name ()
+{
+ if (uses_launch_terminal () && isatty (0)) {
+ return ttyname (0);
+ } else {
+ return get_terminal ().slave_pts_name ();
+ }
+}
+
Gtk::ScrolledWindow&
DBGPerspective::get_breakpoints_scrolled_win ()
{
diff --git a/src/persp/dbgperspective/nmv-dbg-perspective.h b/src/persp/dbgperspective/nmv-dbg-perspective.h
index 8ed822f..4d1db34 100644
--- a/src/persp/dbgperspective/nmv-dbg-perspective.h
+++ b/src/persp/dbgperspective/nmv-dbg-perspective.h
@@ -160,6 +160,10 @@ public:
virtual Gtk::Widget* get_contextual_menu () = 0;
+ virtual bool uses_launch_terminal () const = 0;
+
+ virtual void uses_launch_terminal (bool a_flag) = 0;
+
virtual sigc::signal<void, bool>& activated_signal () = 0;
virtual sigc::signal<void, bool>& debugger_ready_signal () = 0;
diff --git a/src/persp/dbgperspective/nmv-preferences-dialog.cc b/src/persp/dbgperspective/nmv-preferences-dialog.cc
index 661eb6a..abbc255 100644
--- a/src/persp/dbgperspective/nmv-preferences-dialog.cc
+++ b/src/persp/dbgperspective/nmv-preferences-dialog.cc
@@ -81,6 +81,7 @@ public:
Gtk::CellRendererText m_style_name_renderer;
Gtk::HBox *custom_font_box;
Gtk::CheckButton *show_lines_check_button;
+ Gtk::CheckButton *launch_terminal_check_button;
Gtk::CheckButton *highlight_source_check_button;
Gtk::RadioButton *always_reload_radio_button;
Gtk::RadioButton *never_reload_radio_button;
@@ -96,6 +97,7 @@ public:
custom_font_button (0),
custom_font_box (0),
show_lines_check_button (0),
+ launch_terminal_check_button (0),
highlight_source_check_button (0),
always_reload_radio_button (0),
never_reload_radio_button (0),
@@ -159,6 +161,11 @@ public:
update_show_source_line_numbers_key ();
}
+ void on_launch_terminal_toggled_signal ()
+ {
+ update_use_launch_terminal_key ();
+ }
+
void on_highlight_source_toggled_signal ()
{
update_highlight_source_keys ();
@@ -229,6 +236,15 @@ public:
(*this,
&PreferencesDialog::Priv::on_show_lines_toggled_signal));
+ launch_terminal_check_button =
+ ui_utils::get_widget_from_glade<Gtk::CheckButton>
+ (glade, "launchterminalcheckbutton");
+ THROW_IF_FAIL (launch_terminal_check_button);
+ launch_terminal_check_button->signal_toggled ().connect
+ (sigc::mem_fun
+ (*this,
+ &PreferencesDialog::Priv::on_launch_terminal_toggled_signal));
+
highlight_source_check_button =
ui_utils::get_widget_from_glade<Gtk::CheckButton>
(glade, "highlightsourcecheckbutton");
@@ -384,6 +400,14 @@ public:
(CONF_KEY_SHOW_SOURCE_LINE_NUMBERS, is_on);
}
+ void update_use_launch_terminal_key ()
+ {
+ THROW_IF_FAIL (launch_terminal_check_button);
+ bool is_on = launch_terminal_check_button->get_active ();
+ conf_manager ().set_key_value
+ (CONF_KEY_USE_LAUNCH_TERMINAL, is_on);
+ }
+
void update_highlight_source_keys ()
{
THROW_IF_FAIL (highlight_source_check_button);
@@ -455,13 +479,14 @@ public:
void update_widget_from_editor_keys ()
{
THROW_IF_FAIL (show_lines_check_button);
+ THROW_IF_FAIL (launch_terminal_check_button);
THROW_IF_FAIL (highlight_source_check_button);
THROW_IF_FAIL (system_font_check_button);
THROW_IF_FAIL (custom_font_button);
THROW_IF_FAIL (custom_font_box);
THROW_IF_FAIL (editor_style_combo);
- bool is_on=true;
+ bool is_on = true;
if (!conf_manager ().get_key_value
(CONF_KEY_SHOW_SOURCE_LINE_NUMBERS, is_on)) {
LOG_ERROR ("failed to get gconf key");
@@ -469,7 +494,15 @@ public:
show_lines_check_button->set_active (is_on);
}
- is_on=true;
+ is_on = false;
+ if (!conf_manager ().get_key_value
+ (CONF_KEY_USE_LAUNCH_TERMINAL, is_on)) {
+ LOG_ERROR ("failed to get gconf key");
+ } else {
+ launch_terminal_check_button->set_active (is_on);
+ }
+
+ is_on = true;
if (!conf_manager ().get_key_value
(CONF_KEY_HIGHLIGHT_SOURCE_CODE, is_on)) {
LOG_ERROR ("failed to get gconf key");
diff --git a/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas b/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas
index 1f6e31d..da1208d 100644
--- a/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas
+++ b/src/persp/dbgperspective/schemas/nemiver-dbgperspective.schemas
@@ -93,6 +93,18 @@
</locale>
</schema>
<schema>
+ <key>/schemas/apps/nemiver/dbgperspective/use-launch-terminal</key>
+ <applyto>/apps/nemiver/dbgperspective/use-launch-terminal</applyto>
+ <owner>nemiver</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short>Whether to use the terminal we were launched from</short>
+ <long>Whether to use the terminal we were launched from as
+ the debuggee's terminal, or to use our own embedded terminal.</long>
+ </locale>
+ </schema>
+ <schema>
<key>/schemas/apps/nemiver/dbgperspective/editor-style-scheme</key>
<applyto>/apps/nemiver/dbgperspective/editor-style-scheme</applyto>
<owner>nemiver</owner>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]