xref: /openbsd-src/gnu/usr.bin/binutils/gdb/doc/LRS (revision b725ae7711052a2233e31a66fefb8a752c388d7a)
1*b725ae77SkettenisWhat's LRS?
2*b725ae77Skettenis===========
3*b725ae77Skettenis
4*b725ae77SkettenisLRS, or Live Range Splitting is an optimization technique which allows
5*b725ae77Skettenisa user variable to reside in different locations during different parts
6*b725ae77Skettenisof a function.
7*b725ae77Skettenis
8*b725ae77SkettenisFor example, a variable might reside in the stack for part of a function
9*b725ae77Skettenisand in a register during a loop and in a different register during
10*b725ae77Skettenisanother loop.
11*b725ae77Skettenis
12*b725ae77SkettenisClearly, if a variable may reside in different locations, then the
13*b725ae77Sketteniscompiler must describe to the debugger where the variable resides for
14*b725ae77Skettenisany given part of the function.
15*b725ae77Skettenis
16*b725ae77SkettenisThis document describes the debug format for encoding these extensions
17*b725ae77Skettenisin stabs.
18*b725ae77Skettenis
19*b725ae77SkettenisSince these extensions are gcc specific, these additional symbols and
20*b725ae77Skettenisstabs can be disabled by the gcc command option -gstabs.
21*b725ae77Skettenis
22*b725ae77Skettenis
23*b725ae77SkettenisGNU extensions for LRS under stabs:
24*b725ae77Skettenis===================================
25*b725ae77Skettenis
26*b725ae77Skettenis
27*b725ae77Skettenisrange symbols:
28*b725ae77Skettenis-------------
29*b725ae77Skettenis
30*b725ae77Skettenis    A range symbol will be used to mark the beginning or end of a
31*b725ae77Skettenis    live range (the range which describes where a symbol is active,
32*b725ae77Skettenis    or live).  These symbols will later be referenced in the stabs for
33*b725ae77Skettenis    debug purposes.  For simplicity, we'll use the terms "range_start"
34*b725ae77Skettenis    and "range_end" to identify the range symbols which mark the beginning
35*b725ae77Skettenis    and end of a live range respectively.
36*b725ae77Skettenis
37*b725ae77Skettenis    Any text symbol which would normally appear in the symbol table
38*b725ae77Skettenis    (eg. a function name) can be used as range symbol.  If an address
39*b725ae77Skettenis    is needed to delimit a live range and does not match any of the
40*b725ae77Skettenis    values of symbols which would normally appear in the symbol table,
41*b725ae77Skettenis    a new symbol will be added to the table whose value is that address.
42*b725ae77Skettenis
43*b725ae77Skettenis    The three new symbol types described below have been added for this
44*b725ae77Skettenis    purpose.
45*b725ae77Skettenis
46*b725ae77Skettenis    For efficiency, the compiler should use existing symbols as range
47*b725ae77Skettenis    symbols whenever possible; this reduces the number of additional
48*b725ae77Skettenis    symbols which need to be added to the symbol table.
49*b725ae77Skettenis
50*b725ae77Skettenis
51*b725ae77SkettenisNew debug symbol type for defining ranges:
52*b725ae77Skettenis------------------------------------------
53*b725ae77Skettenis
54*b725ae77Skettenis    range_off - contains PC function offset for start/end of a live range.
55*b725ae77Skettenis		Its location is relative to the function start and therefore
56*b725ae77Skettenis		eliminates the need for additional relocation.
57*b725ae77Skettenis
58*b725ae77Skettenis    This symbol has a values in the text section, and does not have a name.
59*b725ae77Skettenis
60*b725ae77Skettenis	    NOTE: the following may not be needed but are included here just
61*b725ae77Skettenis		in case.
62*b725ae77Skettenis	    range - contains PC value of beginning or end of a live range
63*b725ae77Skettenis		(relocs required).
64*b725ae77Skettenis
65*b725ae77Skettenis	    NOTE: the following will be required if we desire LRS debugging
66*b725ae77Skettenis		to work with old style a.out stabs.
67*b725ae77Skettenis	    range_abs - contains absolute PC value of start/end of a live
68*b725ae77Skettenis		range.  The range_abs debug symbol is provided for
69*b725ae77Skettenis		completeness, in case there is a need to describe addresses
70*b725ae77Skettenis		in ROM, etc.
71*b725ae77Skettenis
72*b725ae77Skettenis
73*b725ae77SkettenisLive range:
74*b725ae77Skettenis-----------
75*b725ae77Skettenis
76*b725ae77Skettenis    The compiler and debugger view a variable with multiple homes as
77*b725ae77Skettenis    a primary symbol and aliases for that symbol.  The primary symbol
78*b725ae77Skettenis    describes the default home of the variable while aliases describe
79*b725ae77Skettenis    alternate homes for the variable.
80*b725ae77Skettenis
81*b725ae77Skettenis    A live range defines the interval of instructions beginning with
82*b725ae77Skettenis    range_start and ending at range_end-1, and is used to specify a
83*b725ae77Skettenis    range of instructions where an alias is active or "live".  So,
84*b725ae77Skettenis    the actual end of the range will be one less than the value of the
85*b725ae77Skettenis    range_end symbol.
86*b725ae77Skettenis
87*b725ae77Skettenis    Ranges do not have to be nested. Eg. Two ranges may intersect while
88*b725ae77Skettenis        each range contains subranges which are not in the other range.
89*b725ae77Skettenis
90*b725ae77Skettenis    There does not have to be a 1-1 mapping from range_start to
91*b725ae77Skettenis        range_end symbols.  Eg. Two range_starts can share the same
92*b725ae77Skettenis        range_end, while one symbol's range_start can be another symbol's
93*b725ae77Skettenis        range_end.
94*b725ae77Skettenis
95*b725ae77Skettenis    When a variable's storage class changes (eg. from stack to register,
96*b725ae77Skettenis	or from one register to another), a new symbol entry will be
97*b725ae77Skettenis	added to the symbol table with stabs describing the new type,
98*b725ae77Skettenis	and appropriate live ranges refering to the variable's initial
99*b725ae77Skettenis	symbol index.
100*b725ae77Skettenis
101*b725ae77Skettenis    For variables which are defined in the source but optimized away,
102*b725ae77Skettenis        a symbol should be emitted with the live range l(0,0).
103*b725ae77Skettenis
104*b725ae77Skettenis    Live ranges for aliases of a particular variable should always
105*b725ae77Skettenis	be disjoint.  Overlapping ranges for aliases of the same variable
106*b725ae77Skettenis	will be treated as an error by the debugger, and the overlapping
107*b725ae77Skettenis	range will be ignored.
108*b725ae77Skettenis
109*b725ae77Skettenis    If no live range information is given, the live range will be assumed to
110*b725ae77Skettenis	span the symbol's entire lexical scope.
111*b725ae77Skettenis
112*b725ae77Skettenis
113*b725ae77SkettenisNew stabs string identifiers:
114*b725ae77Skettenis-----------------------------
115*b725ae77Skettenis
116*b725ae77Skettenis  "id" in "#id" in the following section refers to a numeric value.
117*b725ae77Skettenis
118*b725ae77Skettenis  New stab syntax for live range:  l(<ref_from>,<ref_to>)
119*b725ae77Skettenis
120*b725ae77Skettenis    <ref_from> - "#id" where #id identifies the text symbol (range symbol) to
121*b725ae77Skettenis		use as the start of live range (range_start).  The value for
122*b725ae77Skettenis		the referenced text symbol is the starting address of the
123*b725ae77Skettenis		live range.
124*b725ae77Skettenis
125*b725ae77Skettenis    <ref_to> - "#id" where #id identifies the text symbol (range symbol) to
126*b725ae77Skettenis		use as the end of live range (range_end).  The value for
127*b725ae77Skettenis		the referenced text symbol is ONE BYTE PAST the ending
128*b725ae77Skettenis		address of the live range.
129*b725ae77Skettenis
130*b725ae77Skettenis
131*b725ae77Skettenis  New stab syntax for identifying symbols.
132*b725ae77Skettenis
133*b725ae77Skettenis    <def> - "#id="
134*b725ae77Skettenis
135*b725ae77Skettenis	    Uses:
136*b725ae77Skettenis	      <def><name>:<typedef1>...
137*b725ae77Skettenis		  When used in front of a symbol name, "#id=" defines a
138*b725ae77Skettenis		  unique reference number for this symbol.  The reference
139*b725ae77Skettenis		  number can be used later when defining aliases for this
140*b725ae77Skettenis		  symbol.
141*b725ae77Skettenis	      <def>
142*b725ae77Skettenis		  When used as the entire stab string, "#id=" identifies this
143*b725ae77Skettenis		  nameless symbol as being the symbol for which "#id" refers to.
144*b725ae77Skettenis
145*b725ae77Skettenis
146*b725ae77Skettenis    <ref> - "#id" where "#id" refers to the symbol for which the string
147*b725ae77Skettenis		"#id=" identifies.
148*b725ae77Skettenis	    Uses:
149*b725ae77Skettenis	      <ref>:<typedef2>;<liverange>;<liverange>...
150*b725ae77Skettenis		  Defines an alias for the symbol identified by the reference
151*b725ae77Skettenis		  number ID.
152*b725ae77Skettenis	      l(<ref1>,<ref2>)
153*b725ae77Skettenis		  When used within a live range, "#id" refers to the text
154*b725ae77Skettenis		  symbol identified by "#id=" to use as the range symbol.
155*b725ae77Skettenis
156*b725ae77Skettenis    <liverange> - "l(<ref_from>,<ref_to>)" - specifies a live range for a
157*b725ae77Skettenis		symbol.  Multiple "l" specifiers can be combined to represent
158*b725ae77Skettenis		mutiple live ranges, separated by semicolons.
159*b725ae77Skettenis
160*b725ae77Skettenis
161*b725ae77Skettenis
162*b725ae77Skettenis
163*b725ae77SkettenisExample:
164*b725ae77Skettenis========
165*b725ae77Skettenis
166*b725ae77SkettenisConsider a program of the form:
167*b725ae77Skettenis
168*b725ae77Skettenis    void foo(){
169*b725ae77Skettenis      int a = ...;
170*b725ae77Skettenis      ...
171*b725ae77Skettenis      while (b--)
172*b725ae77Skettenis       c += a;
173*b725ae77Skettenis      ..
174*b725ae77Skettenis      d = a;
175*b725ae77Skettenis      ..
176*b725ae77Skettenis    }
177*b725ae77Skettenis
178*b725ae77SkettenisAssume that "a" lives in the stack at offset -8, except for inside the
179*b725ae77Skettenisloop where "a" resides in register "r5".
180*b725ae77Skettenis
181*b725ae77SkettenisThe way to describe this is to create a stab for the variable "a" which
182*b725ae77Skettenisdescribes "a" as living in the stack and an alias for the variable "a"
183*b725ae77Sketteniswhich describes it as living in register "r5" in the loop.
184*b725ae77Skettenis
185*b725ae77SkettenisLet's assume that "#1" and "#2" are symbols which bound the area where
186*b725ae77Skettenis"a" lives in a register.
187*b725ae77Skettenis
188*b725ae77SkettenisThe stabs to describe "a" and its alias would look like this:
189*b725ae77Skettenis
190*b725ae77Skettenis        .stabs "#3=a:1",128,0,8,-8
191*b725ae77Skettenis        .stabs "#3:r1;l(#1,#2)",64,0,0,5
192*b725ae77Skettenis
193*b725ae77Skettenis
194*b725ae77SkettenisThis design implies that the debugger will keep a chain of aliases for
195*b725ae77Skettenisany given variable with aliases and that chain will be searched first
196*b725ae77Skettenisto find out if an alias is active.  If no alias is active, then the
197*b725ae77Skettenisdebugger will assume that the main variable is active.
198