func cmdline(w http.ResponseWriter, r *http.Request) {
	fake := filterResponse{
		w: w,
		edit: func(buf []byte) []byte {
			return bytes.ReplaceAll(buf, []byte{0}, []byte{' '})
		},
	}
	pprof.Cmdline(fake, r)
}
replace annoying nuls by spaces
package debug
import (
	"archive/zip"
	"bytes"
	"context"
	"fmt"
	"html/template"
	"io"
	stdlog "log"
	"net"
	"net/http"
	"net/http/pprof"
	"os"
	"path"
	"path/filepath"
	"runtime"
	rpprof "runtime/pprof"
	"sort"
	"strconv"
	"strings"
	"sync"
	"time"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/core"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/export"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/export/metric"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/export/ocagent"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/export/prometheus"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/keys"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/event/label"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/cache"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/debug/log"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/debug/tag"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/protocol"
	"github.com/govim/govim/cmd/govim/internal/golang_org_x_tools/lsp/source"
	errors "golang.org/x/xerrors"
)
type contextKeyType int
const (
	instanceKey contextKeyType = iota
	traceKey
)
type Instance struct {
	Logfile       string
	StartTime     time.Time
	ServerAddress string
	Workdir       string
	OCAgentConfig string
	LogWriter io.Writer
	exporter event.Exporter
	ocagent    *ocagent.Exporter
	prometheus *prometheus.Exporter
	rpcs       *Rpcs
	traces     *traces
	State      *State
	serveMu              sync.Mutex
	debugAddress         string
	listenedDebugAddress string
}
type State struct {
	mu      sync.Mutex
	clients []*Client
	servers []*Server
	bugs map[string]string
}
func Bug(ctx context.Context, desc, format string, args ...interface{}) {
	labels := []label.Label{tag.Bug.Of(desc)}
	_, file, line, ok := runtime.Caller(1)
	if ok {
		labels = append(labels, tag.Callsite.Of(fmt.Sprintf("%s:%d", file, line)))
	}
	msg := fmt.Sprintf(format, args...)
	event.Log(ctx, msg, labels...)
}
type bug struct {
	Description, Event string
}
func (st *State) Bugs() []bug {
	st.mu.Lock()
	defer st.mu.Unlock()
	var bugs []bug
	for k, v := range st.bugs {
		bugs = append(bugs, bug{k, v})
	}
	sort.Slice(bugs, func(i, j int) bool {
		return bugs[i].Description < bugs[j].Description
	})
	return bugs
}
func (st *State) recordBug(description, event string) {
	st.mu.Lock()
	defer st.mu.Unlock()
	if st.bugs == nil {
		st.bugs = make(map[string]string)
	}
	st.bugs[description] = event
}
func (st *State) Caches() []*cache.Cache {
	var caches []*cache.Cache
	seen := make(map[string]struct{})
	for _, client := range st.Clients() {
		cache, ok := client.Session.Cache().(*cache.Cache)
		if !ok {
			continue
		}
		if _, found := seen[cache.ID()]; found {
			continue
		}
		seen[cache.ID()] = struct{}{}
		caches = append(caches, cache)
	}
	return caches
}
func (st *State) Cache(id string) *cache.Cache {
	for _, c := range st.Caches() {
		if c.ID() == id {
			return c
		}
	}
	return nil
}
func (st *State) Sessions() []*cache.Session {
	var sessions []*cache.Session
	for _, client := range st.Clients() {
		sessions = append(sessions, client.Session)
	}
	return sessions
}
func (st *State) Session(id string) *cache.Session {
	for _, s := range st.Sessions() {
		if s.ID() == id {
			return s
		}
	}
	return nil
}
func (st *State) Views() []*cache.View {
	var views []*cache.View
	for _, s := range st.Sessions() {
		for _, v := range s.Views() {
			if cv, ok := v.(*cache.View); ok {
				views = append(views, cv)
			}
		}
	}
	return views
}
func (st *State) View(id string) *cache.View {
	for _, v := range st.Views() {
		if v.ID() == id {
			return v
		}
	}
	return nil
}
func (st *State) Clients() []*Client {
	st.mu.Lock()
	defer st.mu.Unlock()
	clients := make([]*Client, len(st.clients))
	copy(clients, st.clients)
	return clients
}
func (st *State) Client(id string) *Client {
	for _, c := range st.Clients() {
		if c.Session.ID() == id {
			return c
		}
	}
	return nil
}
func (st *State) Servers() []*Server {
	st.mu.Lock()
	defer st.mu.Unlock()
	servers := make([]*Server, len(st.servers))
	copy(servers, st.servers)
	return servers
}
type Client struct {
	Session      *cache.Session
	DebugAddress string
	Logfile      string
	GoplsPath    string
	ServerID     string
	Service      protocol.Server
}
type Server struct {
	ID           string
	DebugAddress string
	Logfile      string
	GoplsPath    string
	ClientID     string
}
func (st *State) addClient(session *cache.Session) {
	st.mu.Lock()
	defer st.mu.Unlock()
	st.clients = append(st.clients, &Client{Session: session})
}
func (st *State) dropClient(session source.Session) {
	st.mu.Lock()
	defer st.mu.Unlock()
	for i, c := range st.clients {
		if c.Session == session {
			copy(st.clients[i:], st.clients[i+1:])
			st.clients[len(st.clients)-1] = nil
			st.clients = st.clients[:len(st.clients)-1]
			return
		}
	}
}
func (st *State) updateServer(server *Server) {
	st.mu.Lock()
	defer st.mu.Unlock()
	for i, existing := range st.servers {
		if existing.ID == server.ID {
			newServers := make([]*Server, len(st.servers))
			copy(newServers, st.servers[:i])
			newServers[i] = server
			copy(newServers[i+1:], st.servers[i+1:])
			st.servers = newServers
			return
		}
	}
	st.servers = append(st.servers, server)
}
func (st *State) dropServer(id string) {
	st.mu.Lock()
	defer st.mu.Unlock()
	for i, s := range st.servers {
		if s.ID == id {
			copy(st.servers[i:], st.servers[i+1:])
			st.servers[len(st.servers)-1] = nil
			st.servers = st.servers[:len(st.servers)-1]
			return
		}
	}
}
type filterResponse struct {
	w    http.ResponseWriter
	edit func([]byte) []byte
}
func (c filterResponse) Header() http.Header {
	return c.w.Header()
}
func (c filterResponse) Write(buf []byte) (int, error) {
	ans := c.edit(buf)
	return c.w.Write(ans)
}
func (c filterResponse) WriteHeader(n int) {
	c.w.WriteHeader(n)
}