Skip to content
55 changes: 35 additions & 20 deletions desktop/internal/core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,17 @@ type BuildDecodeRunRequest struct {
}

type buildOutcome struct {
Status string `json:"status"`
Error *MarketplaceRejection `json:"error"`
Detection *BuildDetection `json:"detection"`
Plan *BuildPlan `json:"plan"`
Model *BuildModel `json:"model"`
Launch *BuildLaunch `json:"launch"`
Results *BuildTestResults `json:"results"`
Invocation *BuildInvocation `json:"invocation"`
Version *BuildToolVersion `json:"version"`
Status string `json:"status"`
Error *MarketplaceRejection `json:"error"`
Detection *BuildDetection `json:"detection"`
Plan *BuildPlan `json:"plan"`
Model *BuildModel `json:"model"`
Launch *BuildLaunch `json:"launch"`
// Preparation answers build.decodeDebugPreparation.
Preparation *BuildDebugPreparation `json:"preparation"`
Results *BuildTestResults `json:"results"`
Invocation *BuildInvocation `json:"invocation"`
Version *BuildToolVersion `json:"version"`
// Dependencies is the answer of build.decodeDependencies.
Dependencies *BuildDependencyTree `json:"dependencies"`
// Storage and Edit answer build.resolveStoredOptions and build.editStoredOption.
Expand Down Expand Up @@ -443,34 +445,47 @@ func (c *Client) DecodeBuildModel(ctx context.Context, manifest json.RawMessage,
return *result.Model, nil
}

// BuildDecodeDebugRequest validates the raw result of a provider's debug preparation. Native
// debug preparation takes no launch options, so the request carries none.
// BuildDecodeDebugRequest validates the raw result of a provider's debug preparation. Run is
// the run declaration the preparation was planned for, whose `debug.adapter` Core answers.
// Native debug preparation takes no launch options, so the request carries none.
type BuildDecodeDebugRequest struct {
WorkspaceRoot string `json:"workspaceRoot"`
Root string `json:"root"`
Run string `json:"run"`
Result json.RawMessage `json:"result"`
}

// DecodeBuildDebug validates the native debug program a provider prepared, with the process
// facts the host starts it from. It answers the same launch shape as DecodeBuildRun, which the
// Debug host already knows how to start.
func (c *Client) DecodeBuildDebug(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeDebugRequest) (BuildLaunch, error) {
// BuildDebugPreparation is the native debug program a provider prepared, as Core validated it:
// the local ID of the plugin's own adapter the run declares, and the program with its process
// facts. Program and WorkingDirectory are relative to the workspace root.
type BuildDebugPreparation struct {
Adapter string `json:"adapter"`
Root string `json:"root"`
Program string `json:"program"`
Arguments []string `json:"arguments"`
WorkingDirectory string `json:"workingDirectory"`
Environment map[string]string `json:"environment"`
}

// DecodeBuildDebug validates the native debug program a provider prepared
// (`build.decodeDebugPreparation`).
func (c *Client) DecodeBuildDebug(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeDebugRequest) (BuildDebugPreparation, error) {
const command = "build.decodeDebugPreparation"
var result buildOutcome
if err := c.Execute(ctx, command, struct {
Manifest json.RawMessage `json:"manifest"`
BuildSystemID string `json:"buildSystemID"`
Request BuildDecodeDebugRequest `json:"request"`
}{manifest, buildSystemID, request}, &result); err != nil {
return BuildLaunch{}, err
return BuildDebugPreparation{}, err
}
if err := result.failure(command); err != nil {
return BuildLaunch{}, err
return BuildDebugPreparation{}, err
}
if result.Launch == nil {
return BuildLaunch{}, newParseError(command, "build debug preparation returned no launch", "")
if result.Preparation == nil {
return BuildDebugPreparation{}, newParseError(command, "build debug preparation returned no preparation", "")
}
return *result.Launch, nil
return *result.Preparation, nil
}
func (c *Client) DecodeBuildRun(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeRunRequest) (BuildLaunch, error) {
const command = "build.decodeRunPreparation"
Expand Down
37 changes: 37 additions & 0 deletions desktop/internal/core/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,40 @@ func TestBuildProviderRequestNeedsAnOpenSession(t *testing.T) {
t.Fatal("a build request to a missing session succeeded")
}
}

// A native debug preparation decodes with the run it was planned for: Core answers the adapter
// that run declares and the workspace-relative program the provider prepared.
func TestBuildDecodeDebugAnswersTheDeclaredAdapter(t *testing.T) {
client, ctx := NewClient(), testContext(t)
root := t.TempDir()
if err := os.MkdirAll(filepath.Join(root, "app", "bin"), 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(root, "app", "bin", "sample"), []byte("#!/bin/sh\n"), 0o700); err != nil {
t.Fatal(err)
}
manifest := readBuildFixture(t, "build-provider-debug-preparation.plugin.json")
raw, err := os.ReadFile(contractfixture.Path("fixtures/build-providers/build-debug-preparation.json"))
if err != nil {
t.Fatal(err)
}
var fixture struct {
Result json.RawMessage `json:"result"`
}
if err := json.Unmarshal(raw, &fixture); err != nil {
t.Fatal(err)
}
preparation, err := client.DecodeBuildDebug(ctx, manifest, "gradle", BuildDecodeDebugRequest{
WorkspaceRoot: root,
Root: ".",
Run: "application",
Result: fixture.Result,
})
if err != nil {
t.Fatal(err)
}
if preparation.Adapter != "native" || preparation.Program != "app/bin/sample" || preparation.WorkingDirectory != "app" ||
len(preparation.Arguments) != 2 || preparation.Environment["SAMPLE"] != "debug" {
t.Fatalf("preparation = %+v", preparation)
}
}
65 changes: 65 additions & 0 deletions desktop/internal/core/debug_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,68 @@ func (c *Client) SetDebugDataBreakpoints(ctx context.Context, sessionID string,
}
return update, nil
}

// SetDebugBreakpointsMuted mutes or unmutes every breakpoint kind of a session. Core keeps the
// stored sets and sends each kind empty while muted; a child session starts muted when its
// parent is.
func (c *Client) SetDebugBreakpointsMuted(ctx context.Context, sessionID string, muted bool) (DebugUpdate, error) {
var update DebugUpdate
if err := c.Execute(ctx, "debug.setBreakpointsMuted", struct {
SessionID string `json:"sessionId"`
Muted bool `json:"muted"`
}{sessionID, muted}, &update); err != nil {
return DebugUpdate{}, err
}
return update, nil
}

// DebugReadMemoryArguments are the exact DAP readMemory arguments of a memory window.
type DebugReadMemoryArguments struct {
MemoryReference string `json:"memoryReference"`
Offset int64 `json:"offset"`
Count uint32 `json:"count"`
}

// DebugMemoryWindow is one planned readMemory window. The host keeps it and passes it back
// with the adapter's reply.
type DebugMemoryWindow struct {
// Address is what the address field shows: a number in lowercase 0x hexadecimal, any
// other reference as given.
Address string `json:"address"`
Request DebugReadMemoryArguments `json:"request"`
}

// DebugMemoryLocation is where one reply's bytes sit.
type DebugMemoryLocation struct {
// Base is the first returned byte's address in lowercase 0x hexadecimal; empty when
// neither the reply nor the window gives a number.
Base string `json:"base,omitempty"`
// Mark is the index of the byte at the address read; nil when the reply does not hold it.
Mark *uint32 `json:"mark,omitempty"`
}

// PlanDebugMemoryWindow places the memory view's readMemory window at an address the user
// typed or at a frame's instruction pointer.
func (c *Client) PlanDebugMemoryWindow(ctx context.Context, address string) (DebugMemoryWindow, error) {
var window DebugMemoryWindow
if err := c.Execute(ctx, "debug.planMemoryWindow", struct {
Address string `json:"address"`
}{address}, &window); err != nil {
return DebugMemoryWindow{}, err
}
return window, nil
}

// LocateDebugMemoryWindow finds where a reply's bytes start and which of them is at the
// window's address. start is the reply's address, empty when the adapter gave none.
func (c *Client) LocateDebugMemoryWindow(ctx context.Context, window DebugMemoryWindow, start string, length uint32) (DebugMemoryLocation, error) {
var location DebugMemoryLocation
if err := c.Execute(ctx, "debug.locateMemoryWindow", struct {
Window DebugMemoryWindow `json:"window"`
Start string `json:"start,omitempty"`
Length uint32 `json:"length"`
}{window, start, length}, &location); err != nil {
return DebugMemoryLocation{}, err
}
return location, nil
}
45 changes: 45 additions & 0 deletions desktop/internal/core/debug_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,48 @@ func TestDebugStartOrContinueFollowsCore(t *testing.T) {
}
}
}

// TestDebugMemoryWindowFollowsTheContractFixture plans each scenario's window and locates
// each reply through the typed wrappers.
func TestDebugMemoryWindowFollowsTheContractFixture(t *testing.T) {
var fixture struct {
Scenarios []struct {
Name string `json:"name"`
Address string `json:"address"`
Window DebugMemoryWindow `json:"window"`
Replies []struct {
Start string `json:"start"`
Length uint32 `json:"length"`
Expected DebugMemoryLocation `json:"expected"`
} `json:"replies"`
} `json:"scenarios"`
}
if err := json.Unmarshal(readDebugFixture(t, "memory-window-v1.json"), &fixture); err != nil {
t.Fatal(err)
}
ctx := debugContext(t)
client := NewClient()
for _, scenario := range fixture.Scenarios {
t.Run(scenario.Name, func(t *testing.T) {
window, err := client.PlanDebugMemoryWindow(ctx, scenario.Address)
if err != nil {
t.Fatal(err)
}
if window != scenario.Window {
t.Fatalf("window = %+v, want %+v", window, scenario.Window)
}
for index, reply := range scenario.Replies {
got, err := client.LocateDebugMemoryWindow(ctx, window, reply.Start, reply.Length)
if err != nil {
t.Fatalf("reply %d: %v", index, err)
}
if !reflect.DeepEqual(got, reply.Expected) {
t.Fatalf("reply %d: got %+v, want %+v", index, got, reply.Expected)
}
}
})
}
if _, err := client.PlanDebugMemoryWindow(ctx, " "); err == nil {
t.Fatal("a blank address was planned")
}
}
35 changes: 35 additions & 0 deletions desktop/internal/core/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,41 @@ func (c *Client) ResolveRunConfigurations(ctx context.Context, root string) (Run
return result, err
}

// TitleConfiguration describes the configuration the title bar shows, as far as starting it
// depends on. Kind is "unsupported", "instanceMissing", "modelNotLoaded" (with Failed) or
// "modelLoaded" (with Debuggable).
type TitleConfiguration struct {
Kind string `json:"kind"`
Failed *bool `json:"failed,omitempty"`
Debuggable *bool `json:"debuggable,omitempty"`
}

// TitleActionFacts are the facts one title bar Run or Debug decision depends on.
type TitleActionFacts struct {
// Action is "run" or "debug".
Action string `json:"action"`
// Trigger is "press", or "settled" when the host asks again for a press it kept.
Trigger string `json:"trigger"`
CurrentFileChosen bool `json:"currentFileChosen"`
// Settled says detection answered, no model is loading and the configurations were
// resolved since.
Settled bool `json:"settled"`
Configuration *TitleConfiguration `json:"configuration,omitempty"`
}

// DecideTitleAction asks Core what a title bar press does. The answer is "currentFile",
// "wait", "loadModel", "unsupported", "targetMissing", "modelFailed", "run", "debug" or
// "notDebuggable".
func (c *Client) DecideTitleAction(ctx context.Context, facts TitleActionFacts) (string, error) {
var decision struct {
Kind string `json:"kind"`
}
if err := c.Execute(ctx, "runConfig.decideTitleAction", facts, &decision); err != nil {
return "", err
}
return decision.Kind, nil
}

// RunLaunchOptions are the typed launch options of a build provider run
// (buildProviders 10): the user's resolved choices, passed to the provider's
// prepareRun and to the decoder of its answer.
Expand Down
33 changes: 33 additions & 0 deletions desktop/internal/core/run_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,36 @@ func TestRunConfigurationOptionsRoundTrip(t *testing.T) {
t.Fatalf("argument text = %q, %v", texts, err)
}
}

// TestTitleActionsFollowTheContractFixture replays every title bar case through the typed
// wrapper.
func TestTitleActionsFollowTheContractFixture(t *testing.T) {
data, err := os.ReadFile(filepath.Join("..", "..", "..", "shared", "fixtures", "run-configuration", "title-action-v1.json"))
if err != nil {
t.Fatal(err)
}
var fixture struct {
Cases []struct {
Name string `json:"name"`
Request TitleActionFacts `json:"request"`
Expected struct {
Kind string `json:"kind"`
} `json:"expected"`
} `json:"cases"`
}
if err := json.Unmarshal(data, &fixture); err != nil {
t.Fatal(err)
}
client := NewClient()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
for _, testCase := range fixture.Cases {
got, err := client.DecideTitleAction(ctx, testCase.Request)
if err != nil {
t.Fatalf("%s: %v", testCase.Name, err)
}
if got != testCase.Expected.Kind {
t.Fatalf("%s: decision = %q, want %q", testCase.Name, got, testCase.Expected.Kind)
}
}
}
15 changes: 6 additions & 9 deletions desktop/internal/i18n/debug_breakpoint_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package i18n
// DebugBreakpointMessages are the words of the breakpoint editor: the condition,
// hit count and log message a source breakpoint may carry.
type DebugBreakpointMessages struct {
Edit string
FunctionName string
FunctionPlaceholder string
AddFunction string
FunctionRow func(name string) string
RemoveFunction string
// Instruction labels the button that toggles a machine-instruction breakpoint on a row.
Instruction string
Edit string
FunctionName string
FunctionPlaceholder string
AddFunction string
FunctionRow func(name string) string
RemoveFunction string
BreakOnChange string
DataRow func(label string) string
RemoveData string
Expand Down Expand Up @@ -39,7 +37,6 @@ func debugBreakpointMessages(language Language) DebugBreakpointMessages {
return SharedFormat(language, "desktop.debug.breakpoint.functionRow", map[string]string{"name": name})
},
RemoveFunction: Shared(language, "desktop.debug.breakpoint.removeFunction"),
Instruction: Shared(language, "desktop.debug.breakpoint.instruction"),
BreakOnChange: Shared(language, "desktop.debug.breakpoint.breakOnChange"),
DataRow: func(label string) string {
return SharedFormat(language, "desktop.debug.breakpoint.dataRow", map[string]string{"label": label})
Expand Down
6 changes: 0 additions & 6 deletions desktop/internal/i18n/debug_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ type DebugMessages struct {
SetValue string
NoExceptionFilters string
NoDisassembly string
LoadBefore string
LoadAfter string
Reload string
EndOfCode string
BufferLimit string
InvalidEndpoint string
// RemotePrompt asks whether to attach to a debuggee that is not local.
Expand Down Expand Up @@ -131,10 +128,7 @@ func debugMessages(language Language) DebugMessages {
SetValue: Shared(language, "desktop.debug.setValue"),
NoExceptionFilters: Shared(language, "desktop.debug.noExceptionFilters"),
NoDisassembly: Shared(language, "desktop.debug.noDisassembly"),
LoadBefore: Shared(language, "desktop.debug.loadBefore"),
LoadAfter: Shared(language, "desktop.debug.loadAfter"),
Reload: Shared(language, "desktop.debug.reload"),
EndOfCode: Shared(language, "desktop.debug.endOfCode"),
BufferLimit: Shared(language, "desktop.debug.bufferLimit"),
InvalidEndpoint: Shared(language, "desktop.debug.invalidEndpoint"),
RemotePrompt: func(endpoint string) string {
Expand Down
2 changes: 0 additions & 2 deletions desktop/internal/i18n/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ type TitleMessages struct {
Debug string
Search string
Settings string
// RunLater explains that running needs a build provider that is not connected yet.
RunLater string
// The settings button's menu.
Preferences string
Plugins string
Expand Down
Loading
Loading