Skip to content

Commit

Permalink
service/dap: provide process events after launch (go-delve#3902)
Browse files Browse the repository at this point in the history
This change adds support to emit the process DAP event after handling launch
requests
  • Loading branch information
shaunduncan authored Jan 17, 2025
1 parent 0b1ef9b commit 38af36e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
12 changes: 12 additions & 0 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,18 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) {
s.mu.Lock()
defer s.mu.Unlock() // Make sure to unlock in case of panic that will become internal error
s.debugger, err = debugger.New(&s.config.Debugger, s.config.ProcessArgs)

if s.debugger != nil {
s.send(&dap.ProcessEvent{
Event: *newEvent("process"),
Body: dap.ProcessEventBody{
Name: s.debugger.Target().CmdLine,
SystemProcessId: s.debugger.ProcessPid(),
IsLocalProcess: true,
StartMethod: "launch",
},
})
}
}()
if err != nil {
if s.binaryToRemove != "" {
Expand Down
27 changes: 25 additions & 2 deletions service/dap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func TestStopWithTarget(t *testing.T) {
client.ExpectInitializeResponseAndCapabilities(t)
fixture := protest.BuildFixture("increment", protest.AllNonOptimized)
client.LaunchRequest("debug", fixture.Source, stopOnEntry)
client.ExpectProcessEvent(t)
client.ExpectInitializedEvent(t)
client.ExpectLaunchResponse(t)
triggerStop(client, forceStop)
Expand Down Expand Up @@ -304,6 +305,7 @@ func TestSessionStop(t *testing.T) {
client.ExpectInitializeResponseAndCapabilities(t)
fixture := protest.BuildFixture("increment", protest.AllNonOptimized)
client.LaunchRequest("debug", fixture.Source, stopOnEntry)
client.ExpectProcessEvent(t)
client.ExpectInitializedEvent(t)
client.ExpectLaunchResponse(t)
stopSession(session, client, serveDAPCodecDone)
Expand All @@ -321,6 +323,7 @@ func TestForceStopWhileStopping(t *testing.T) {
client.ExpectInitializeResponseAndCapabilities(t)
fixture := protest.BuildFixture("increment", protest.AllNonOptimized)
client.LaunchRequest("exec", fixture.Path, stopOnEntry)
client.ExpectProcessEvent(t)
client.ExpectInitializedEvent(t)
client.Close() // depending on timing may trigger Stop()
time.Sleep(time.Microsecond)
Expand All @@ -335,6 +338,7 @@ func TestForceStopWhileStopping(t *testing.T) {
// User selects "Start Debugging": 1 >> initialize
// : 1 << initialize
// : 2 >> launch
// : << process event
// : << initialized event
// : 2 << launch
// : 3 >> setBreakpoints (empty)
Expand Down Expand Up @@ -375,8 +379,14 @@ func TestLaunchStopOnEntry(t *testing.T) {
t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=1", initResp)
}

// 2 >> launch, << initialized, << launch
// 2 >> launch, << process, << initialized, << launch
client.LaunchRequest("exec", fixture.Path, stopOnEntry)

processEvent := client.ExpectProcessEvent(t)
if processEvent.Seq != 0 {
t.Errorf("\ngot %#v\nwant Seq=0", processEvent)
}

initEvent := client.ExpectInitializedEvent(t)
if initEvent.Seq != 0 {
t.Errorf("\ngot %#v\nwant Seq=0", initEvent)
Expand Down Expand Up @@ -634,6 +644,7 @@ func TestContinueOnEntry(t *testing.T) {

// 2 >> launch, << initialized, << launch
client.LaunchRequest("exec", fixture.Path, !stopOnEntry)
client.ExpectProcessEvent(t)
client.ExpectInitializedEvent(t)
client.ExpectLaunchResponse(t)

Expand Down Expand Up @@ -682,6 +693,7 @@ func TestPreSetBreakpoint(t *testing.T) {
client.ExpectInitializeResponseAndCapabilities(t)

client.LaunchRequest("exec", fixture.Path, !stopOnEntry)
client.ExpectProcessEvent(t)
client.ExpectInitializedEvent(t)
client.ExpectLaunchResponse(t)

Expand Down Expand Up @@ -3594,6 +3606,7 @@ func TestConcurrentBreakpointsLogPoints(t *testing.T) {
client.ExpectInitializeResponseAndCapabilities(t)

client.LaunchRequest("exec", fixture.Path, !stopOnEntry)
client.ExpectProcessEvent(t)
client.ExpectInitializedEvent(t)
client.ExpectLaunchResponse(t)

Expand Down Expand Up @@ -5281,6 +5294,11 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm
client.ExpectInitializeResponseAndCapabilities(t)

cmdRequest()

if cmd == "launch" {
client.ExpectProcessEvent(t)
}

client.ExpectInitializedEvent(t)
switch cmd {
case "launch":
Expand Down Expand Up @@ -5470,6 +5488,7 @@ func TestExitNonZeroStatus(t *testing.T) {
client.ExpectInitializeResponseAndCapabilities(t)

client.LaunchRequest("exec", fixture.Path, !stopOnEntry)
client.ExpectProcessEvent(t)
client.ExpectInitializedEvent(t)
client.ExpectLaunchResponse(t)

Expand Down Expand Up @@ -7586,13 +7605,17 @@ func TestRedirect(t *testing.T) {
t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=1", initResp)
}

// 2 >> launch, << initialized, << launch
// 2 >> launch, << process, << initialized, << launch
client.LaunchRequestWithArgs(map[string]interface{}{
"request": "launch",
"mode": "debug",
"program": fixture.Source,
"outputMode": "remote",
})
processEvent := client.ExpectProcessEvent(t)
if processEvent.Seq != 0 {
t.Errorf("\ngot %#v\nwant Seq=0", processEvent)
}
initEvent := client.ExpectInitializedEvent(t)
if initEvent.Seq != 0 {
t.Errorf("\ngot %#v\nwant Seq=0", initEvent)
Expand Down

0 comments on commit 38af36e

Please sign in to comment.