Skip to content

Commit 227ec02

Browse files
mdempskygopherbot
authored andcommitted
cmd/internal/dwarf: replace Sym.Length with Context.Size
Preparatory refactoring before next CL. Change-Id: I06fb4670b933fddff1a2a70f3cf1eb124cbd86ee Reviewed-on: https://go-review.googlesource.com/c/go/+/524899 Auto-Submit: Matthew Dempsky <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 9b0140a commit 227ec02

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/cmd/internal/dwarf/dwarf.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var logDwarf bool
4040

4141
// Sym represents a symbol.
4242
type Sym interface {
43-
Length(dwarfContext interface{}) int64
4443
}
4544

4645
// A Var represents a local variable or a function parameter.
@@ -189,6 +188,7 @@ type InlCall struct {
189188
// A Context specifies how to add data to a Sym.
190189
type Context interface {
191190
PtrSize() int
191+
Size(s Sym) int64
192192
AddInt(s Sym, size int, i int64)
193193
AddBytes(s Sym, b []byte)
194194
AddAddress(s Sym, t interface{}, ofs int64)
@@ -1322,7 +1322,7 @@ func putInlinedFunc(ctxt Context, s *FnState, callIdx int) error {
13221322
putattr(ctxt, s.Info, abbrev, DW_FORM_ref_addr, DW_CLS_REFERENCE, 0, callee)
13231323

13241324
if abbrev == DW_ABRV_INLINED_SUBROUTINE_RANGES {
1325-
putattr(ctxt, s.Info, abbrev, DW_FORM_sec_offset, DW_CLS_PTR, s.Ranges.Length(ctxt), s.Ranges)
1325+
putattr(ctxt, s.Info, abbrev, DW_FORM_sec_offset, DW_CLS_PTR, ctxt.Size(s.Ranges), s.Ranges)
13261326
s.PutRanges(ctxt, ic.Ranges)
13271327
} else {
13281328
st := ic.Ranges[0].Start
@@ -1535,7 +1535,7 @@ func putscope(ctxt Context, s *FnState, scopes []Scope, curscope int32, fnabbrev
15351535
putattr(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_SIMPLE, DW_FORM_addr, DW_CLS_ADDRESS, scope.Ranges[0].End, s.StartPC)
15361536
} else {
15371537
Uleb128put(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_RANGES)
1538-
putattr(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_RANGES, DW_FORM_sec_offset, DW_CLS_PTR, s.Ranges.Length(ctxt), s.Ranges)
1538+
putattr(ctxt, s.Info, DW_ABRV_LEXICAL_BLOCK_RANGES, DW_FORM_sec_offset, DW_CLS_PTR, ctxt.Size(s.Ranges), s.Ranges)
15391539

15401540
s.PutRanges(ctxt, scope.Ranges)
15411541
}
@@ -1684,7 +1684,7 @@ func putvar(ctxt Context, s *FnState, v *Var, absfn Sym, fnabbrev, inlIndex int,
16841684
}
16851685

16861686
if abbrevUsesLoclist(abbrev) {
1687-
putattr(ctxt, s.Info, abbrev, DW_FORM_sec_offset, DW_CLS_PTR, s.Loc.Length(ctxt), s.Loc)
1687+
putattr(ctxt, s.Info, abbrev, DW_FORM_sec_offset, DW_CLS_PTR, ctxt.Size(s.Loc), s.Loc)
16881688
v.PutLocationList(s.Loc, s.StartPC)
16891689
} else {
16901690
loc := encbuf[:0]

src/cmd/internal/obj/dwarf.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ type dwCtxt struct{ *Link }
207207
func (c dwCtxt) PtrSize() int {
208208
return c.Arch.PtrSize
209209
}
210+
func (c dwCtxt) Size(s dwarf.Sym) int64 {
211+
return s.(*LSym).Size
212+
}
210213
func (c dwCtxt) AddInt(s dwarf.Sym, size int, i int64) {
211214
ls := s.(*LSym)
212215
ls.WriteInt(c.Link, ls.Size, size, i)
@@ -315,10 +318,6 @@ func (ctxt *Link) dwarfSym(s *LSym) (dwarfInfoSym, dwarfLocSym, dwarfRangesSym,
315318
return fn.dwarfInfoSym, fn.dwarfLocSym, fn.dwarfRangesSym, fn.dwarfAbsFnSym, fn.dwarfDebugLinesSym
316319
}
317320

318-
func (s *LSym) Length(dwarfContext interface{}) int64 {
319-
return s.Size
320-
}
321-
322321
// textPos returns the source position of the first instruction (prog)
323322
// of the specified function.
324323
func textPos(fn *LSym) src.XPos {

src/cmd/link/internal/ld/dwarf.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ type dwctxt struct {
7373
// DwAttr objects contain references to symbols via this type.
7474
type dwSym loader.Sym
7575

76-
func (s dwSym) Length(dwarfContext interface{}) int64 {
77-
l := dwarfContext.(dwctxt).ldr
78-
return int64(len(l.Data(loader.Sym(s))))
79-
}
80-
8176
func (c dwctxt) PtrSize() int {
8277
return c.arch.PtrSize
8378
}
8479

80+
func (c dwctxt) Size(s dwarf.Sym) int64 {
81+
return int64(len(c.ldr.Data(loader.Sym(s.(dwSym)))))
82+
}
83+
8584
func (c dwctxt) AddInt(s dwarf.Sym, size int, i int64) {
8685
ds := loader.Sym(s.(dwSym))
8786
dsu := c.ldr.MakeSymbolUpdater(ds)

0 commit comments

Comments
 (0)