From 938cb6e9d8e59f358d44590a4beb13a98c5a22dc Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 14 Nov 2023 17:36:55 +0200 Subject: [PATCH] pkg,service: remove unnecessary convertions (#3564) --- pkg/dwarf/dwarfbuilder/info.go | 4 ++-- pkg/dwarf/leb128/decode.go | 2 +- pkg/dwarf/line/line_parser.go | 10 ++++---- pkg/dwarf/line/state_machine.go | 2 +- pkg/dwarf/loclist/dwarf2_loclist.go | 2 +- pkg/dwarf/op/op.go | 4 ++-- pkg/elfwriter/writer.go | 2 +- pkg/locspec/locations.go | 2 +- pkg/proc/amd64_arch.go | 6 ++--- pkg/proc/arm64_arch.go | 22 +++++++++--------- pkg/proc/arm64_disasm.go | 2 +- pkg/proc/bininfo.go | 2 +- pkg/proc/breakpoints.go | 2 +- pkg/proc/core/core.go | 2 +- pkg/proc/core/minidump/minidump.go | 4 ++-- pkg/proc/disasm.go | 2 +- pkg/proc/dwarf_expr_test.go | 10 ++++---- pkg/proc/eval.go | 8 +++---- pkg/proc/fncall.go | 8 +++---- pkg/proc/gdbserial/gdbserver.go | 2 +- pkg/proc/gdbserial/gdbserver_conn.go | 2 +- pkg/proc/mem.go | 4 ++-- pkg/proc/proc_general_test.go | 2 +- pkg/proc/stack.go | 2 +- pkg/proc/target_exec.go | 4 ++-- pkg/proc/types.go | 4 ++-- pkg/proc/variables.go | 24 ++++++++++---------- pkg/proc/winutil/regs_amd64_arch.go | 34 ++++++++++++++-------------- pkg/terminal/starbind/conv.go | 2 +- service/dap/server_test.go | 6 ++--- service/test/integration2_test.go | 8 +++---- 31 files changed, 95 insertions(+), 95 deletions(-) diff --git a/pkg/dwarf/dwarfbuilder/info.go b/pkg/dwarf/dwarfbuilder/info.go index 52b1fdba..3de9ed3b 100644 --- a/pkg/dwarf/dwarfbuilder/info.go +++ b/pkg/dwarf/dwarfbuilder/info.go @@ -167,8 +167,8 @@ func (b *Builder) Attr(attr dwarf.Attr, val interface{}) dwarf.Offset { binary.Write(&b.loc, binary.LittleEndian, uint64(0)) for _, locentry := range x { - binary.Write(&b.loc, binary.LittleEndian, uint64(locentry.Lowpc)) - binary.Write(&b.loc, binary.LittleEndian, uint64(locentry.Highpc)) + binary.Write(&b.loc, binary.LittleEndian, locentry.Lowpc) + binary.Write(&b.loc, binary.LittleEndian, locentry.Highpc) binary.Write(&b.loc, binary.LittleEndian, uint16(len(locentry.Loc))) b.loc.Write(locentry.Loc) } diff --git a/pkg/dwarf/leb128/decode.go b/pkg/dwarf/leb128/decode.go index 61f0aa3c..c066a7dd 100644 --- a/pkg/dwarf/leb128/decode.go +++ b/pkg/dwarf/leb128/decode.go @@ -67,7 +67,7 @@ func DecodeSigned(buf Reader) (int64, uint32) { } length++ - result |= int64((int64(b) & 0x7f) << shift) + result |= (int64(b) & 0x7f) << shift shift += 7 if b&0x80 == 0 { break diff --git a/pkg/dwarf/line/line_parser.go b/pkg/dwarf/line/line_parser.go index 030689a3..259bdc1e 100644 --- a/pkg/dwarf/line/line_parser.go +++ b/pkg/dwarf/line/line_parser.go @@ -132,16 +132,16 @@ func parseDebugLinePrologue(dbl *DebugLineInfo, buf *bytes.Buffer) { } p.Length = binary.LittleEndian.Uint32(buf.Next(4)) - p.MinInstrLength = uint8(buf.Next(1)[0]) + p.MinInstrLength = buf.Next(1)[0] if p.Version >= 4 { - p.MaxOpPerInstr = uint8(buf.Next(1)[0]) + p.MaxOpPerInstr = buf.Next(1)[0] } else { p.MaxOpPerInstr = 1 } - p.InitialIsStmt = uint8(buf.Next(1)[0]) + p.InitialIsStmt = buf.Next(1)[0] p.LineBase = int8(buf.Next(1)[0]) - p.LineRange = uint8(buf.Next(1)[0]) - p.OpcodeBase = uint8(buf.Next(1)[0]) + p.LineRange = buf.Next(1)[0] + p.OpcodeBase = buf.Next(1)[0] p.StdOpLengths = make([]uint8, p.OpcodeBase-1) binary.Read(buf, binary.LittleEndian, &p.StdOpLengths) diff --git a/pkg/dwarf/line/state_machine.go b/pkg/dwarf/line/state_machine.go index 6c31fb46..22149ff9 100644 --- a/pkg/dwarf/line/state_machine.go +++ b/pkg/dwarf/line/state_machine.go @@ -423,7 +423,7 @@ func (sm *StateMachine) next() error { func execSpecialOpcode(sm *StateMachine, instr byte) { var ( - opcode = uint8(instr) + opcode = instr decoded = opcode - sm.dbl.Prologue.OpcodeBase ) diff --git a/pkg/dwarf/loclist/dwarf2_loclist.go b/pkg/dwarf/loclist/dwarf2_loclist.go index e9859cd7..89fef49f 100644 --- a/pkg/dwarf/loclist/dwarf2_loclist.go +++ b/pkg/dwarf/loclist/dwarf2_loclist.go @@ -87,7 +87,7 @@ func (rdr *Dwarf2Reader) oneAddr() uint64 { } return uint64(addr) case 8: - addr := uint64(binary.LittleEndian.Uint64(rdr.read(rdr.ptrSz))) + addr := binary.LittleEndian.Uint64(rdr.read(rdr.ptrSz)) return addr default: panic("bad address size") diff --git a/pkg/dwarf/op/op.go b/pkg/dwarf/op/op.go index 3d630dcd..c8694fcc 100644 --- a/pkg/dwarf/op/op.go +++ b/pkg/dwarf/op/op.go @@ -208,7 +208,7 @@ func callframecfa(opcode Opcode, ctxt *context) error { if ctxt.CFA == 0 { return errors.New("could not retrieve CFA for current PC") } - ctxt.stack = append(ctxt.stack, int64(ctxt.CFA)) + ctxt.stack = append(ctxt.stack, ctxt.CFA) return nil } @@ -373,7 +373,7 @@ func pick(opcode Opcode, ctxt *context) error { default: panic("internal error") } - idx := len(ctxt.stack) - 1 - int(uint8(n)) + idx := len(ctxt.stack) - 1 - int(n) if idx < 0 || idx >= len(ctxt.stack) { return ErrStackIndexOutOfBounds } diff --git a/pkg/elfwriter/writer.go b/pkg/elfwriter/writer.go index 3876b260..65a5b51c 100644 --- a/pkg/elfwriter/writer.go +++ b/pkg/elfwriter/writer.go @@ -58,7 +58,7 @@ func New(w WriteCloserSeeker, fhdr *elf.FileHeader) *Writer { } // e_ident - r.Write([]byte{0x7f, 'E', 'L', 'F', byte(fhdr.Class), byte(fhdr.Data), byte(fhdr.Version), byte(fhdr.OSABI), byte(fhdr.ABIVersion), 0, 0, 0, 0, 0, 0, 0}) + r.Write([]byte{0x7f, 'E', 'L', 'F', byte(fhdr.Class), byte(fhdr.Data), byte(fhdr.Version), byte(fhdr.OSABI), fhdr.ABIVersion, 0, 0, 0, 0, 0, 0, 0}) r.u16(uint16(fhdr.Type)) // e_type r.u16(uint16(fhdr.Machine)) // e_machine diff --git a/pkg/locspec/locations.go b/pkg/locspec/locations.go index 9832ffb1..d48b72a1 100644 --- a/pkg/locspec/locations.go +++ b/pkg/locspec/locations.go @@ -311,7 +311,7 @@ func (loc *AddrLocationSpec) Find(t *proc.Target, _ []string, scope *proc.EvalSc addr, _ := constant.Uint64Val(v.Value) return []api.Location{{PC: addr}}, "", nil case reflect.Func: - fn := scope.BinInfo.PCToFunc(uint64(v.Base)) + fn := scope.BinInfo.PCToFunc(v.Base) pc, err := proc.FirstPCAfterPrologue(t, fn, false) if err != nil { return nil, "", err diff --git a/pkg/proc/amd64_arch.go b/pkg/proc/amd64_arch.go index 4f193f1e..6d8c8283 100644 --- a/pkg/proc/amd64_arch.go +++ b/pkg/proc/amd64_arch.go @@ -150,7 +150,7 @@ func amd64SwitchStack(it *stackIterator, _ *op.DwarfRegisters) bool { // switches from the goroutine stack to the system stack. // Since we are unwinding the stack from callee to caller we have to switch // from the system stack to the goroutine stack. - off, _ := readIntRaw(it.mem, uint64(it.regs.SP()+amd64cgocallSPOffsetSaveSlot), int64(it.bi.Arch.PtrSize())) // reads "offset of SP from StackHi" from where runtime.asmcgocall saved it + off, _ := readIntRaw(it.mem, it.regs.SP()+amd64cgocallSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize())) // reads "offset of SP from StackHi" from where runtime.asmcgocall saved it oldsp := it.regs.SP() it.regs.Reg(it.regs.SPRegNum).Uint64Val = uint64(int64(it.stackhi) - off) @@ -190,7 +190,7 @@ func amd64SwitchStack(it *stackIterator, _ *op.DwarfRegisters) bool { // entering the system stack it.regs.Reg(it.regs.SPRegNum).Uint64Val = it.g0_sched_sp // reads the previous value of g0.sched.sp that runtime.cgocallback_gofunc saved on the stack - it.g0_sched_sp, _ = readUintRaw(it.mem, uint64(it.regs.SP()), int64(it.bi.Arch.PtrSize())) + it.g0_sched_sp, _ = readUintRaw(it.mem, it.regs.SP(), int64(it.bi.Arch.PtrSize())) it.top = false callFrameRegs, ret, retaddr := it.advanceRegs() frameOnSystemStack := it.newStackframe(ret, retaddr) @@ -409,7 +409,7 @@ func formatX87Reg(b []byte) string { return fmt.Sprintf("%#x", b) } mantissa := binary.LittleEndian.Uint64(b[:8]) - exponent := uint16(binary.LittleEndian.Uint16(b[8:])) + exponent := binary.LittleEndian.Uint16(b[8:]) var f float64 fset := false diff --git a/pkg/proc/arm64_arch.go b/pkg/proc/arm64_arch.go index 8cb70459..c28e4711 100644 --- a/pkg/proc/arm64_arch.go +++ b/pkg/proc/arm64_arch.go @@ -174,7 +174,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool // Entering the system stack. it.regs.Reg(callFrameRegs.SPRegNum).Uint64Val = it.g0_sched_sp // Reads the previous value of g0.sched.sp that runtime.cgocallback_gofunc saved on the stack. - it.g0_sched_sp, _ = readUintRaw(it.mem, uint64(it.regs.SP()+prevG0schedSPOffsetSaveSlot), int64(it.bi.Arch.PtrSize())) + it.g0_sched_sp, _ = readUintRaw(it.mem, it.regs.SP()+prevG0schedSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize())) it.top = false callFrameRegs, ret, retaddr := it.advanceRegs() frameOnSystemStack := it.newStackframe(ret, retaddr) @@ -195,7 +195,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool // switches from the goroutine stack to the system stack. // Since we are unwinding the stack from callee to caller we have to switch // from the system stack to the goroutine stack. - off, _ := readIntRaw(it.mem, uint64(it.regs.SP()+arm64cgocallSPOffsetSaveSlot), + off, _ := readIntRaw(it.mem, it.regs.SP()+arm64cgocallSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize())) oldsp := it.regs.SP() newsp := uint64(int64(it.stackhi) - off) @@ -239,20 +239,20 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool bpoff = 22 lroff = 23 } - newsp, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*24), int64(it.bi.Arch.PtrSize())) - newbp, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*bpoff), int64(it.bi.Arch.PtrSize())) - newlr, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*lroff), int64(it.bi.Arch.PtrSize())) + newsp, _ := readUintRaw(it.mem, it.regs.SP()+8*24, int64(it.bi.Arch.PtrSize())) + newbp, _ := readUintRaw(it.mem, it.regs.SP()+8*bpoff, int64(it.bi.Arch.PtrSize())) + newlr, _ := readUintRaw(it.mem, it.regs.SP()+8*lroff, int64(it.bi.Arch.PtrSize())) if it.regs.Reg(it.regs.BPRegNum) != nil { - it.regs.Reg(it.regs.BPRegNum).Uint64Val = uint64(newbp) + it.regs.Reg(it.regs.BPRegNum).Uint64Val = newbp } else { reg, _ := it.readRegisterAt(it.regs.BPRegNum, it.regs.SP()+8*bpoff) it.regs.AddReg(it.regs.BPRegNum, reg) } - it.regs.Reg(it.regs.LRRegNum).Uint64Val = uint64(newlr) + it.regs.Reg(it.regs.LRRegNum).Uint64Val = newlr if linux { - it.regs.Reg(it.regs.SPRegNum).Uint64Val = uint64(newbp) + it.regs.Reg(it.regs.SPRegNum).Uint64Val = newbp } else { - it.regs.Reg(it.regs.SPRegNum).Uint64Val = uint64(newsp) + it.regs.Reg(it.regs.SPRegNum).Uint64Val = newsp } it.pc = newlr return true @@ -299,7 +299,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool // switches from the goroutine stack to the system stack. // Since we are unwinding the stack from callee to caller we have to switch // from the system stack to the goroutine stack. - off, _ := readIntRaw(it.mem, uint64(callFrameRegs.SP()+arm64cgocallSPOffsetSaveSlot), int64(it.bi.Arch.PtrSize())) + off, _ := readIntRaw(it.mem, callFrameRegs.SP()+arm64cgocallSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize())) oldsp := callFrameRegs.SP() newsp := uint64(int64(it.stackhi) - off) @@ -334,7 +334,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool callFrameRegs.Reg(callFrameRegs.SPRegNum).Uint64Val = it.g0_sched_sp // reads the previous value of g0.sched.sp that runtime.cgocallback_gofunc saved on the stack - it.g0_sched_sp, _ = readUintRaw(it.mem, uint64(callFrameRegs.SP()+prevG0schedSPOffsetSaveSlot), int64(it.bi.Arch.PtrSize())) + it.g0_sched_sp, _ = readUintRaw(it.mem, callFrameRegs.SP()+prevG0schedSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize())) it.systemstack = true return false } diff --git a/pkg/proc/arm64_disasm.go b/pkg/proc/arm64_disasm.go index 517c9a25..f0737f2a 100644 --- a/pkg/proc/arm64_disasm.go +++ b/pkg/proc/arm64_disasm.go @@ -63,7 +63,7 @@ func resolveCallArgARM64(inst *arm64asm.Inst, instAddr uint64, currentGoroutine return nil } case arm64asm.PCRel: - pc = uint64(instAddr) + uint64(arg) + pc = instAddr + uint64(arg) default: return nil } diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 66f34e92..8ebc335b 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -914,7 +914,7 @@ func (bi *BinaryInfo) AddImage(path string, addr uint64) error { // moduleDataToImage finds the image corresponding to the given module data object. func (bi *BinaryInfo) moduleDataToImage(md *moduleData) *Image { - fn := bi.PCToFunc(uint64(md.text)) + fn := bi.PCToFunc(md.text) if fn != nil { return bi.funcToImage(fn) } diff --git a/pkg/proc/breakpoints.go b/pkg/proc/breakpoints.go index d846f204..e2b1d095 100644 --- a/pkg/proc/breakpoints.go +++ b/pkg/proc/breakpoints.go @@ -704,7 +704,7 @@ func (t *Target) setBreakpointInternal(logicalID int, addr uint64, kind Breakpoi return bp, nil } - f, l, fn := t.BinInfo().PCToLine(uint64(addr)) + f, l, fn := t.BinInfo().PCToLine(addr) fnName := "" if fn != nil { diff --git a/pkg/proc/core/core.go b/pkg/proc/core/core.go index 57f8299c..dfab1b13 100644 --- a/pkg/proc/core/core.go +++ b/pkg/proc/core/core.go @@ -340,7 +340,7 @@ func (t *thread) Breakpoint() *proc.BreakpointState { // ThreadID returns the ID for this thread. func (t *thread) ThreadID() int { - return int(t.th.pid()) + return t.th.pid() } // Registers returns the current value of the registers for this thread. diff --git a/pkg/proc/core/minidump/minidump.go b/pkg/proc/core/minidump/minidump.go index 1e328b3e..bd4c69ff 100644 --- a/pkg/proc/core/minidump/minidump.go +++ b/pkg/proc/core/minidump/minidump.go @@ -186,10 +186,10 @@ func (m *MemoryRange) ReadMemory(buf []byte, addr uint64) (int, error) { if len(buf) == 0 { return 0, nil } - if (uint64(addr) < m.Addr) || (uint64(addr)+uint64(len(buf)) > m.Addr+uint64(len(m.Data))) { + if (addr < m.Addr) || (addr+uint64(len(buf)) > m.Addr+uint64(len(m.Data))) { return 0, io.EOF } - copy(buf, m.Data[uint64(addr)-m.Addr:]) + copy(buf, m.Data[addr-m.Addr:]) return len(buf), nil } diff --git a/pkg/proc/disasm.go b/pkg/proc/disasm.go index 9928abd3..4b7b69aa 100644 --- a/pkg/proc/disasm.go +++ b/pkg/proc/disasm.go @@ -139,7 +139,7 @@ func disassemble(memrw MemoryReadWriter, regs Registers, breakpoints *Breakpoint return nil, err } - r := make([]AsmInstruction, 0, len(mem)/int(bi.Arch.MaxInstructionLength())) + r := make([]AsmInstruction, 0, len(mem)/bi.Arch.MaxInstructionLength()) pc := startAddr var curpc uint64 diff --git a/pkg/proc/dwarf_expr_test.go b/pkg/proc/dwarf_expr_test.go index 88c9a46e..0950d80d 100644 --- a/pkg/proc/dwarf_expr_test.go +++ b/pkg/proc/dwarf_expr_test.go @@ -65,10 +65,10 @@ func newFakeMemory(base uint64, contents ...interface{}) *fakeMemory { } func (mem *fakeMemory) ReadMemory(data []byte, addr uint64) (int, error) { - if uint64(addr) < mem.base { + if addr < mem.base { return 0, fmt.Errorf("read out of bounds %d %#x", len(data), addr) } - start := uint64(addr) - mem.base + start := addr - mem.base end := uint64(len(data)) + start if end > uint64(len(mem.data)) { panic(fmt.Errorf("read out of bounds %d %#x", len(data), addr)) @@ -78,10 +78,10 @@ func (mem *fakeMemory) ReadMemory(data []byte, addr uint64) (int, error) { } func (mem *fakeMemory) WriteMemory(addr uint64, data []byte) (int, error) { - if uint64(addr) < mem.base { + if addr < mem.base { return 0, fmt.Errorf("write out of bounds %d %#x", len(data), addr) } - start := uint64(addr) - mem.base + start := addr - mem.base end := uint64(len(data)) + start if end > uint64(len(mem.data)) { panic(fmt.Errorf("write out of bounds %d %#x", len(data), addr)) @@ -217,7 +217,7 @@ func TestDwarfExprComposite(t *testing.T) { mainfn := bi.LookupFunc()["main.main"][0] - mem := newFakeMemory(fakeCFA(), uint64(0), uint64(0), uint16(testCases["pair.v"]), []byte(stringVal)) + mem := newFakeMemory(fakeCFA(), uint64(0), uint64(0), testCases["pair.v"], []byte(stringVal)) var regs linutil.AMD64Registers regs.Regs = &linutil.AMD64PtraceRegs{} regs.Regs.Rax = uint64(len(stringVal)) diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index 41dd16d4..851493b0 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -553,7 +553,7 @@ func (scope *EvalScope) setValue(dstv, srcv *Variable, srcExpr string) error { if srcv.Base == 0 && srcv.Len > 0 && srcv.Flags&VariableConstant != 0 { return errFuncCallNotAllowedStrAlloc } - return dstv.writeString(uint64(srcv.Len), uint64(srcv.Base)) + return dstv.writeString(uint64(srcv.Len), srcv.Base) } // slice assignment (this is not handled by the writeCopy below so that @@ -564,7 +564,7 @@ func (scope *EvalScope) setValue(dstv, srcv *Variable, srcExpr string) error { // allow any integer to be converted to any pointer if t, isptr := dstv.RealType.(*godwarf.PtrType); isptr { - return dstv.writeUint(uint64(srcv.Children[0].Addr), int64(t.ByteSize)) + return dstv.writeUint(srcv.Children[0].Addr, t.ByteSize) } // byte-by-byte copying for everything else, but the source must be addressable @@ -1251,7 +1251,7 @@ func (scope *EvalScope) evalTypeCast(op *evalop.TypeCast, stack *evalStack) { stack.push(v) return case reflect.Ptr: - v.Value = constant.MakeUint64(uint64(argv.Children[0].Addr)) + v.Value = constant.MakeUint64(argv.Children[0].Addr) stack.push(v) return } @@ -2552,7 +2552,7 @@ func (v *Variable) reslice(low int64, high int64) (*Variable, error) { return nil, fmt.Errorf("index out of bounds") } - base := v.Base + uint64(int64(low)*v.stride) + base := v.Base + uint64(low*v.stride) len := high - low if high-low < 0 { diff --git a/pkg/proc/fncall.go b/pkg/proc/fncall.go index 541957e1..98ed192f 100644 --- a/pkg/proc/fncall.go +++ b/pkg/proc/fncall.go @@ -483,7 +483,7 @@ func funcCallEvalFuncExpr(scope *EvalScope, stack *evalStack, fncall *functionCa if fnvar.Base == 0 { return errors.New("nil pointer dereference") } - fncall.fn = bi.PCToFunc(uint64(fnvar.Base)) + fncall.fn = bi.PCToFunc(fnvar.Base) if fncall.fn == nil { return fmt.Errorf("could not find DIE for function %q", exprToString(fncall.expr.Fun)) } @@ -558,7 +558,7 @@ func funcCallCopyOneArg(scope *EvalScope, fncall *functionCallState, actualArg * return err } } else { - formalArgVar = newVariable(formalArg.name, uint64(formalArg.off+int64(formalScope.Regs.CFA)), formalArg.typ, scope.BinInfo, scope.Mem) + formalArgVar = newVariable(formalArg.name, uint64(formalArg.off+formalScope.Regs.CFA), formalArg.typ, scope.BinInfo, scope.Mem) } if err := scope.setValue(formalArgVar, actualArg, actualArg.Name); err != nil { return err @@ -684,7 +684,7 @@ func funcCallArgRegABI(fn *Function, bi *BinaryInfo, entry reader.Variable, argn // alignAddr rounds up addr to a multiple of align. Align must be a power of 2. func alignAddr(addr, align int64) int64 { - return (addr + int64(align-1)) &^ int64(align-1) + return (addr + align - 1) &^ (align - 1) } func escapeCheck(v *Variable, name string, stack stack) error { @@ -733,7 +733,7 @@ func escapeCheck(v *Variable, name string, stack stack) error { } func escapeCheckPointer(addr uint64, name string, stack stack) error { - if uint64(addr) >= stack.lo && uint64(addr) < stack.hi { + if addr >= stack.lo && addr < stack.hi { return fmt.Errorf("stack object passed to escaping pointer: %s", name) } return nil diff --git a/pkg/proc/gdbserial/gdbserver.go b/pkg/proc/gdbserial/gdbserver.go index 744db008..381a4557 100644 --- a/pkg/proc/gdbserial/gdbserver.go +++ b/pkg/proc/gdbserial/gdbserver.go @@ -780,7 +780,7 @@ func (p *gdbProcess) Recorded() (bool, string) { // Pid returns the process ID. func (p *gdbProcess) Pid() int { - return int(p.conn.pid) + return p.conn.pid } // Valid returns true if we are not detached diff --git a/pkg/proc/gdbserial/gdbserver_conn.go b/pkg/proc/gdbserial/gdbserver_conn.go index 2f71dd17..294c34df 100644 --- a/pkg/proc/gdbserial/gdbserver_conn.go +++ b/pkg/proc/gdbserial/gdbserver_conn.go @@ -892,7 +892,7 @@ func (conn *gdbConn) queryProcessInfo(pid int) (map[string]string, error) { case "name": name := make([]byte, len(value)/2) for i := 0; i < len(value); i += 2 { - n, _ := strconv.ParseUint(string(value[i:i+2]), 16, 8) + n, _ := strconv.ParseUint(value[i:i+2], 16, 8) name[i/2] = byte(n) } pi[key] = string(name) diff --git a/pkg/proc/mem.go b/pkg/proc/mem.go index a215d274..6138a59b 100644 --- a/pkg/proc/mem.go +++ b/pkg/proc/mem.go @@ -127,7 +127,7 @@ func newCompositeMemory(mem MemoryReadWriter, arch *Arch, regs op.DwarfRegisters cmem.data = append(cmem.data, reg[:piece.Size]...) case op.AddrPiece: buf := make([]byte, piece.Size) - mem.ReadMemory(buf, uint64(piece.Val)) + mem.ReadMemory(buf, piece.Val) cmem.data = append(cmem.data, buf...) case op.ImmPiece: buf := piece.Bytes @@ -191,7 +191,7 @@ func (mem *compositeMemory) WriteMemory(addr uint64, data []byte) (int, error) { return donesz, err } case op.AddrPiece: - n, err := mem.realmem.WriteMemory(uint64(piece.Val), pieceMem) + n, err := mem.realmem.WriteMemory(piece.Val, pieceMem) if err != nil { return donesz + n, err } diff --git a/pkg/proc/proc_general_test.go b/pkg/proc/proc_general_test.go index 872b79b6..07013c99 100644 --- a/pkg/proc/proc_general_test.go +++ b/pkg/proc/proc_general_test.go @@ -44,7 +44,7 @@ type memRead struct { func (dm *dummyMem) ReadMemory(buf []byte, addr uint64) (int, error) { dm.t.Logf("read addr=%#x size=%#x\n", addr, len(buf)) - dm.reads = append(dm.reads, memRead{uint64(addr), len(buf)}) + dm.reads = append(dm.reads, memRead{addr, len(buf)}) a := int64(addr) - int64(dm.base) if a < 0 { panic("reading below base") diff --git a/pkg/proc/stack.go b/pkg/proc/stack.go index d774300b..e0ed2024 100644 --- a/pkg/proc/stack.go +++ b/pkg/proc/stack.go @@ -251,7 +251,7 @@ func (it *stackIterator) Next() bool { it.regs = *regs it.top = false if it.g != nil && it.g.ID != 0 { - it.systemstack = !(uint64(it.regs.SP()) >= it.g.stack.lo && uint64(it.regs.SP()) < it.g.stack.hi) + it.systemstack = !(it.regs.SP() >= it.g.stack.lo && it.regs.SP() < it.g.stack.hi) } logflags.StackLogger().Debugf("sigtramp context read") return true diff --git a/pkg/proc/target_exec.go b/pkg/proc/target_exec.go index 282167d2..418ee3d3 100644 --- a/pkg/proc/target_exec.go +++ b/pkg/proc/target_exec.go @@ -470,7 +470,7 @@ func sameGoroutineCondition(bi *BinaryInfo, g *G, threadID int) ast.Expr { } return astutil.Eql(astutil.PkgVar("runtime", "threadid"), astutil.Int(int64(threadID))) } - return astutil.Eql(astutil.Sel(astutil.PkgVar("runtime", "curg"), "goid"), astutil.Int(int64(g.ID))) + return astutil.Eql(astutil.Sel(astutil.PkgVar("runtime", "curg"), "goid"), astutil.Int(g.ID)) } func frameoffCondition(frame *Stackframe) ast.Expr { @@ -1316,7 +1316,7 @@ func (t *Target) handleHardcodedBreakpoints(grp *TargetGroup, trapthread Thread, return } if bpsize := isHardcodedBreakpoint(thread, pc); bpsize > 0 { - setPC(thread, pc+uint64(bpsize)) + setPC(thread, pc+bpsize) } } diff --git a/pkg/proc/types.go b/pkg/proc/types.go index 125bff12..3a761f68 100644 --- a/pkg/proc/types.go +++ b/pkg/proc/types.go @@ -114,7 +114,7 @@ func runtimeTypeToDIE(_type *Variable, dataAddr uint64) (typ godwarf.Type, kind if md != nil { so := bi.moduleDataToImage(md) if so != nil { - if rtdie, ok := so.runtimeTypeToDIE[uint64(_type.Addr-md.types)]; ok { + if rtdie, ok := so.runtimeTypeToDIE[_type.Addr-md.types]; ok { typ, err := godwarf.ReadType(so.dwarf, so.index, rtdie.offset, so.typeCache) if err != nil { return nil, 0, fmt.Errorf("invalid interface type: %v", err) @@ -189,7 +189,7 @@ func dwarfToRuntimeType(bi *BinaryInfo, mem MemoryReadWriter, typ godwarf.Type) } } - typeAddr = uint64(md.types) + off + typeAddr = md.types + off rtyp, err := bi.findType(bi.runtimeTypeTypename()) if err != nil { diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index 20f4c284..15eb3b9a 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -959,7 +959,7 @@ func (v *Variable) parseG() (*G, error) { SP: uint64(sp), BP: uint64(bp), LR: uint64(lr), - Status: uint64(status), + Status: status, WaitSince: waitSince, WaitReason: waitReason, CurrentLoc: Location{PC: uint64(pc), File: f, Line: l, Fn: fn}, @@ -1454,7 +1454,7 @@ func convertToEface(srcv, dstv *Variable) error { return srcv.Unreadable } _type = _type.maybeDereference() - dstv.writeEmptyInterface(uint64(_type.Addr), data) + dstv.writeEmptyInterface(_type.Addr, data) return nil } typeAddr, typeKind, runtimeTypeFound, err := dwarfToRuntimeType(srcv.bi, srcv.mem, srcv.RealType) @@ -1738,13 +1738,13 @@ func (v *Variable) readComplex(size int64) { } func (v *Variable) writeComplex(real, imag float64, size int64) error { - err := v.writeFloatRaw(real, int64(size/2)) + err := v.writeFloatRaw(real, size/2) if err != nil { return err } imagaddr := *v imagaddr.Addr += uint64(size / 2) - return imagaddr.writeFloatRaw(imag, int64(size/2)) + return imagaddr.writeFloatRaw(imag, size/2) } func readIntRaw(mem MemoryReadWriter, addr uint64, size int64) (int64, error) { @@ -1781,7 +1781,7 @@ func (v *Variable) writeUint(value uint64, size int64) error { case 4: binary.LittleEndian.PutUint32(val, uint32(value)) case 8: - binary.LittleEndian.PutUint64(val, uint64(value)) + binary.LittleEndian.PutUint64(val, value) } _, err := v.mem.WriteMemory(v.Addr, val) @@ -1805,7 +1805,7 @@ func readUintRaw(mem MemoryReadWriter, addr uint64, size int64) (uint64, error) case 4: n = uint64(binary.LittleEndian.Uint32(val)) case 8: - n = uint64(binary.LittleEndian.Uint64(val)) + n = binary.LittleEndian.Uint64(val) } return n, nil @@ -1841,7 +1841,7 @@ func (v *Variable) writeFloatRaw(f float64, size int64) error { n := float32(f) binary.Write(buf, binary.LittleEndian, n) case 8: - n := float64(f) + n := f binary.Write(buf, binary.LittleEndian, n) } @@ -1878,7 +1878,7 @@ func (v *Variable) writeSlice(len, cap int64, base uint64) error { switch f.Name { case sliceArrayFieldName: arrv, _ := v.toField(f) - if err := arrv.writeUint(uint64(base), arrv.RealType.Size()); err != nil { + if err := arrv.writeUint(base, arrv.RealType.Size()); err != nil { return err } case sliceLenFieldName: @@ -1897,8 +1897,8 @@ func (v *Variable) writeSlice(len, cap int64, base uint64) error { } func (v *Variable) writeString(len, base uint64) error { - writePointer(v.bi, v.mem, uint64(v.Addr), base) - writePointer(v.bi, v.mem, uint64(v.Addr)+uint64(v.bi.Arch.PtrSize()), len) + writePointer(v.bi, v.mem, v.Addr, base) + writePointer(v.bi, v.mem, v.Addr+uint64(v.bi.Arch.PtrSize()), len) return nil } @@ -1931,7 +1931,7 @@ func (v *Variable) readFunctionPtr() { } v.Base = val - fn := v.bi.PCToFunc(uint64(v.Base)) + fn := v.bi.PCToFunc(v.Base) if fn == nil { v.Unreadable = fmt.Errorf("could not find function for %#v", v.Base) return @@ -2406,7 +2406,7 @@ func (v *Variable) registerVariableTypeConv(newtyp string) (*Variable, error) { child.Kind = reflect.Uint32 n = 4 case "uint64": - child = newConstant(constant.MakeUint64(uint64(binary.LittleEndian.Uint64(v.reg.Bytes[i:]))), v.mem) + child = newConstant(constant.MakeUint64(binary.LittleEndian.Uint64(v.reg.Bytes[i:])), v.mem) child.Kind = reflect.Uint64 n = 8 case "float32": diff --git a/pkg/proc/winutil/regs_amd64_arch.go b/pkg/proc/winutil/regs_amd64_arch.go index 4bd19305..80785706 100644 --- a/pkg/proc/winutil/regs_amd64_arch.go +++ b/pkg/proc/winutil/regs_amd64_arch.go @@ -43,23 +43,23 @@ type AMD64Registers struct { // struct and the TEB base address of the thread. func NewAMD64Registers(context *AMD64CONTEXT, TebBaseAddress uint64) *AMD64Registers { regs := &AMD64Registers{ - rax: uint64(context.Rax), - rbx: uint64(context.Rbx), - rcx: uint64(context.Rcx), - rdx: uint64(context.Rdx), - rdi: uint64(context.Rdi), - rsi: uint64(context.Rsi), - rbp: uint64(context.Rbp), - rsp: uint64(context.Rsp), - r8: uint64(context.R8), - r9: uint64(context.R9), - r10: uint64(context.R10), - r11: uint64(context.R11), - r12: uint64(context.R12), - r13: uint64(context.R13), - r14: uint64(context.R14), - r15: uint64(context.R15), - rip: uint64(context.Rip), + rax: context.Rax, + rbx: context.Rbx, + rcx: context.Rcx, + rdx: context.Rdx, + rdi: context.Rdi, + rsi: context.Rsi, + rbp: context.Rbp, + rsp: context.Rsp, + r8: context.R8, + r9: context.R9, + r10: context.R10, + r11: context.R11, + r12: context.R12, + r13: context.R13, + r14: context.R14, + r15: context.R15, + rip: context.Rip, eflags: uint64(context.EFlags), cs: uint64(context.SegCs), fs: uint64(context.SegFs), diff --git a/pkg/terminal/starbind/conv.go b/pkg/terminal/starbind/conv.go index b421e151..adacc596 100644 --- a/pkg/terminal/starbind/conv.go +++ b/pkg/terminal/starbind/conv.go @@ -20,7 +20,7 @@ var autoLoadConfig = api.LoadConfig{MaxVariableRecurse: 1, MaxStringLen: 1024, M func (env *Env) interfaceToStarlarkValue(v interface{}) starlark.Value { switch v := v.(type) { case bool: - return starlark.Bool(bool(v)) + return starlark.Bool(v) case uint8: return starlark.MakeUint64(uint64(v)) case uint16: diff --git a/service/dap/server_test.go b/service/dap/server_test.go index 9e016605..563dbe2e 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -7353,7 +7353,7 @@ func TestFindInstructions(t *testing.T) { { name: "request out of bounds", args: args{ - addr: uint64(uint64(startPC + 2*(numInstructions-1))), + addr: uint64(startPC + 2*(numInstructions-1)), offset: 1, count: numInstructions, }, @@ -7512,11 +7512,11 @@ func TestRedirect(t *testing.T) { // check output if expectStdout != stdout.String() { - t.Errorf("\n got stdout: len:%d\n%s\nwant: len:%d\n%s", stdout.Len(), stdout.String(), len(expectStdout), string(expectStdout)) + t.Errorf("\n got stdout: len:%d\n%s\nwant: len:%d\n%s", stdout.Len(), stdout.String(), len(expectStdout), expectStdout) } if expectStderr != stderr.String() { - t.Errorf("\n got stderr: len:%d \n%s\nwant: len:%d\n%s", stderr.Len(), stderr.String(), len(expectStderr), string(expectStderr)) + t.Errorf("\n got stderr: len:%d \n%s\nwant: len:%d\n%s", stderr.Len(), stderr.String(), len(expectStderr), expectStderr) } // 7 >> disconnect, << disconnect diff --git a/service/test/integration2_test.go b/service/test/integration2_test.go index 364af533..e2161fa0 100644 --- a/service/test/integration2_test.go +++ b/service/test/integration2_test.go @@ -1543,7 +1543,7 @@ func TestSkipPrologue(t *testing.T) { findLocationHelper(t, c, "*fn1", false, 1, afunction) findLocationHelper(t, c, "locationsprog2.go:8", false, 1, afunction) - afunction0 := uint64(clientEvalVariable(t, c, "main.afunction").Addr) + afunction0 := clientEvalVariable(t, c, "main.afunction").Addr if afunction == afunction0 { t.Fatal("Skip prologue failed") @@ -1554,21 +1554,21 @@ func TestSkipPrologue(t *testing.T) { func TestSkipPrologue2(t *testing.T) { withTestClient2("callme", t, func(c service.Client) { callme := findLocationHelper(t, c, "main.callme", false, 1, 0)[0] - callmeZ := uint64(clientEvalVariable(t, c, "main.callme").Addr) + callmeZ := clientEvalVariable(t, c, "main.callme").Addr findLocationHelper(t, c, "callme.go:5", false, 1, callme) if callme == callmeZ { t.Fatal("Skip prologue failed") } callme2 := findLocationHelper(t, c, "main.callme2", false, 1, 0)[0] - callme2Z := uint64(clientEvalVariable(t, c, "main.callme2").Addr) + callme2Z := clientEvalVariable(t, c, "main.callme2").Addr findLocationHelper(t, c, "callme.go:12", false, 1, callme2) if callme2 == callme2Z { t.Fatal("Skip prologue failed") } callme3 := findLocationHelper(t, c, "main.callme3", false, 1, 0)[0] - callme3Z := uint64(clientEvalVariable(t, c, "main.callme3").Addr) + callme3Z := clientEvalVariable(t, c, "main.callme3").Addr ver, _ := goversion.Parse(runtime.Version()) if (ver.Major < 0 || ver.AfterOrEqual(goversion.GoVer18Beta)) && runtime.GOARCH != "386" {