Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cmd/internal/lldb/lldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import (
"strings"

"github.com/goplus/llgo/cmd/internal/base"
"github.com/goplus/llgo/internal/debugabi"
"github.com/goplus/llgo/internal/mockable"
)

const minimumUpstreamLLDBVersion = 18
const debuggerSchemaFilename = "llgo_debugger_schema_v1.json"

var (
//go:embed llgo_plugin.py
Expand Down Expand Up @@ -91,9 +93,15 @@ func run(configuredPath string, args []string, stdin io.Reader, stdout, stderr i
if err := os.WriteFile(pluginPath, pluginSource, 0600); err != nil {
return fmt.Errorf("llgo lldb: write plugin: %w", err)
}
schemaPath := filepath.Join(pluginDir, debuggerSchemaFilename)
if err := os.WriteFile(schemaPath, debugabi.SchemaV1(), 0600); err != nil {
return fmt.Errorf("llgo lldb: write debugger schema: %w", err)
}

lldbArgs := make([]string, 0, len(args)+2)
lldbArgs = append(lldbArgs, "-O", lldbImportCommand(pluginPath))
// Import after LLDB creates the target so the plugin can enable runtime
// formatters only for binaries that advertise a supported LLGo schema.
lldbArgs = append(lldbArgs, "-o", lldbImportCommand(pluginPath))
lldbArgs = append(lldbArgs, args...)

command := exec.Command(path, lldbArgs...)
Expand Down
14 changes: 11 additions & 3 deletions cmd/internal/lldb/lldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ func TestRunImportsEmbeddedPluginAndPassesArguments(t *testing.T) {
printf '%s\n' "$@" > "$LLGO_LLDB_TEST_CAPTURE"
plugin=$(printf '%s\n' "$2" | sed 's/^command script import "//; s/"$//')
test -s "$plugin"
grep -q __llgo_debugger_marker_v1 "$plugin"
schema=$(dirname "$plugin")/llgo_debugger_schema_v1.json
test -s "$schema"
grep -q '"contract": "llgo.debugger"' "$schema"
grep -q __llgo_debugger_marker_v1 "$schema"
`)

var stdout, stderr bytes.Buffer
Expand All @@ -129,7 +132,10 @@ grep -q __llgo_debugger_marker_v1 "$plugin"
t.Fatal(err)
}
got := string(data)
for _, want := range []string{"-O\n", "command script import \"", "--batch\n", "./program\n", "-o\n", "run\n"} {
if !strings.HasPrefix(got, "-o\ncommand script import \"") {
t.Fatalf("LLDB arguments %q do not import the plugin after target creation", got)
}
for _, want := range []string{"--batch\n", "./program\n", "-o\n", "run\n"} {
if !strings.Contains(got, want) {
t.Fatalf("LLDB arguments %q do not contain %q", got, want)
}
Expand Down Expand Up @@ -170,11 +176,13 @@ func TestEmbeddedPluginIdentity(t *testing.T) {
source := string(pluginSource)
for _, want := range []string{
"__lldb_init_module",
"__llgo_debugger_marker_v1",
"LLGO_DEBUGGER_MARKER_PREFIX",
"is_llgo_compiler",
"inspect_target",
"LLGO_DEBUGGER_SCHEMAS",
"LLGO_RUNTIME_LAYOUTS",
"LLGO_DEBUGGER_RECORD_SYMBOL",
"llgo_debugger_schema_v1.json",
"string_summary",
"slice_summary",
"SliceSyntheticProvider",
Expand Down
Loading
Loading