Skip to content

Commit 3adb8be

Browse files
committed
fix: improve error handling in Extract method and skip functions with "go:" prefix
1 parent 5a32dc5 commit 3adb8be

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

internal/disasm/interface.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package disasm
33
import (
44
"errors"
55
"fmt"
6+
"log/slog"
67
"unicode/utf8"
78

89
"github.com/Zxilly/go-size-analyzer/internal/entity"
@@ -83,11 +84,9 @@ func (e *Extractor) Validate(addr, size uint64) bool {
8384
}
8485

8586
func (e *Extractor) Extract(start, end uint64) []PossibleStr {
86-
if start < e.textStart {
87-
panic(fmt.Errorf("start address %#x is before text segment %#x", start, e.textStart))
88-
}
89-
if end > e.textEnd {
90-
panic(fmt.Errorf("end address %#x is after text segment %#x", end, e.textEnd))
87+
if start < e.textStart || end > e.textEnd || start > end {
88+
slog.Debug("skipping function outside text section", "start", fmt.Sprintf("%#x", start), "end", fmt.Sprintf("%#x", end), "textStart", fmt.Sprintf("%#x", e.textStart), "textEnd", fmt.Sprintf("%#x", e.textEnd))
89+
return nil
9190
}
9291

9392
code := e.text[start-e.textStart : end-e.textStart]

internal/entity/package.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"maps"
7+
"strings"
78
"sync"
89

910
"github.com/ZxillyFork/gore"
@@ -90,6 +91,9 @@ func NewPackageWithGorePackage(gp *gore.Package, name string, typ PackageType, p
9091
}
9192

9293
for _, f := range gp.Functions {
94+
if strings.HasPrefix(f.Name, "go:") {
95+
continue
96+
}
9397
src, _, _ := pclntab.PCToLine(f.Offset)
9498
sf := getFunction(f)
9599
sf.Type = FuncTypeFunction

scripts/tool/remote.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,26 @@ def generated_filepath(self, typ: TestType):
7676

7777
def run_test(self, gsa: GSAInstance, log_typ: callable(TestType), timeout=240):
7878
threads = []
79+
errors = []
7980

8081
draw = not self.name.startswith("bin-")
8182

8283
def run(pargs: list[str], typ: TestType):
83-
figure_output = self.performance_figure_filepath(typ)
84-
if not draw:
85-
figure_output = None
86-
87-
gsa.run_with_figure(*pargs,
88-
output=self.output_filepath(typ),
89-
profiler_dir=self.profiler_dir(typ),
90-
figure_name=self.name,
91-
timeout=timeout,
92-
figure_output=figure_output)
93-
94-
log_typ(typ)
84+
try:
85+
figure_output = self.performance_figure_filepath(typ)
86+
if not draw:
87+
figure_output = None
88+
89+
gsa.run_with_figure(*pargs,
90+
output=self.output_filepath(typ),
91+
profiler_dir=self.profiler_dir(typ),
92+
figure_name=self.name,
93+
timeout=timeout,
94+
figure_output=figure_output)
95+
96+
log_typ(typ)
97+
except Exception as e:
98+
errors.append(e)
9599

96100
if TestType.TEXT_TEST in self.type:
97101
threads.append(Thread(target=run, args=(["-f", "text", "--verbose", self.path], TestType.TEXT_TEST)))
@@ -127,6 +131,9 @@ def run(pargs: list[str], typ: TestType):
127131
for t in threads:
128132
t.join()
129133

134+
if errors:
135+
raise errors[0]
136+
130137

131138
class RemoteBinaryType(Enum):
132139
RAW = "raw"

0 commit comments

Comments
 (0)