[Nemiver-list] Saving / restoring environment variables with a session
- From: "Jonathon Jongsma" <jonathon jongsma domain hid>
- To: nemiver-list domain hid
- Subject: [Nemiver-list] Saving / restoring environment variables with a session
- Date: Sun, 24 Sep 2006 22:12:29 -0500
I thought I'd send this out as a patch instead of committing it right
away because it involves a change to the database, and I wanted to
make sure it looked ok to you before making you update or delete your
old session database. All it does is create a new table called
env_variables that stores the name/value pairs for environment
variables associated with a session ID. These are saved on exit and
loaded when a session is loaded.
OK to commit? Also, would it be a good idea to make a little database
upgrade script for cases like this in the future?
--
jonner
Index: src/DBGPerspective/nmv-sess-mgr.h
===================================================================
--- src/DBGPerspective/nmv-sess-mgr.h (revision 111)
+++ src/DBGPerspective/nmv-sess-mgr.h (working copy)
@@ -86,6 +86,7 @@
class Session {
gint64 m_session_id ;
map<UString, UString> m_properties ;
+ map<UString, UString> m_env_variables ;
list<BreakPoint> m_breakpoints ;
list<UString> m_opened_files ;
@@ -104,6 +105,9 @@
const map<UString, UString>& properties () const {return m_properties;}
map<UString, UString>& properties () {return m_properties;}
+ const map<UString, UString>& env_variables () const {return m_env_variables;}
+ map<UString, UString>& env_variables () {return m_env_variables;}
+
list<BreakPoint>& breakpoints () {return m_breakpoints;}
const list<BreakPoint>& breakpoints () const
{
Index: src/DBGPerspective/nmv-dbg-perspective.cc
===================================================================
--- src/DBGPerspective/nmv-dbg-perspective.cc (revision 111)
+++ src/DBGPerspective/nmv-dbg-perspective.cc (working copy)
@@ -386,6 +386,7 @@
UString prog_name ;
UString prog_args ;
UString prog_cwd ;
+ map<UString, UString> env_variables ;
Glib::RefPtr<Gtk::ActionGroup> target_connected_action_group ;
Glib::RefPtr<Gtk::ActionGroup> debugger_ready_action_group ;
Glib::RefPtr<Gtk::ActionGroup> debugger_busy_action_group ;
@@ -1732,6 +1733,7 @@
a_session.properties ()[PROGRAM_NAME] = m_priv->prog_name ;
a_session.properties ()[PROGRAM_ARGS] = m_priv->prog_args ;
a_session.properties ()[PROGRAM_CWD] = m_priv->prog_cwd ;
+ a_session.env_variables () = m_priv->env_variables;
map<UString, int>::const_iterator path_iter =
m_priv->path_2_pagenum_map.begin () ;
@@ -1974,10 +1976,9 @@
DBGPerspective::execute_session (ISessMgr::Session &a_session)
{
m_priv->session = a_session ;
- map<UString, UString> env ;//TODO: get env from session
execute_program (a_session.properties ()[PROGRAM_NAME],
a_session.properties ()[PROGRAM_ARGS],
- env,
+ a_session.env_variables (),
a_session.properties ()[PROGRAM_CWD]) ;
m_priv->reused_session = true ;
}
@@ -1987,6 +1988,12 @@
{
RunProgramDialog dialog (plugin_path ()) ;
+ // set defaults from session
+ dialog.program_name (m_priv->prog_name) ;
+ dialog.arguments (m_priv->prog_args) ;
+ dialog.working_directory (m_priv->prog_cwd) ;
+ dialog.environment_variables (m_priv->env_variables) ;
+
int result = dialog.run () ;
if (result != Gtk::RESPONSE_OK) {
return;
@@ -1998,8 +2005,8 @@
args = dialog.arguments () ;
cwd = dialog.working_directory () ;
THROW_IF_FAIL (cwd != "") ;
+ map<UString, UString> env = dialog.environment_variables();
- map<UString, UString> env = dialog.environment_variables();
execute_program (prog, args, env, cwd) ;
m_priv->reused_session = false ;
}
@@ -2048,6 +2055,7 @@
m_priv->prog_name = a_prog ;
m_priv->prog_args = a_args ;
m_priv->prog_cwd = a_cwd ;
+ m_priv->env_variables = a_env ;
NEMIVER_CATCH
}
Index: src/DBGPerspective/nmv-sess-mgr.cc
===================================================================
--- src/DBGPerspective/nmv-sess-mgr.cc (revision 111)
+++ src/DBGPerspective/nmv-sess-mgr.cc (working copy)
@@ -228,6 +228,24 @@
THROW_IF_FAIL (trans.get ().get_connection ().execute_statement (query));
}
+ //store the environment variables
+ query = "delete from env_variables where sessionid = "
+ + UString::from_int (a_session.session_id ()) ;
+ THROW_IF_FAIL (trans.get ().get_connection ().execute_statement (query));
+
+ map<UString, UString>::const_iterator var_iter ;
+ for (var_iter = a_session.env_variables ().begin ();
+ var_iter != a_session.env_variables ().end ();
+ ++var_iter) {
+ query = "insert into env_variables values(NULL, "
+ + UString::from_int (a_session.session_id ()) + ", '"
+ + var_iter->first + "', '"
+ + var_iter->second
+ + "')"
+ ;
+ THROW_IF_FAIL (trans.get ().get_connection ().execute_statement (query));
+ }
+
//store the breakpoints
query = "delete from breakpoints where sessionid = "
+ UString::from_int (a_session.session_id ()) ;
@@ -305,6 +323,18 @@
session.properties ()[name] = value ;
}
+ //load the environment variables
+ query="select env_variables.name, env_variables.value "
+ "from env_variables where env_variables.sessionid = "
+ + UString::from_int (a_session.session_id ());
+ THROW_IF_FAIL (trans.get ().get_connection ().execute_statement (query)) ;
+ while (trans.get ().get_connection ().read_next_row ()) {
+ UString name, value ;
+ THROW_IF_FAIL (trans.get ().get_connection ().get_column_content (0, name)) ;
+ THROW_IF_FAIL (trans.get ().get_connection ().get_column_content (1, value)) ;
+ session.env_variables ()[name] = value ;
+ }
+
//load the breakpoints
query = "select breakpoints.filename, breakpoints.linenumber from "
"breakpoints where breakpoints.sessionid = "
Index: src/DBGPerspective/sqlscripts/sqlite/create-tables.sql
===================================================================
--- src/DBGPerspective/sqlscripts/sqlite/create-tables.sql (revision 111)
+++ src/DBGPerspective/sqlscripts/sqlite/create-tables.sql (working copy)
@@ -4,6 +4,11 @@
create table sessions (id integer primary key) ;
+create table env_variables (id integer primary key,
+ sessionid integer,
+ name text,
+ value text) ;
+
create table attributes (id integer primary key,
sessionid integer,
name text,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]