From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Martin M. Hunt" To: Insight Mailing List Subject: [RFA] run button problems Date: Mon, 17 Dec 2001 23:57:00 -0000 Message-ID: <200112180755.XAA29816@cygnus.com> X-SW-Source: 2001-q4/msg00425.html Message-ID: <20011217235700.AD-7OPPVjvB4Xb7m2SWgASicxtRafFz3MBv6V4S6DGQ@z> Some people (like me) do both native and remote debugging. If you attempt to do so, you cannot just hit the RUN button and expect the right thing to happen. This is because the run_load, run_attach, run_run, and run_cont preferences are changed. To make things work, I had to make them session-dependent. Rather than make lots of changes all over the place, I just modified session.tcl to load the old preferences variables as new sessions are loaded. I also fixed the run button so that if you click it while a program is being debugged, you get a dialog that allows you to restart your debug session or cancel. Also, it can take a long time to connect to a remote target, especially if it isn't responding, so change the RUN botton to the STOP sign so the user can cancel the connect. If the user does cancel, the target dialog pops up again. Finally, it the user wants to set a BP on exit, and that fails, then display an ignoreable warning. -- Martin Hunt GDB Engineer Red Hat, Inc. 2001-12-17 Martin M. Hunt * library/session.tcl (session_notice_file_change): Reset target run prefs back to defaults then load per-session values if available. (session_save): Save target run prefs per-session. * library/interface.tcl (set_target): Don't detach from remote targets. Call gdbtk_busy before the target command and gdbtk_idle after. (run_executable): If target is unchanged, ask user what to do. Display warning if break on exit fails. Index: library/interface.tcl =================================================================== RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v retrieving revision 1.35 diff -u -p -r1.35 interface.tcl --- interface.tcl 2001/12/11 08:55:52 1.35 +++ interface.tcl 2001/12/18 07:33:06 @@ -1085,10 +1085,15 @@ proc set_target {} { $srcWin set_status "Trying to communicate with target $gdb_pretty_name" 1 update - catch {gdb_cmd "detach"} + + # Why would you want to detach?? + # catch {gdb_cmd "detach"} + debug "CONNECTING TO TARGET: $gdb_target_cmd" + gdbtk_busy set err [catch {gdb_immediate "target $gdb_target_cmd"} msg ] $srcWin set_status + gdbtk_idle if {$err} { if {[string first "Program not killed" $msg] != -1} { @@ -1149,9 +1154,28 @@ proc run_executable { {auto_start 1} } { # Attach if {$gdb_target_name == "" || [pref get gdb/src/run_attach]} { - if {[gdbtk_attach_remote] == "ATTACH_CANCELED"} { + set r [gdbtk_attach_remote] + if { $r == "ATTACH_CANCELED" || $r == "ATTACH_ERROR"} { return } + + # + if {$r == "ATTACH_TARGET_UNCHANGED"} { + set msg "A program is being debugged already.\n" + append msg "Do you want to select another target?" + if {[gdbtk_tcl_query $msg no]} { + # YES + set ::gdb_target_name "" + set ::gdb_target_cmd "" + set r [gdbtk_attach_remote] + if { $r == "ATTACH_CANCELED" ||$r == "ATTACH_ERROR"} { + return + } + } else { + # NO + return + } + } } # Download @@ -1183,9 +1207,11 @@ proc run_executable { {auto_start 1} } { if {[pref get gdb/load/exit] && ![TargetSelection::native_debugging]} { debug "Setting new BP at exit" catch {gdb_cmd "clear exit"} - catch {gdb_cmd "break exit"} + if {[catch {gdb_cmd "break exit"} msg]} { + gdbtk_tcl_ignorable_warning break_exit $msg + } } - + if {[pref get gdb/load/main]} { set main "main" if {[set linespec [gdbtk_locate_main]] != ""} { @@ -1242,8 +1268,9 @@ proc run_executable { {auto_start 1} } { dbug W "msg=$msg" gdbtk_idle if {[string match "*help target*" $msg]} { - set_target_name - run_executable $auto_start + if {[set_target_name]} { + run_executable $auto_start + } return } if {[string match "No executable*" $msg]} { @@ -1490,7 +1517,7 @@ proc gdbtk_stop {} { # This callback normally does nothing. When the stop button has # been pressed, though, and gdb has successfully stopped the target, # this callback will clean up after gdbtk_stop, removing the "Detach" -# dialog (if it's open) and gettingg rid of any outstanding timers +# dialog (if it's open) and getting rid of any outstanding timers # and hooks. proc gdbtk_stop_idle_callback {} { global _gdbtk_stop gdbtk_state @@ -1574,7 +1601,7 @@ proc set_baud {} { if {$baud == ""} { set baud [pref get gdb/load/baud] } -# debug "setting baud to $baud" + # debug "setting baud to $baud" catch {gdb_cmd "set remotebaud $baud"} } @@ -1589,26 +1616,28 @@ proc do_state_hook {varname ind op} { # PROC: gdbtk_disconnect - # ------------------------------------------------------------------ proc gdbtk_disconnect {{async 0}} { - global gdb_loaded gdb_target_changed - catch {gdb_cmd "detach"} - # force a new target command to do something - set gdb_loaded 0 - set gdb_target_changed 1 - set gdb_running 0 - gdbtk_idle - gdbtk_update - } + global gdb_loaded gdb_target_changed + + # Why is this needed? + #catch {gdb_cmd "detach"} + # force a new target command to do something + set gdb_loaded 0 + set gdb_target_changed 1 + set gdb_running 0 + gdbtk_idle + gdbtk_update +} # ------------------------------------------------------------------ # PROC: tstart - # ------------------------------------------------------------------ proc tstart {} { - if {[catch {gdb_cmd "tstart"} errTxt]} { - tk_messageBox -title "Error" -message $errTxt -icon error \ - -type ok + if {[catch {gdb_cmd "tstart"} errTxt]} { + tk_messageBox -title "Error" -message $errTxt -icon error \ + -type ok gdbtk_idle - return 0 - } + return 0 + } return 1 } @@ -1616,15 +1645,14 @@ proc tstart {} { # PROC: tstop - # ------------------------------------------------------------------ proc tstop {} { - - if {[catch {gdb_cmd "tstop"} errTxt]} { - tk_messageBox -title "Error" -message $errTxt -icon error \ - -type ok - gdbtk_idle - return 0 - } - return 1 - } + if {[catch {gdb_cmd "tstop"} errTxt]} { + tk_messageBox -title "Error" -message $errTxt -icon error \ + -type ok + gdbtk_idle + return 0 + } + return 1 +} # ------------------------------------------------------------------ # PROC: source_file - Index: library/session.tcl =================================================================== RCS file: /cvs/src/src/gdb/gdbtk/library/session.tcl,v retrieving revision 1.9 diff -u -p -r1.9 session.tcl --- session.tcl 2001/10/28 20:08:39 1.9 +++ session.tcl 2001/12/18 07:33:06 @@ -143,6 +150,12 @@ proc session_save {} { set values(pwd) $gdb_current_directory set values(target) $gdb_target_name + # these prefs need to be made session-dependent + set values(run_attach) [pref get gdb/src/run_attach] + set values(run_load) [pref get gdb/src/run_load] + set values(run_run) [pref get gdb/src/run_run] + set values(run_cont) [pref get gdb/src/run_cont] + # Breakpoints. set values(breakpoints) [SESSION_serialize_bps] @@ -201,6 +214,12 @@ proc session_notice_file_change {} { set values($k) [pref getd $key/$k] } + # reset these back to their defaults + pref set gdb/src/run_attach 0 + pref set gdb/src/run_load 0 + pref set gdb/src/run_run 1 + pref set gdb/src/run_cont 0 + if {! [info exists values(executable)] || $values(executable) != $name} { # No such session. return @@ -230,6 +249,13 @@ proc session_notice_file_change {} { debug "Restoring Target: $values(target)" set gdb_target_name $values(target) } + + if {[info exists values(run_attach)]} { + pref set gdb/src/run_attach $values(run_attach) + pref set gdb/src/run_load $values(run_load) + pref set gdb/src/run_run $values(run_run) + pref set gdb/src/run_cont $values(run_cont) + } } #