Skip to content

Commit

Permalink
proc: optimize RegistersToDwarfRegisters
Browse files Browse the repository at this point in the history
Benchmark before:

BenchmarkConditionalBreakpoints-4              1        11570508729 ns/op

Benchmark after:

BenchmarkConditionalBreakpoints-4   	       1	10013510647 ns/op

Conditional breakpoint evaluation 1.2ms -> 1.0ms

Updates go-delve#1549
  • Loading branch information
aarzilli committed Jan 25, 2020
1 parent 5da9b76 commit ba7f4ea
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/proc/amd64_arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ var amd64DwarfToName = map[int]string{
66: "sw",
}

var amd64NameToDwarf = func() map[string]int {
r := make(map[string]int)
for regNum, regName := range amd64DwarfToName {
r[regName] = regNum
}
return r
}()

func maxAmd64DwarfRegister() int {
max := int(amd64DwarfIPRegNum)
for i := range amd64DwarfToHardware {
Expand Down Expand Up @@ -393,11 +401,8 @@ func (a *AMD64) RegistersToDwarfRegisters(staticBase uint64, regs Registers) op.
}

for _, reg := range regs.Slice(true) {
regName1 := strings.ToLower(reg.Name)
for dwarfReg, regName := range amd64DwarfToName {
if regName == regName1 {
dregs[dwarfReg] = reg.Reg
}
if dwarfReg, ok := amd64NameToDwarf[strings.ToLower(reg.Name)]; ok {
dregs[dwarfReg] = reg.Reg
}
}

Expand Down

0 comments on commit ba7f4ea

Please sign in to comment.