Support for "remote" debugging.

[DEVELOPMENT ENVIRONMENT]
* NEW: Update French translation.
* NEW: A new debugger feature that allows to debug "remotely", i.e. debug a process not run by the IDE,
  provided of course that it comes from the same project.
This commit is contained in:
gambas 2021-10-20 02:37:36 +02:00
parent 85cbb94625
commit 1b5b92da72
8 changed files with 594 additions and 627 deletions

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
Public Startup As String
Public Enum ACTION_RUN, ACTION_RUN_WITH, ACTION_STEP, ACTION_FORWARD, ACTION_RETURN_FROM
Public Enum ACTION_RUN, ACTION_RUN_WITH, ACTION_STEP, ACTION_FORWARD, ACTION_RETURN_FROM, ACTION_RUN_REMOTE
Private Const STATE_LAST As Integer = -1
Private Const STATE_STOP As Integer = 0
@ -14,6 +14,7 @@ Private $bTest As Boolean
Private $iState As Integer
Private $hProcess As Process
Private $hObserver As Observer
'Private $bRunRemote As Boolean
Private $sPosClass As String
Private $iPosLine As Integer
@ -51,6 +52,10 @@ Private $iProcessId As Integer
Private $hTimerShowConsole As Timer
Private $bRemote As Boolean
Private $sRemoteLink As String
Private $hTimerRemote As Timer
Public Sub Init()
$sFifo = Debug.Begin()
@ -98,15 +103,15 @@ Private Sub SetState(iState As Integer)
'bDebug = $iState <> STATE_STOP And $iState <> STATE_STARTING
Action["run-remote"].Enabled = iState = STATE_STOP
Action["pause"].Enabled = iState = STATE_RUNNING
bEnable = iState <> STATE_RUNNING And iState <> STATE_STARTING
Action["forward"].Enabled = bEnable
Action["step"].Enabled = bEnable
Action["return"].Enabled = bEnable And iState <> STATE_STOP
Action["start"].Enabled = bEnable
Action["until"].Enabled = bEnable
Action["stop"].Enabled = iState <> STATE_STOP
'btnInfo.Enabled = btnStop.Enabled
If iState = $iState Then Return
@ -135,11 +140,10 @@ Public Sub Pause()
If $iState <> STATE_RUNNING Then Return
If Project.UseTerminal Then
If $iProcessId Then Signal.Send($iProcessId, Signal.SIGUSR2)
Else
Signal.Send($hProcess.Id, Signal.SIGUSR2)
Endif
' If Project.UseTerminal Then
' If $iProcessId Then Signal.Send($iProcessId, Signal.SIGUSR2)
' Else
If $iProcessId Then Signal.Send($iProcessId, Signal.SIGUSR2)
End
@ -535,6 +539,14 @@ Private Sub AfterStop()
If Not $bConsole Then FMain.ShowDebug(False, True)
FDebugInfo.UpdateView
If $bRemote Then
$hTimerRemote.Stop
$hTimerRemote = Null
Try Kill $sRemoteLink
FDebugInfo.StopWaitForRemote
$bRemote = False
Endif
' FOR EACH hForm IN $cShow
' 'TRY PRINT "Design.AfterStop: SHOW "; hForm.Name
@ -562,8 +574,10 @@ Public Sub Stop()
'Try $hBrowser.Kill
'$hBrowser = Null
Try $hProcess.Kill
$hProcess.Wait(1)
If $hProcess Then
Try $hProcess.Kill
$hProcess.Wait(1)
Endif
AfterStop
End
@ -1182,6 +1196,102 @@ Private Sub Start(sCmd As String)
End
Public Sub RunRemote()
Dim hForm As Object
Dim sBreakpoint As String
Dim sDir As String
Dim hStat As Stat
If Project.Running Then Return
sDir = File.Dir(Temp$())
$sRemoteLink = "/tmp/gambas-" & Project.Name & ".debug"
Try hStat = Stat($sRemoteLink)
If hStat And If IsDir(hStat.Link) Then
FMain.ShowErrorWith(("Unable to start remote debugging."), ("Another remote debugging is active."))
Return
Endif
Try Kill $sRemoteLink
Try Link sDir To $sRemoteLink
If Error Then
FMain.ShowErrorWith(("Unable to start remote debugging."))
Return
Endif
$bConsole = Action["console"].Value
ClearOutput
$iProcessId = 0
$sCmdStart = ""
ReadDebugSettings()
For Each sBreakpoint In $aBreakpoint
If $cDisabledBreakpoint.Exist(sBreakpoint) Then Continue
$sCmdStart &= MakeBreakpoint(sBreakpoint, True) & "\n"
Next
If $sAddBreakpoint Then
$sCmdStart &= $sAddBreakpoint & "\n"
$sAddBreakpoint = ""
Endif
$sCmdStart &= FDebugInfo.GetWatches()
$sCmdStart &= "g"
$bRemote = True
$bStart = True
Project.Running = True
For Each hForm In Project.Workspace.Windows
Try hForm.OnProjectDebug
Next
FOutput.OnProjectDebug
FMain.OnProjectDebug
FSearch.OnProjectDebug
FMain.ShowDebug(True, True)
FDebugInfo.UpdateView
FDebugInfo.OnProjectDebug
FDebugInfo.StartWaitForRemote
FDebugInfo.ShowDebugging
SetState(STATE_STARTING)
Try Debug.Start
If Error Then
FMain.ShowErrorWith(("Unable to start debugger."))
Return
Endif
$hTimerRemote = New Timer As "TimerRemote"
$hTimerRemote.Delay = 500
$hTimerRemote.Start
'
' 'If Project.Profiling Then FProfile.CleanProfileFiles
'
' SetState(STATE_STARTING)
' Balloon.Hide
'
'
End
Public Sub TimerRemote_Timer()
If $iProcessId Then
If Not Exist("/proc" &/ CStr($iProcessId)) Then Stop()
Endif
End
' Public Sub Browser_Kill()
'
' Stop()
@ -1214,7 +1324,7 @@ Public Sub Command(sCmd As String, Optional iNewState As Integer = STATE_LAST)
'IF NOT Project.Running THEN RETURN
'WAIT
If Not $hProcess Then Return
If Not $hProcess And If Not $bRemote Then Return
'IF bResult THEN
' $cCommand.Add(sPrefix & sCmd)
@ -1242,6 +1352,7 @@ Private Sub Signal()
'PRINT "Signal"
If $bStart Then
If $bRemote Then FDebugInfo.StopWaitForRemote
'PRINT "START Debug.Write: "; $sCmdStart
WriteCommand($sCmdStart)
$bStart = False
@ -1322,6 +1433,8 @@ End
Public Sub Send(sStr As String)
If $iState <> STATE_RUNNING Then Return
If Not $hProcess Then Return
Write #$hProcess, sStr
Flush #$hProcess

View file

@ -1458,6 +1458,21 @@ Public Sub OnProjectDebugState()
End
Public Sub StartWaitForRemote()
splDebug.Hide
panRemoteDebug.Show
spnRemoteDebug.Start
End
Public Sub StopWaitForRemote()
spnRemoteDebug.Stop
panRemoteDebug.Hide
splDebug.Show
End
Public Sub ShowDebugging()

View file

@ -22,7 +22,7 @@
Index = 0
Text = ("Debugging")
{ panDebug VBox
MoveScaled(0,3,112,40)
MoveScaled(0,3,119,40)
Expand = True
{ splDebug HSplit
MoveScaled(1,1,94,32)
@ -109,6 +109,27 @@
}
}
}
{ panRemoteDebug Panel
MoveScaled(86,7,32,33)
Visible = False
Expand = True
Arrangement = Arrange.Vertical
Centered = True
Spacing = True
Margin = True
{ spnRemoteDebug Spinner
MoveScaled(10,8,14,6)
Type = Spinner.Circle
}
{ Label1 TextLabel
MoveScaled(4,15,24,4)
Font = Font["Bold"]
Foreground = Color.LightForeground
AutoResize = True
Text = ("Waiting for remote process") & "..."
Alignment = Align.Center
}
}
{ sepError Separator
MoveScaled(35,34,17,0)
Visible = False
@ -312,7 +333,7 @@
MoveScaled(68,0,13,4)
AutoResize = True
Text = ("Add everything to repository")
Picture = Picture["icon:/small/add"]
Picture = Picture["icon:/small/added"]
}
{ Spring1 Spring
MoveScaled(82,0,4,4)

View file

@ -1467,6 +1467,8 @@ Public Sub Action_Activate((Key) As String) As Boolean
Project.Run(False, Design.ACTION_RUN)
Case "run-with"
If Not FArguments.Run() Then Project.Run(False, Design.ACTION_RUN_WITH)
Case "run-remote"
Project.Run(False, Design.ACTION_RUN_REMOTE)
Case "test"
Project.Test()
Case "test-suite"

View file

@ -135,6 +135,19 @@
Picture = Picture["icon:/small/make-all"]
Shortcut = "Alt+F7"
}
{ Menu47 Menu
}
{ mnuTest Menu
Action = "test"
Text = ("Test")
Picture = Picture["icon:/small/ok"]
Shortcut = "F4"
}
{ mnuTestsuites Menu
Action = "test-suite"
Text = ("Test suites") & "..."
Shortcut = "Shift+F4"
}
{ mnuSepCompile Menu
}
{ mnuTranslate Menu
@ -256,18 +269,10 @@
Action = "run-with"
Text = ("Run with") & "..."
}
{ Menu47 Menu
}
{ mnuTest Menu
Action = "test"
Text = ("Test")
Picture = Picture["icon:/small/ok"]
Shortcut = "F4"
}
{ mnuTestsuites Menu
Action = "test-suite"
Text = ("Test suites") & "..."
Shortcut = "Shift+F4"
{ mnuRemoteDebug Menu
Action = "run-remote"
Text = ("Run remotely")
Picture = Picture["icon:/small/connect"]
}
{ Menu14 Menu
}
@ -1262,6 +1267,13 @@
Text = ("Run with") & "..."
Picture = Picture["icon:/small/play"]
}
{ btnRunRemote ToolButton
MoveScaled(104,4,4,4)
Visible = False
ToolTip = ("Run remotely")
Action = "run-remote"
Picture = Picture["icon:/small/connect"]
}
}
{ sepMessage Separator
MoveScaled(58,9,38,0)
@ -1824,6 +1836,11 @@
Shortcut = ""
Picture = "icon:/small/eject"
}
{ Action run-remote
Text = "Run remotely"
Shortcut = ""
Picture = "icon:/small/connect"
}
{ Action run-that
Text = "Run this class"
Shortcut = ""
@ -1945,7 +1962,7 @@
{ Toolbars
{ Toolbar main
Text = ""
List = "new-project,open-project,save-project,save-project-as,project-property,refresh-project,option,shortcut,exec,translate,archive,install,project,property,control,console,find,help,compile,compile-all,test,start,pause,stop,step,forward,return,until,find-project,go-back,go-forward,browse-project,open-terminal,send-mail,publish,farm,gui,menu-file,menu-edit,menu-project,menu-debug,menu-view,menu-tool,menu-help,version-control,run-with"
List = "new-project,open-project,save-project,save-project-as,project-property,refresh-project,option,shortcut,exec,translate,archive,install,project,property,control,console,find,help,compile,compile-all,test,start,pause,stop,step,forward,return,until,find-project,go-back,go-forward,browse-project,open-terminal,send-mail,publish,farm,gui,menu-file,menu-edit,menu-project,menu-debug,menu-view,menu-tool,menu-help,version-control,run-with,run-remote"
Default = "new-project,open-project,save-project,save-project-as,project-property,option,|,exec,translate,|,compile,compile-all,test,start,pause,stop,step,forward,return,until,-,find-project,go-back,go-forward,version-control"
}
}

View file

@ -2664,6 +2664,9 @@ Public Sub Run(Optional bCompileAll As Boolean, Optional iAction As Integer, Opt
Case Design.ACTION_RETURN_FROM
Design.ReturnFrom
Case Design.ACTION_RUN_REMOTE
Design.RunRemote
Case Else
If sStartup Then Design.Startup = sStartup
If iAction = Design.ACTION_RUN Then Project.CurrentArgument = Null

View file

@ -88,7 +88,8 @@ Public Sub btnRevert_Click()
If Message.Warning(("You are going to cancel your changes!"), ("Continue"), ("Cancel")) = 2 Then Return
Project.RevertFile($sPath)
LoadVersionControlInfo
Me.Close
'LoadVersionControlInfo
End