Skip to content

Commit 938cb6e

Browse files
authored
pkg,service: remove unnecessary convertions (#3564)
1 parent e6fdc10 commit 938cb6e

31 files changed

+95
-95
lines changed

pkg/dwarf/dwarfbuilder/info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func (b *Builder) Attr(attr dwarf.Attr, val interface{}) dwarf.Offset {
167167
binary.Write(&b.loc, binary.LittleEndian, uint64(0))
168168

169169
for _, locentry := range x {
170-
binary.Write(&b.loc, binary.LittleEndian, uint64(locentry.Lowpc))
171-
binary.Write(&b.loc, binary.LittleEndian, uint64(locentry.Highpc))
170+
binary.Write(&b.loc, binary.LittleEndian, locentry.Lowpc)
171+
binary.Write(&b.loc, binary.LittleEndian, locentry.Highpc)
172172
binary.Write(&b.loc, binary.LittleEndian, uint16(len(locentry.Loc)))
173173
b.loc.Write(locentry.Loc)
174174
}

pkg/dwarf/leb128/decode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func DecodeSigned(buf Reader) (int64, uint32) {
6767
}
6868
length++
6969

70-
result |= int64((int64(b) & 0x7f) << shift)
70+
result |= (int64(b) & 0x7f) << shift
7171
shift += 7
7272
if b&0x80 == 0 {
7373
break

pkg/dwarf/line/line_parser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ func parseDebugLinePrologue(dbl *DebugLineInfo, buf *bytes.Buffer) {
132132
}
133133

134134
p.Length = binary.LittleEndian.Uint32(buf.Next(4))
135-
p.MinInstrLength = uint8(buf.Next(1)[0])
135+
p.MinInstrLength = buf.Next(1)[0]
136136
if p.Version >= 4 {
137-
p.MaxOpPerInstr = uint8(buf.Next(1)[0])
137+
p.MaxOpPerInstr = buf.Next(1)[0]
138138
} else {
139139
p.MaxOpPerInstr = 1
140140
}
141-
p.InitialIsStmt = uint8(buf.Next(1)[0])
141+
p.InitialIsStmt = buf.Next(1)[0]
142142
p.LineBase = int8(buf.Next(1)[0])
143-
p.LineRange = uint8(buf.Next(1)[0])
144-
p.OpcodeBase = uint8(buf.Next(1)[0])
143+
p.LineRange = buf.Next(1)[0]
144+
p.OpcodeBase = buf.Next(1)[0]
145145

146146
p.StdOpLengths = make([]uint8, p.OpcodeBase-1)
147147
binary.Read(buf, binary.LittleEndian, &p.StdOpLengths)

pkg/dwarf/line/state_machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func (sm *StateMachine) next() error {
423423

424424
func execSpecialOpcode(sm *StateMachine, instr byte) {
425425
var (
426-
opcode = uint8(instr)
426+
opcode = instr
427427
decoded = opcode - sm.dbl.Prologue.OpcodeBase
428428
)
429429

pkg/dwarf/loclist/dwarf2_loclist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (rdr *Dwarf2Reader) oneAddr() uint64 {
8787
}
8888
return uint64(addr)
8989
case 8:
90-
addr := uint64(binary.LittleEndian.Uint64(rdr.read(rdr.ptrSz)))
90+
addr := binary.LittleEndian.Uint64(rdr.read(rdr.ptrSz))
9191
return addr
9292
default:
9393
panic("bad address size")

pkg/dwarf/op/op.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func callframecfa(opcode Opcode, ctxt *context) error {
208208
if ctxt.CFA == 0 {
209209
return errors.New("could not retrieve CFA for current PC")
210210
}
211-
ctxt.stack = append(ctxt.stack, int64(ctxt.CFA))
211+
ctxt.stack = append(ctxt.stack, ctxt.CFA)
212212
return nil
213213
}
214214

@@ -373,7 +373,7 @@ func pick(opcode Opcode, ctxt *context) error {
373373
default:
374374
panic("internal error")
375375
}
376-
idx := len(ctxt.stack) - 1 - int(uint8(n))
376+
idx := len(ctxt.stack) - 1 - int(n)
377377
if idx < 0 || idx >= len(ctxt.stack) {
378378
return ErrStackIndexOutOfBounds
379379
}

pkg/elfwriter/writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func New(w WriteCloserSeeker, fhdr *elf.FileHeader) *Writer {
5858
}
5959

6060
// e_ident
61-
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})
61+
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})
6262

6363
r.u16(uint16(fhdr.Type)) // e_type
6464
r.u16(uint16(fhdr.Machine)) // e_machine

pkg/locspec/locations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ func (loc *AddrLocationSpec) Find(t *proc.Target, _ []string, scope *proc.EvalSc
311311
addr, _ := constant.Uint64Val(v.Value)
312312
return []api.Location{{PC: addr}}, "", nil
313313
case reflect.Func:
314-
fn := scope.BinInfo.PCToFunc(uint64(v.Base))
314+
fn := scope.BinInfo.PCToFunc(v.Base)
315315
pc, err := proc.FirstPCAfterPrologue(t, fn, false)
316316
if err != nil {
317317
return nil, "", err

pkg/proc/amd64_arch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func amd64SwitchStack(it *stackIterator, _ *op.DwarfRegisters) bool {
150150
// switches from the goroutine stack to the system stack.
151151
// Since we are unwinding the stack from callee to caller we have to switch
152152
// from the system stack to the goroutine stack.
153-
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
153+
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
154154
oldsp := it.regs.SP()
155155
it.regs.Reg(it.regs.SPRegNum).Uint64Val = uint64(int64(it.stackhi) - off)
156156

@@ -190,7 +190,7 @@ func amd64SwitchStack(it *stackIterator, _ *op.DwarfRegisters) bool {
190190
// entering the system stack
191191
it.regs.Reg(it.regs.SPRegNum).Uint64Val = it.g0_sched_sp
192192
// reads the previous value of g0.sched.sp that runtime.cgocallback_gofunc saved on the stack
193-
it.g0_sched_sp, _ = readUintRaw(it.mem, uint64(it.regs.SP()), int64(it.bi.Arch.PtrSize()))
193+
it.g0_sched_sp, _ = readUintRaw(it.mem, it.regs.SP(), int64(it.bi.Arch.PtrSize()))
194194
it.top = false
195195
callFrameRegs, ret, retaddr := it.advanceRegs()
196196
frameOnSystemStack := it.newStackframe(ret, retaddr)
@@ -409,7 +409,7 @@ func formatX87Reg(b []byte) string {
409409
return fmt.Sprintf("%#x", b)
410410
}
411411
mantissa := binary.LittleEndian.Uint64(b[:8])
412-
exponent := uint16(binary.LittleEndian.Uint16(b[8:]))
412+
exponent := binary.LittleEndian.Uint16(b[8:])
413413

414414
var f float64
415415
fset := false

pkg/proc/arm64_arch.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool
174174
// Entering the system stack.
175175
it.regs.Reg(callFrameRegs.SPRegNum).Uint64Val = it.g0_sched_sp
176176
// Reads the previous value of g0.sched.sp that runtime.cgocallback_gofunc saved on the stack.
177-
it.g0_sched_sp, _ = readUintRaw(it.mem, uint64(it.regs.SP()+prevG0schedSPOffsetSaveSlot), int64(it.bi.Arch.PtrSize()))
177+
it.g0_sched_sp, _ = readUintRaw(it.mem, it.regs.SP()+prevG0schedSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize()))
178178
it.top = false
179179
callFrameRegs, ret, retaddr := it.advanceRegs()
180180
frameOnSystemStack := it.newStackframe(ret, retaddr)
@@ -195,7 +195,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool
195195
// switches from the goroutine stack to the system stack.
196196
// Since we are unwinding the stack from callee to caller we have to switch
197197
// from the system stack to the goroutine stack.
198-
off, _ := readIntRaw(it.mem, uint64(it.regs.SP()+arm64cgocallSPOffsetSaveSlot),
198+
off, _ := readIntRaw(it.mem, it.regs.SP()+arm64cgocallSPOffsetSaveSlot,
199199
int64(it.bi.Arch.PtrSize()))
200200
oldsp := it.regs.SP()
201201
newsp := uint64(int64(it.stackhi) - off)
@@ -239,20 +239,20 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool
239239
bpoff = 22
240240
lroff = 23
241241
}
242-
newsp, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*24), int64(it.bi.Arch.PtrSize()))
243-
newbp, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*bpoff), int64(it.bi.Arch.PtrSize()))
244-
newlr, _ := readUintRaw(it.mem, uint64(it.regs.SP()+8*lroff), int64(it.bi.Arch.PtrSize()))
242+
newsp, _ := readUintRaw(it.mem, it.regs.SP()+8*24, int64(it.bi.Arch.PtrSize()))
243+
newbp, _ := readUintRaw(it.mem, it.regs.SP()+8*bpoff, int64(it.bi.Arch.PtrSize()))
244+
newlr, _ := readUintRaw(it.mem, it.regs.SP()+8*lroff, int64(it.bi.Arch.PtrSize()))
245245
if it.regs.Reg(it.regs.BPRegNum) != nil {
246-
it.regs.Reg(it.regs.BPRegNum).Uint64Val = uint64(newbp)
246+
it.regs.Reg(it.regs.BPRegNum).Uint64Val = newbp
247247
} else {
248248
reg, _ := it.readRegisterAt(it.regs.BPRegNum, it.regs.SP()+8*bpoff)
249249
it.regs.AddReg(it.regs.BPRegNum, reg)
250250
}
251-
it.regs.Reg(it.regs.LRRegNum).Uint64Val = uint64(newlr)
251+
it.regs.Reg(it.regs.LRRegNum).Uint64Val = newlr
252252
if linux {
253-
it.regs.Reg(it.regs.SPRegNum).Uint64Val = uint64(newbp)
253+
it.regs.Reg(it.regs.SPRegNum).Uint64Val = newbp
254254
} else {
255-
it.regs.Reg(it.regs.SPRegNum).Uint64Val = uint64(newsp)
255+
it.regs.Reg(it.regs.SPRegNum).Uint64Val = newsp
256256
}
257257
it.pc = newlr
258258
return true
@@ -299,7 +299,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool
299299
// switches from the goroutine stack to the system stack.
300300
// Since we are unwinding the stack from callee to caller we have to switch
301301
// from the system stack to the goroutine stack.
302-
off, _ := readIntRaw(it.mem, uint64(callFrameRegs.SP()+arm64cgocallSPOffsetSaveSlot), int64(it.bi.Arch.PtrSize()))
302+
off, _ := readIntRaw(it.mem, callFrameRegs.SP()+arm64cgocallSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize()))
303303
oldsp := callFrameRegs.SP()
304304
newsp := uint64(int64(it.stackhi) - off)
305305

@@ -334,7 +334,7 @@ func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool
334334
callFrameRegs.Reg(callFrameRegs.SPRegNum).Uint64Val = it.g0_sched_sp
335335
// reads the previous value of g0.sched.sp that runtime.cgocallback_gofunc saved on the stack
336336

337-
it.g0_sched_sp, _ = readUintRaw(it.mem, uint64(callFrameRegs.SP()+prevG0schedSPOffsetSaveSlot), int64(it.bi.Arch.PtrSize()))
337+
it.g0_sched_sp, _ = readUintRaw(it.mem, callFrameRegs.SP()+prevG0schedSPOffsetSaveSlot, int64(it.bi.Arch.PtrSize()))
338338
it.systemstack = true
339339
return false
340340
}

0 commit comments

Comments
 (0)