| 1 |
:sectnums: |
| 2 |
== Goal |
| 3 |
|
| 4 |
A mechanism is needed by which programs executed under the Java^TM^ virtual |
| 5 |
machine but written in languages other than the Java programming language, |
| 6 |
can be debugged with references to the original source (for example, source |
| 7 |
file and line number references). |
| 8 |
|
| 9 |
Constraints: |
| 10 |
|
| 11 |
* No change to the Java programming language. |
| 12 |
* Optional change to Java programming language compiler. |
| 13 |
* No change to JPDA clients (debuggers, ...) for basic functionality. With the |
| 14 |
exception being, tools that arbitrarily prohibit non-Java programming language |
| 15 |
source. |
| 16 |
* Minimal change to Java virtual machine. |
| 17 |
* No change to the Java platform class libraries. |
| 18 |
|
| 19 |
== Terminology |
| 20 |
|
| 21 |
[width="100%",cols=".^30%s,70%",options="header"] |
| 22 |
|=== |
| 23 |
|Term |Definition |
| 24 |
|[#TermFinalSource]#final-source# |
| 25 |
|The final form of source. This source will be <<TermCompiler,compiled>> into a |
| 26 |
<<TermClassFile,class file>>. Typically, final-source is Java programming |
| 27 |
language source. |
| 28 |
|
| 29 |
|[#TermTranslatedSource]#translated-source# |
| 30 |
|Source that will be translated by a |
| 31 |
<<TermLanguageProcessor,language-processor>> into another language or form. |
| 32 |
|
| 33 |
|[#TermLanguageProcessor]#language-processor# |
| 34 |
|Converts <<TermTranslatedSource,translated-source>> to |
| 35 |
<<TermFinalSource,final-source>> or to different |
| 36 |
<<TermTranslatedSource,translated-source>>. |
| 37 |
|
| 38 |
|[#TermClassFile]#class file# |
| 39 |
|A collection of bytes in Java virtual machine class file format. |
| 40 |
|
| 41 |
|[#TermCompiler]#compiler# |
| 42 |
|Compiler which converts <<TermFinalSource,final-source>> to class files. For |
| 43 |
example, `javac` is a compiler. |
| 44 |
|
| 45 |
|[#TermPostProcessor]#post-processor# |
| 46 |
|Takes a <<TermClassFile,class file>> and a |
| 47 |
<<TermSourceMapFile,Source Map File>> as input; generates a class file as |
| 48 |
output. Inserts a <<TermSourceDebugExtension,SourceDebugExtension attribute>>. |
| 49 |
|
| 50 |
|[#TermSourceMap]#Source Map# + |
| 51 |
SMAP |
| 52 |
|Specifies the mapping of source between one or more sets of input source and |
| 53 |
the output source. See: <<Source Map Format>>. |
| 54 |
|
| 55 |
|[#TermSourceMapFile]#Source Map File# + |
| 56 |
SMAP-file |
| 57 |
|Specifies the mapping created by a |
| 58 |
<<TermLanguageProcessor,language-processor>> between |
| 59 |
<<TermTranslatedSource,translated-source>> input and the resultant output |
| 60 |
source. It is a <<TermSourceMap,Source Map>> stored in a file in |
| 61 |
<<Source Map Format>>. |
| 62 |
|
| 63 |
|[#TermStratum]#stratum# |
| 64 |
|A view of a class from a particular, named, programming language level. |
| 65 |
|
| 66 |
|[#TermJPDA]#JPDA# |
| 67 |
|The https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/index.html[Java |
| 68 |
Platform Debugger Architecture]. |
| 69 |
|
| 70 |
|[#TermJDI]#JDI# |
| 71 |
|The Java Debug Interface, which is the high-level Java programming language |
| 72 |
interface of the |
| 73 |
https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/[Java Platform Debugger |
| 74 |
Architecture]. See: |
| 75 |
https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/[JDI Specification]. |
| 76 |
|
| 77 |
|[#TermSourceDebugExtension]#SourceDebugExtension + |
| 78 |
attribute# |
| 79 |
|A Java virtual machine class file attribute that holds information about the |
| 80 |
source. In this case, the information is a |
| 81 |
<<TermSourceMap,Source Map>> in <<Source Map Format>>. The source |
| 82 |
is mapped to <<TermFinalSource,final-source>> (output source). The Source Map |
| 83 |
has potentially multiple sets of input source (<<TermStratum,strata>>). |
| 84 |
See: <<attribute,SourceDebugExtension Class File Attribute>> |
| 85 |
|=== |
| 86 |
|
| 87 |
|
| 88 |
== Approach |
| 89 |
|
| 90 |
=== Single Translation |
| 91 |
|
| 92 |
A <<TermLanguageProcessor,language-processor>> translates |
| 93 |
<<TermTranslatedSource,translated-source>> to <<TermFinalSource,final-source>> |
| 94 |
(the case of translation from one <<TermTranslatedSource,translated-source>> to |
| 95 |
another translated-source, is addressed <<Multiple Translations,below>>). It |
| 96 |
also creates a second output, an <<TermSourceMapFile,SMAP-file>>, whose format |
| 97 |
is described in <<Source Map Format>>. This file describes the mapping between |
| 98 |
input source and output source (e.g. line number and source file). |
| 99 |
|
| 100 |
The <<TermFinalSource,final-source>> generated by the |
| 101 |
<<TermLanguageProcessor,language-processor>> is compiled by the |
| 102 |
<<TermCompiler,compiler>>. |
| 103 |
|
| 104 |
The <<TermPostProcessor,post-processor>> takes the class file generated by the |
| 105 |
<<TermCompiler,compiler>> and the <<TermSourceMapFile,SMAP-file>> as input. A |
| 106 |
<<TermSourceDebugExtension, SourceDebugExtension>> attribute containing the SMAP |
| 107 |
in the SMAP-file is added to the class file and the new class file is written. |
| 108 |
|
| 109 |
Optionally, the <<TermCompiler,compiler>> may take both |
| 110 |
<<TermFinalSource,final-source>> and the SMAP-file as input, and perform both |
| 111 |
compilation and installation of the SourceDebugExtension. |
| 112 |
|
| 113 |
When the resultant program is debugged using a debugging tool based on the Java |
| 114 |
Debug Interface + |
| 115 |
(<<TermJDI,JDI>>) of <<TermJPDA,JPDA>>, the final-source line |
| 116 |
number information is converted to the specified language view |
| 117 |
(<<TermStratum,strata>>). |
| 118 |
|
| 119 |
=== Multiple Translations |
| 120 |
|
| 121 |
A language-processor might translate source into source which will become input |
| 122 |
to another language-processor, and so on. Eventually, after possibly many |
| 123 |
translated-source forms, final-source is produced. Each translation produces |
| 124 |
SMAP information. This information must be preserved and placed in context, so |
| 125 |
that each <<TermStratum,stratum>> can be mapped to the final-source. |
| 126 |
|
| 127 |
A language-processor checks for an <<TermSourceMapFile,SMAP-file>> in a location |
| 128 |
parallel to that of the input source. For example, if the source repository is a |
| 129 |
file system and the input source is located at `path name.extension` then |
| 130 |
`path name.extension.smap` will be checked for an SMAP. The input SMAPs will be |
| 131 |
copied into the generated SMAP. See <<Embedded Source Maps>> for specifics on |
| 132 |
the embedding of input SMAPs. |
| 133 |
|
| 134 |
In the case of multiple translations, the <<TermPostProcessor,post-processor>> |
| 135 |
must resolve the embedded SMAPs. See <<SMAP Resolution>>. |
| 136 |
|
| 137 |
Note that final-source need not be Java programming language source, as |
| 138 |
compilers for other languages may directly generate class files, including the |
| 139 |
`SourceFile` and `LineNumberTable` class file attributes. SMAPs and the |
| 140 |
mechanism presented here are still useful for handling multiple translations. |
| 141 |
|
| 142 |
A programming language implementor, directly generating class files might also |
| 143 |
choose to generate SMAPs (thus functioning as both language-processor and |
| 144 |
compiler) since the SMAP is useful for describing source configurations (such as |
| 145 |
multiple source files per class file) which cannot be represented with the |
| 146 |
`SourceFile` and `LineNumberTable` attributes. In this case, the input is |
| 147 |
translated-source and the final-source is represented in the attributes but is |
| 148 |
never generated. |
| 149 |
|
| 150 |
=== Diagram |
| 151 |
|
| 152 |
This diagram demonstrates data flow. The particular case shown has two levels of |
| 153 |
translation, with file inclusion on the second level (as is the case in the |
| 154 |
example in <<SMAP Resolution>>). |
| 155 |
|
| 156 |
image:data-flow.png[data flow diagram,pdfwidth=75%] |
| 157 |
|
| 158 |
Where `TS` is <<TermTranslatedSource,translated-source>> and `FS` is |
| 159 |
<<TermFinalSource,final-source>>. |
| 160 |
|
| 161 |
== Scope |
| 162 |
|
| 163 |
=== Variables |
| 164 |
|
| 165 |
The complexity of mapping semantics (like variable and data views) across |
| 166 |
languages is such that this feature has not been included in this version of the |
| 167 |
specification and will be considered for a future version. |
| 168 |
|
| 169 |
=== Multi-Level Source View |
| 170 |
|
| 171 |
The ability to choose the source level to view is addressed in this |
| 172 |
specification. These are referred to as <<TermStratum,strata>>. |
| 173 |
|
| 174 |
=== Finding Source Files |
| 175 |
|
| 176 |
Currently, <<TermFinalSource,final-source>> is found by combining the follow |
| 177 |
elements: |
| 178 |
|
| 179 |
* A source path |
| 180 |
* The package name converted to a directory path |
| 181 |
* The source file name from a <<TermJDI,JDI>> call (derived from the `SourceFile` |
| 182 |
class file attribute) |
| 183 |
|
| 184 |
Since existing debuggers use this mechanism (the only way for an existing |
| 185 |
debugger to find <<TermTranslatedSource,translated-source>>) each aspect must be |
| 186 |
addressed: |
| 187 |
|
| 188 |
* The source path must be set-up to include translated-source directories |
| 189 |
* Source must be placed in a directory corresponding to the package |
| 190 |
* The <<TermJDI,JDI>> call must return the translated-source name. |
| 191 |
|
| 192 |
For debuggers written against the new APIs, a new method has been added which |
| 193 |
returns the source path - this makes the translated-source directory structure |
| 194 |
flexible. |
| 195 |
|
| 196 |
=== Multiple Source Files per Class File |
| 197 |
|
| 198 |
When an inclusion mechanism is used, a class file will contain source from |
| 199 |
multiple <<TermTranslatedSource,translated-source>> files. The SourceFile |
| 200 |
attribute of class files only associates one source file with a class file which |
| 201 |
is one reason the approach of simply rewriting the `SourceFile` and |
| 202 |
`LineNumberTable` attributes had to be abandoned. The SMAP allows a virtually |
| 203 |
unlimited number of source files per stratum. |
| 204 |
|
| 205 |
== Source Map Format |
| 206 |
|
| 207 |
A Source Map (SMAP) describes a mapping between source positions in an input |
| 208 |
language (<<TermTranslatedSource,translated-source>>) and source positions in a |
| 209 |
generated output language. A view of the source through such a mapping is called |
| 210 |
a <<TermStratum,stratum>>. The <<TermSourceMapFile,SMAP-file>> contains an |
| 211 |
unresolved SMAP. The <<TermSourceDebugExtension,SourceDebugExtension>> class |
| 212 |
file attribute, when used as described in this document, contains an SMAP. The |
| 213 |
SMAP stored in a SourceDebugExtension attribute must be |
| 214 |
<<SMAP Resolution,resolved>>, and thus will have no |
| 215 |
<<Embedded Source Maps,embedded SMAPs>> and will have the |
| 216 |
<<TermFinalSource,final-source>> language as the output language. |
| 217 |
|
| 218 |
An SMAP consists of a header and one or more sections of mapping information. |
| 219 |
|
| 220 |
There are currently seven types of section: stratum sections, file sections, |
| 221 |
line sections, vendor sections, end sections, and open and close embedded |
| 222 |
sections. New section types may be added in the future - to facilitate this, any |
| 223 |
unknown sections must be ignored without error. |
| 224 |
|
| 225 |
The semantics of each section is discussed below. For clarity, an informal |
| 226 |
description of the syntax of each section is included in the discussion. See the |
| 227 |
formal <<SMAP Syntax,SMAP syntax>> for syntax questions. |
| 228 |
|
| 229 |
=== General Format |
| 230 |
|
| 231 |
The SMAP consists of lines of |
| 232 |
http://www.unicode.org/unicode/standard/standard.html[Unicode] text, with a |
| 233 |
concrete representation of http://ietf.org/rfc/rfc2279.txt[UTF-8]. Line |
| 234 |
termination is with line-feed, carriage-return or carriage-return followed by |
| 235 |
line-feed. Because SMAPs are included in class files, size of the SMAP was an |
| 236 |
important constraint on the format chosen for them. |
| 237 |
|
| 238 |
[#smap-header] |
| 239 |
=== Header |
| 240 |
|
| 241 |
The first line of an SMAP is the four letters `SMAP` which identifies it as an |
| 242 |
SMAP. The next line is the name of the generated file. This name is without path |
| 243 |
information (and thus if the generated file is final-source, the name should |
| 244 |
match the `SourceFile` class file attribute). The last line of the header is the |
| 245 |
default stratum for this class. The default stratum is the stratum used when a |
| 246 |
debugger does not explicitly specify interest in another stratum. In an |
| 247 |
unresolved SMAP the default stratum can be unspecified (blank line). In a |
| 248 |
resolved SMAP the default stratum must be specified. A specified stratum must |
| 249 |
either be one represented with a stratum section or `Java` which indicates the |
| 250 |
standard final-source information should be used by default. |
| 251 |
|
| 252 |
=== StratumSection |
| 253 |
|
| 254 |
An SMAP may map more than one <<TermTranslatedSource,translated-source>> to the |
| 255 |
output source (the output source is <<TermFinalSource,final-source>> if the SMAP |
| 256 |
is in a <<TermSourceDebugExtension,SourceDebugExtension>>). A view of the source |
| 257 |
is a stratum (whether viewed as translated-source or final-source). Each |
| 258 |
translated-source language should have its own stratum section with a unique |
| 259 |
stratum name. The final-source stratum (named "`Java`") is created automatically |
| 260 |
and should not have a stratum section. The stratum section should be followed by |
| 261 |
a file section and a line section which will be associated with that stratum. |
| 262 |
|
| 263 |
The format of the section is simply the stratum section marker `*S` followed by |
| 264 |
the name of the stratum. The section ends with a line termination. One |
| 265 |
<<FileSection>> and one <<LineSection>> (in either order) must follow the |
| 266 |
StratumSection (before the next StratumSection or the <<EndSection>>). One or |
| 267 |
more <<VendorSection>>s may follow a StratumSection. There must be at least one |
| 268 |
<<StratumSection>>. |
| 269 |
|
| 270 |
=== FileSection |
| 271 |
|
| 272 |
The file section describes the translated-source file names. Each line maps a |
| 273 |
file ID to a source name and, optionally, to a source path. File IDs are used |
| 274 |
only in the <<LineSection>>. The source name is the name of the |
| 275 |
translated-source. The source path is the path to the translated-source, the "/" |
| 276 |
symbol is translated to the local file separator. In the case where the source |
| 277 |
repository is a file system, source name is the file name (without directory |
| 278 |
information) and source path is a path name (often relative to one of the |
| 279 |
compilation source paths). For example: `Bar.foo` would be a source name, and |
| 280 |
`here/there/Bar.foo` would be a source path. The first file line denotes the |
| 281 |
primary file. |
| 282 |
|
| 283 |
The format of the file section is the file section marker `*F` on a line by |
| 284 |
itself, followed by file information. File information has two forms, source |
| 285 |
name only and source name / source path. The source name only form is one line: |
| 286 |
the integer file ID followed by the source name. The source name / source path |
| 287 |
form is two lines: a plus sign `+`, file ID, and source name on the first line |
| 288 |
and the source path on the second. The file ID must be unique within the file |
| 289 |
section. A <<FileSection>> may only occur after a <<StratumSection>>. The |
| 290 |
`FileName` must have at least one character. The `AbsoluteFileName`, if |
| 291 |
specified, must have at least one character. |
| 292 |
|
| 293 |
For example: |
| 294 |
|
| 295 |
*F |
| 296 |
+ 1 Foo.xyz |
| 297 |
here/there/Foo.xyz |
| 298 |
2 Incl.xyz |
| 299 |
|
| 300 |
declares two source files. File ID #1 has source name `Foo.xyz` and source path |
| 301 |
`here/there/Foo.xyz`. File ID #2 has source name `Incl.xyz` and a source path to |
| 302 |
be computed by the debugger. |
| 303 |
|
| 304 |
=== LineSection |
| 305 |
|
| 306 |
The <<SyntaxLineSection,line section>> associates line numbers in the output source |
| 307 |
with line numbers and source names in the input source. |
| 308 |
|
| 309 |
The format of the line section is the line section marker `*L` on a line by |
| 310 |
itself, followed by the lines of <<SyntaxLineInfo,LineInfo>>. Each |
| 311 |
<<SyntaxLineInfo,LineInfo>> has the form: |
| 312 |
|
| 313 |
[subs=normal] |
| 314 |
---- |
| 315 |
<<SyntaxInputStartLine,InputStartLine>> # <<SyntaxLineFileID,LineFileID>> , <<SyntaxRepeatCount,RepeatCount>> : <<SyntaxOutputStartLine,OutputStartLine>> , <<SyntaxOutputLineIncrement,OutputLineIncrement>> |
| 316 |
---- |
| 317 |
|
| 318 |
where all but |
| 319 |
|
| 320 |
[subs=normal] |
| 321 |
---- |
| 322 |
<<SyntaxInputStartLine,InputStartLine>> : <<SyntaxOutputStartLine,OutputStartLine>> |
| 323 |
---- |
| 324 |
|
| 325 |
are optional. |
| 326 |
|
| 327 |
A range of output source lines is mapped to a single input source line. Each |
| 328 |
<<SyntaxLineInfo,LineInfo>> describes <<SyntaxRepeatCount,RepeatCount>> of these |
| 329 |
mappings. <<SyntaxOutputLineIncrement,OutputLineIncrement>> specifies the number |
| 330 |
of lines in the output source range; this line increment is applied to each |
| 331 |
mapping in the <<SyntaxLineInfo,LineInfo>>. The source file containing the input |
| 332 |
source line is specified by <<SyntaxLineFileID,LineFileID>> via the |
| 333 |
<<FileSection>>. |
| 334 |
|
| 335 |
More precisely, for each `n` between zero and |
| 336 |
|
| 337 |
[subs=normal] |
| 338 |
---- |
| 339 |
<<SyntaxRepeatCount,RepeatCount>> - 1 |
| 340 |
---- |
| 341 |
|
| 342 |
the input source line number |
| 343 |
|
| 344 |
[subs=normal] |
| 345 |
---- |
| 346 |
<<SyntaxInputStartLine,InputStartLine>> + n |
| 347 |
---- |
| 348 |
|
| 349 |
maps to the output source line numbers from |
| 350 |
|
| 351 |
[subs=normal] |
| 352 |
---- |
| 353 |
<<SyntaxOutputStartLine,OutputStartLine>> + (n * <<SyntaxOutputLineIncrement,OutputLineIncrement>>) |
| 354 |
---- |
| 355 |
|
| 356 |
through |
| 357 |
|
| 358 |
[subs=normal] |
| 359 |
---- |
| 360 |
<<SyntaxOutputStartLine,OutputStartLine>> + ((n + 1) * <<SyntaxOutputLineIncrement,OutputLineIncrement>>) - 1 |
| 361 |
---- |
| 362 |
|
| 363 |
If absent, <<SyntaxRepeatCount,RepeatCount>> and |
| 364 |
<<SyntaxOutputLineIncrement,OutputLineIncrement>> default to one. If absent, |
| 365 |
<<SyntaxLineFileID,LineFileID>> defaults to the most recent value (initially |
| 366 |
zero). |
| 367 |
|
| 368 |
The first line of a file is line one. <<SyntaxRepeatCount,RepeatCount>> is |
| 369 |
greater than or equal to one. Each <<SyntaxLineFileID,LineFileID>> must be a |
| 370 |
file ID present in the <<FileSection,FileSection>>. |
| 371 |
<<SyntaxInputStartLine,InputStartLine>> is greater than or equal to one. |
| 372 |
<<SyntaxOutputStartLine,OutputStartLine>> is greater than or equal to one. |
| 373 |
<<SyntaxOutputLineIncrement,OutputLineIncrement>> is greater than or equal to |
| 374 |
zero. A <<LineSection,LineSection>> may only occur after a |
| 375 |
<<StratumSection,StratumSection>>. |
| 376 |
|
| 377 |
For example: |
| 378 |
|
| 379 |
*L |
| 380 |
123:207 |
| 381 |
130,3:210 |
| 382 |
140:250,7 |
| 383 |
160,3:300,2 |
| 384 |
|
| 385 |
Creates this mapping: |
| 386 |
|
| 387 |
[width="100%",cols="3",options="header"] |
| 388 |
|=== |
| 389 |
|Input Source |
| 390 |
2+^|Output Source |
| 391 |
|
| 392 |
|Line |
| 393 |
|Begin Line |
| 394 |
|End Line |
| 395 |
|
| 396 |
|123 |
| 397 |
|207 |
| 398 |
|207 |
| 399 |
|
| 400 |
|130 |
| 401 |
|210 |
| 402 |
|210 |
| 403 |
|
| 404 |
|131 |
| 405 |
|211 |
| 406 |
|211 |
| 407 |
|
| 408 |
|132 |
| 409 |
|212 |
| 410 |
|212 |
| 411 |
|
| 412 |
|140 |
| 413 |
|250 |
| 414 |
|256 |
| 415 |
|
| 416 |
|160 |
| 417 |
|300 |
| 418 |
|301 |
| 419 |
|
| 420 |
|161 |
| 421 |
|302 |
| 422 |
|303 |
| 423 |
|
| 424 |
|162 |
| 425 |
|304 |
| 426 |
|305 |
| 427 |
|
| 428 |
|=== |
| 429 |
|
| 430 |
Note that multiple <<SyntaxLineInfo,LineInfo>> may map multiple input source |
| 431 |
lines to a single output source line, when such a |
| 432 |
<<SyntaxLineSection,LineSection>> is being used to map output source lines to |
| 433 |
input source lines, a first matching <<SyntaxLineInfo,LineInfo>> rule applies. |
| 434 |
|
| 435 |
Note also that multiple <<SyntaxLineInfo,LineInfo>> may map a single input |
| 436 |
source line to a multiple, possibly disjoint, output source lines, when such a |
| 437 |
<<SyntaxLineSection,LineSection>> is being used to map input source lines to |
| 438 |
output source lines, a first matching <<SyntaxLineInfo,LineInfo>> rule again |
| 439 |
applies. |
| 440 |
|
| 441 |
=== VendorSection |
| 442 |
|
| 443 |
The vendor section is for vendor specific information. |
| 444 |
|
| 445 |
The format is `*V` on the first line to mark the section. The second line is the |
| 446 |
vendor ID which is formed by the same rules by which unique package names are |
| 447 |
formed in the Java language specification, third edition |
| 448 |
https://docs.oracle.com/javase/specs/jls/se6/html/packages.html#7.7[(§7.7) Unique Package Names]. |
| 449 |
|
| 450 |
=== EndSection |
| 451 |
|
| 452 |
The end section marks the end of an SMAP, it consists simply of a `*E` marker. |
| 453 |
The end section must be the last line of an SMAP. |
| 454 |
|
| 455 |
=== Embedded Source Maps |
| 456 |
|
| 457 |
The <<SyntaxOpenEmbeddedSection,OpenEmbeddedSection>> marks the beginning and |
| 458 |
<<SyntaxCloseEmbeddedSection,CloseEmbeddedSection>> the end of a set of |
| 459 |
<<SyntaxEmbeddedSourceMaps,EmbeddedSourceMaps>>. These SMAPs correspond to the |
| 460 |
input source for a language-processor. The stratum of the language-processor is |
| 461 |
indicated on both sections. These sections must not occur in a |
| 462 |
<<SMAP Resolution,resolved>> SMAP. |
| 463 |
|
| 464 |
The format is the `*O` marker and the name of the output stratum on the first |
| 465 |
line. This is followed by the set of embedded SMAPs. The embedded SMAPs are |
| 466 |
included "whole" - from the `SMAP` to the <<EndSection,`EndSection`>> `*E` |
| 467 |
marker - inclusive. Finally, the `*C` marker and the name of the output stratum |
| 468 |
on the last line terminates the embedded SMAPs. |
| 469 |
|
| 470 |
=== SMAP Syntax |
| 471 |
|
| 472 |
[listing,subs="+macros"] |
| 473 |
---- |
| 474 |
SMAP: |
| 475 |
Header { Section } EndSection |
| 476 |
|
| 477 |
Header: |
| 478 |
ID OutputFileName DefaultStratumId |
| 479 |
|
| 480 |
ID: |
| 481 |
SMAP CR |
| 482 |
|
| 483 |
OutputFileName: |
| 484 |
NONASTERISKSTRING CR |
| 485 |
|
| 486 |
DefaultStratumId: |
| 487 |
NONASTERISKSTRING CR |
| 488 |
|
| 489 |
Section: |
| 490 |
StratumSection |
| 491 |
FileSection |
| 492 |
LineSection |
| 493 |
EmbeddedSourceMaps |
| 494 |
VendorSection |
| 495 |
FutureSection |
| 496 |
[[SyntaxEmbeddedSourceMaps]] |
| 497 |
EmbeddedSourceMaps: |
| 498 |
OpenEmbeddedSection { SMAP } CloseEmbeddedSection |
| 499 |
[[SyntaxOpenEmbeddedSection]] |
| 500 |
OpenEmbeddedSection: |
| 501 |
*O StratumID CR |
| 502 |
[[SyntaxCloseEmbeddedSection]] |
| 503 |
CloseEmbeddedSection: |
| 504 |
*C StratumID CR |
| 505 |
|
| 506 |
StratumSection: |
| 507 |
*S StratumID CR |
| 508 |
|
| 509 |
StratumID: |
| 510 |
NONASTERISKSTRING |
| 511 |
[[SyntaxLineSection]] |
| 512 |
LineSection: |
| 513 |
*L CR { LineInfo } |
| 514 |
[[SyntaxLineInfo]] |
| 515 |
LineInfo: |
| 516 |
InputLineInfo : OutputLineInfo CR |
| 517 |
|
| 518 |
InputLineInfo: |
| 519 |
InputStartLine , RepeatCount |
| 520 |
InputStartLine |
| 521 |
|
| 522 |
OutputLineInfo: |
| 523 |
OutputStartLine , OutputLineIncrement |
| 524 |
OutputStartLine |
| 525 |
[[SyntaxInputStartLine]] |
| 526 |
InputStartLine: |
| 527 |
NUMBER |
| 528 |
NUMBER # LineFileID |
| 529 |
[[SyntaxLineFileID]] |
| 530 |
LineFileID: |
| 531 |
FileID |
| 532 |
[[SyntaxRepeatCount]] |
| 533 |
RepeatCount: |
| 534 |
NUMBER |
| 535 |
[[SyntaxOutputStartLine]] |
| 536 |
OutputStartLine: |
| 537 |
NUMBER |
| 538 |
[[SyntaxOutputLineIncrement]] |
| 539 |
OutputLineIncrement: |
| 540 |
NUMBER |
| 541 |
|
| 542 |
FileSection: |
| 543 |
*F CR { FileInfo } |
| 544 |
[[SyntaxFileInfo]] |
| 545 |
FileInfo: |
| 546 |
FileID FileName CR |
| 547 |
+ FileID FileName CR AbsoluteFileName CR |
| 548 |
|
| 549 |
FileID: |
| 550 |
NUMBER |
| 551 |
|
| 552 |
FileName: |
| 553 |
NONASTERISKSTRING |
| 554 |
|
| 555 |
AbsoluteFileName: |
| 556 |
NONASTERISKSTRING |
| 557 |
|
| 558 |
VendorSection: |
| 559 |
*V CR VENDORID CR { VendorInfo } |
| 560 |
|
| 561 |
VendorInfo: |
| 562 |
NONASTERISKSTRING CR |
| 563 |
|
| 564 |
FutureSection: |
| 565 |
* OTHERCHAR CR { FutureInfo } |
| 566 |
|
| 567 |
FutureInfo: |
| 568 |
NONASTERISKSTRING CR |
| 569 |
|
| 570 |
EndSection: |
| 571 |
*E CR |
| 572 |
---- |
| 573 |
|
| 574 |
Where `{x}` denotes zero or more occurrences of `x`. And where the terminals are |
| 575 |
defined as follows (whitespace is a sequence of zero or more spaces or tabs): |
| 576 |
|
| 577 |
[width="100%",cols="25%,75%",options="header"] |
| 578 |
|=== |
| 579 |
|
| 580 |
2+^|Terminals |
| 581 |
|
| 582 |
|`NONASTERISKSTRING` |
| 583 |
|Any sequence of characters (excluding the terminal carriage-return or new-line) |
| 584 |
which does not start with "*". Leading whitespace is ignored. |
| 585 |
|
| 586 |
|`NUMBER` |
| 587 |
|Non negative decimal integer. The number is terminated by the first non-digit |
| 588 |
character. Leading and trailing whitespace is ignored. |
| 589 |
|
| 590 |
|`CR` |
| 591 |
|a line terminator: carriage-return, carriage-return followed by new-line or |
| 592 |
new-line. |
| 593 |
|
| 594 |
|`OTHERCHAR` |
| 595 |
|Any character (other than carriage-return, new-line, space or tab) not already |
| 596 |
used as a section header (not S,F,L,V,O,C or E). |
| 597 |
|
| 598 |
|`VENDORID` |
| 599 |
|A sequence of characters that identifies a vendor. The name is formed by the |
| 600 |
same rules that unique package names are formed in the Java language |
| 601 |
specification. Leading and trailing whitespace is ignored. The terminal |
| 602 |
carriage-return or new-line is excluded. |
| 603 |
|
| 604 |
|=== |
| 605 |
|
| 606 |
|
| 607 |
== SMAP Resolution |
| 608 |
|
| 609 |
Before the SMAP in a SMAP-file can be installed into the SourceDebugExtension |
| 610 |
attribute it must be resolved into an SMAP with no embedded SMAPs and with |
| 611 |
final-source as the output source. A set of |
| 612 |
<<SyntaxEmbeddedSourceMaps,embedded SMAPs>> is specific to a stratum and is |
| 613 |
resolved in the context of the matching StratumSection in the outer SMAP. The |
| 614 |
resolved SMAP includes StratumSections computed from each set of embedded SMAPs |
| 615 |
as well as the unchanged StratumSections of the outer SMAP. If embedded SMAPs |
| 616 |
are nested, the inner-most is resolved first. |
| 617 |
|
| 618 |
The structure of an SMAP with embedded SMAPs is as follows: |
| 619 |
|
| 620 |
[subs="normal,-replacements"] |
| 621 |
---- |
| 622 |
SMAP |
| 623 |
... |
| 624 |
*O _B_ |
| 625 |
SMAP |
| 626 |
... |
| 627 |
*S _A_ |
| 628 |
... |
| 629 |
*E |
| 630 |
*C _B_ |
| 631 |
... |
| 632 |
*S _B_ |
| 633 |
... |
| 634 |
*E |
| 635 |
---- |
| 636 |
|
| 637 |
The structure is a set of embedded SMAPs (for a stratum, here named _B_), an |
| 638 |
outer StratumSection (for _B_), and an embedded SMAP with a StratumSection (for |
| 639 |
a stratum, here named _A_). Note that: there may be many sets of embedded SMAPs, |
| 640 |
many embedded SMAPs within the set of embedded SMAPs, and many StratumSections |
| 641 |
within an SMAP. A StratumSection maps source information from its stratum to an |
| 642 |
output stratum. Thus, the embedded StratumSection maps stratum _A_ to stratum |
| 643 |
_B_. We know it is mapped to stratum _B_ because the set of embedded SMAPs for |
| 644 |
stratum _B_ corresponds to the input for the language-processor for _B_. The |
| 645 |
outer StratumSection maps stratum _B_ to its output stratum (let's call this |
| 646 |
stratum _C_), if the shown SMAP is the outer-most SMAP then stratum _C_ is the |
| 647 |
final-source stratum. The purpose of resolution is to create a non-embedded |
| 648 |
StratumSection for _A_ which maps to _C_ (all StratumSections within an SMAP |
| 649 |
must map to the same output stratum, in a resolved outer-most SMAP all |
| 650 |
StratumSections will map to the final-source stratum). This is done by |
| 651 |
composing the mapping in the embedded StratumSection (from _A_ to _B_) with the |
| 652 |
mapping in the outer StratumSection (from _B_ to _C_). Since there may be many |
| 653 |
embedded StratumSections for _A_, these sections must be merged. |
| 654 |
|
| 655 |
A StratumSection is computed for each stratum present in the embedded SMAPs. The |
| 656 |
computed StratumSection is the merge of each embedded StratumSection, for that |
| 657 |
stratum. Line number information is composed with the line number information of |
| 658 |
the outer StratumSection (note that the embedded StratumSections cannot be for |
| 659 |
the same stratum as the outer StratumSection). Specifically, a computed |
| 660 |
StratumSection consists of a merged <<FileSection>>, a composed <<LineSection>>, |
| 661 |
and direct copies of any <<VendorSection>>s or unknown sections. The merged |
| 662 |
FileSection includes each unique <<SyntaxFileInfo,FileInfo>>, with FileIDs |
| 663 |
reassigned to be unique. The composition the LineSections is described in the |
| 664 |
algorithm below. |
| 665 |
|
| 666 |
=== LineInfo Composition Algorithm |
| 667 |
|
| 668 |
The following pseudo-code sketches the algorithm for resolving LineInfo in |
| 669 |
embedded SMAPs. LineInfo resolution is by composition - discussed above. An |
| 670 |
embedded LineInfo which maps stratum _A_ to stratum _B_ is composed with an |
| 671 |
outer LineInfo which maps stratum _B_ to stratum _C_ to create a new resolved |
| 672 |
LineInfo which maps stratum _A_ to stratum _C_. |
| 673 |
|
| 674 |
The SMAPs and their components are marked by subscript: |
| 675 |
|
| 676 |
* Embedded SMAP - level~E~ |
| 677 |
* Outer StratumSection - level~O~ |
| 678 |
* Resolved computed StratumSection - level~R~ |
| 679 |
|
| 680 |
The inputs and outputs of the algorithm are LineInfo tuples. Line information is |
| 681 |
represented in this algorithm in its <<SyntaxLineInfo,LineInfo format>> which is |
| 682 |
discussed in the <<LineSection>>. This algorithm is invoked for each LineInfo~E~ |
| 683 |
in each embedded SMAP. |
| 684 |
|
| 685 |
[subs=normal] |
| 686 |
---- |
| 687 |
ResolveLineInfo: |
| 688 |
InputStartLine~E~ #LineFileID~E~, RepeatCount~E~ : OutputStartLine~E~, OutputLineIncrement~E~ |
| 689 |
as follows: |
| 690 |
|
| 691 |
if RepeatCount~E~ > 0 then { |
| 692 |
for each LineInfo~O~ in the stratum of the embedded SMAP: |
| 693 |
InputStartLine~O~ #LineFileID~O~, RepeatCount~O~: OutputStartLine~O~, OutputLineIncrement~O~ |
| 694 |
which includes OutputStartLine~E~ |
| 695 |
that is, InputStartLine~O~ + N == OutputStartLine~E~ |
| 696 |
for some offset into the outer input range N where 0 <= N < RepeatCount~O~ |
| 697 |
and for which LineFileID~O~ has a sourceName matching the embedded SMAP's OutputFileName { |
| 698 |
compute the number of outer mapping repeations which can be applied |
| 699 |
available := RepeatCount~O~ - N ; |
| 700 |
compute the number of embedded mapping repeations which can be applied |
| 701 |
completeCount := floor(available / OutputLineIncrement~E~) min RepeatCount~E~ ; |
| 702 |
if completeCount > 0 then { |
| 703 |
output resolved LineInfo |
| 704 |
InputStartLine~E~ # uniquify(LineFileID~E~), completeCount : |
| 705 |
(OutputStartLine~O~ + (N * OutputLineIncrement~O~)), |
| 706 |
(OutputLineIncrement~E~ * OutputLineIncrement~O~) ; |
| 707 |
ResolveLineInfo |
| 708 |
(InputStartLine~E~ + completeCount) #LineFileID~E~, (RepeatCount~E~ - completeCount) : |
| 709 |
(OutputStartLine~E~ + completeCount * OutputLineIncrement~E~), OutputLineIncrement~E~ ; |
| 710 |
} else { |
| 711 |
output resolved LineInfo |
| 712 |
InputStartLine~E~ # uniquify(LineFileID~E~), 1 : |
| 713 |
(OutputStartLine~O~ + (N * OutputLineIncrement~O~)), available ; |
| 714 |
ResolveLineInfo |
| 715 |
InputStartLine~E~ #LineFileID~E~, 1 : |
| 716 |
(OutputStartLine~E~ + available), (OutputLineIncrement~E~ - available) ; |
| 717 |
ResolveLineInfo |
| 718 |
(InputStartLine~E~ + 1) #LineFileID~E~, (RepeatCount~E~ - 1): |
| 719 |
(OutputStartLine~E~ + OutputLineIncrement~E~), OutputLineIncrement~E~ ; |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
---- |
| 724 |
|
| 725 |
where _uniquify_ converts a LineFileID~E~ to a corresponding LineFileID~R~ |
| 726 |
|
| 727 |
=== Resolution Example |
| 728 |
|
| 729 |
The following example demonstrates resolution with this algorithm. The |
| 730 |
<<example,general example>> will provide context before walking through this |
| 731 |
example. In this example, `Incl.bar` is included by `Hi.bar`, but each is the |
| 732 |
result of a prior translation. |
| 733 |
|
| 734 |
image:resolution.png[resolution diagram,pdfwidth=75%] |
| 735 |
|
| 736 |
If the unresolved SMAP (in `Hi.java.smap`) is as follows: |
| 737 |
|
| 738 |
[cols="<.^20%,<.^20%"] |
| 739 |
|=== |
| 740 |
|`SMAP + |
| 741 |
Hi.java + |
| 742 |
Java` |
| 743 |
|_Outer Header_ |
| 744 |
|
| 745 |
|`*O Bar` |
| 746 |
|_<<SyntaxOpenEmbeddedSection,OpenEmbeddedSection>>_ |
| 747 |
|
| 748 |
|`SMAP + |
| 749 |
Hi.bar + |
| 750 |
Java + |
| 751 |
*S Foo + |
| 752 |
*F + |
| 753 |
1 Hi.foo + |
| 754 |
*L + |
| 755 |
1#1,5:1,2 + |
| 756 |
*E` |
| 757 |
|_Embedded SMAP (Hi.bar)_ |
| 758 |
|
| 759 |
|`SMAP + |
| 760 |
Incl.bar + |
| 761 |
Java + |
| 762 |
*S Foo + |
| 763 |
*F + |
| 764 |
1 Incl.foo + |
| 765 |
*L 1#1,2:1,2 + |
| 766 |
*E` |
| 767 |
|_Embedded SMAP (Incl.bar)_ |
| 768 |
|
| 769 |
|`*C Bar` |
| 770 |
|_<<SyntaxCloseEmbeddedSection,CloseEmbeddedSection>>_ |
| 771 |
|
| 772 |
|`*S Bar + |
| 773 |
*F + |
| 774 |
1 Hi.bar + |
| 775 |
2 Incl.bar + |
| 776 |
*L + |
| 777 |
1#1:1 + |
| 778 |
1#2,4:2 + |
| 779 |
3#1,8:6` |
| 780 |
|_Outer StratumSection_ |
| 781 |
|
| 782 |
|`*E` |
| 783 |
|_Final <<EndSection>>_ |
| 784 |
|=== |
| 785 |
|
| 786 |
The merged level~R~ FileSection is (in stratum `Foo`): |
| 787 |
|
| 788 |
---- |
| 789 |
*F |
| 790 |
1 Hi.foo |
| 791 |
2 Incl.foo |
| 792 |
---- |
| 793 |
|
| 794 |
The computation proceeds as follows: |
| 795 |
|
| 796 |
[cols="11%,13%,13%,11%,11%,41%",options="header",] |
| 797 |
|=== |
| 798 |
|LineInfo~E~ |
| 799 |
|LineInfo~E~ + |
| 800 |
recursion 1 |
| 801 |
|LineInfo~E~ + |
| 802 |
recursion 2 |
| 803 |
|matching + |
| 804 |
outer + |
| 805 |
LineInfo~O~ |
| 806 |
|resolved + |
| 807 |
LineInfo~R~ |
| 808 |
|discussion |
| 809 |
|
| 810 |
|1#1,5:1,2 |
| 811 |
| |
| 812 |
| |
| 813 |
|1#1:1 |
| 814 |
|1#1,1:1,1 |
| 815 |
|`ResolveLineInfo` is called for `1#1,5:1,2` (from the first embedded SMAP - |
| 816 |
OutputFileName is `Hi.bar`). `1#1:1` is found as the outer StratumSection |
| 817 |
LineInfo~O~ with `InputStartLineO` of 1 and `LineFileIDO` has a sourceName |
| 818 |
matching `Hi.bar`. `N` is 0, and `completeCount` is 0, thus the _else_ |
| 819 |
branch is taken. `available` is 1 and thus output is `1#1,1:1,1`. |
| 820 |
|
| 821 |
| |
| 822 |
|1#1,1:2,1 |
| 823 |
| |
| 824 |
|no match |
| 825 |
| |
| 826 |
|The remaining half of the initial LineInfo~E~ mapping then must be resolved |
| 827 |
recursively, but there is no match and it is ignored. |
| 828 |
|
| 829 |
| |
| 830 |
|2#1,4:3,2 |
| 831 |
| |
| 832 |
|3#1,8:6 |
| 833 |
|2#1,4:6,2 |
| 834 |
|The remaining mappings are also handled recursively. There is a matching |
| 835 |
LineInfo~O~. `N` is 0, and `completeCount` is 4, thus the _if_ branch is taken. |
| 836 |
|
| 837 |
| |
| 838 |
| |
| 839 |
|6#1,0:11,2 |
| 840 |
|n/a |
| 841 |
| |
| 842 |
|The recursive resolve descends deeper but does nothing since all of |
| 843 |
RepeatCount~E~ has been mapped. The first LineInfo~E~ is now resolved. Since it |
| 844 |
had only one LineInfo~E~ the first SMAP is also resolved. |
| 845 |
|
| 846 |
|1#1,2:1,2 |
| 847 |
| |
| 848 |
| |
| 849 |
|1#2,4:2 |
| 850 |
|1#2,2:2,2 |
| 851 |
|Now for the second SMAP (OutputFileName is `Incl.bar`). FileID~E~ 1 in this |
| 852 |
SMAP is `Incl.foo` which corresponds to the remapped FileID~R~ 2. So the |
| 853 |
matching LineInfo~O~ is `1#2,4:2`. `N` is 0, and `completeCount` is 2, so the |
| 854 |
_if_ branch is taken. |
| 855 |
|
| 856 |
| |
| 857 |
|3#1,0:5,2 |
| 858 |
| |
| 859 |
|n/a |
| 860 |
| |
| 861 |
|The recursive resolve does nothing since all the maps have been handled. |
| 862 |
Resolution is complete. |
| 863 |
|=== |
| 864 |
|
| 865 |
The resultant resolved SMAP is: |
| 866 |
|
| 867 |
---- |
| 868 |
SMAP |
| 869 |
Hi.java |
| 870 |
Java |
| 871 |
*S Foo |
| 872 |
*F |
| 873 |
1 Hi.foo |
| 874 |
2 Incl.foo |
| 875 |
*L |
| 876 |
1#1,1:1,1 |
| 877 |
2#1,4:6,2 |
| 878 |
1#2,2:2,2 |
| 879 |
*S Bar |
| 880 |
*F |
| 881 |
1 Hi.bar |
| 882 |
2 Incl.bar |
| 883 |
*L |
| 884 |
1#1:1 |
| 885 |
1#2,4:2 |
| 886 |
3#1,8:6 |
| 887 |
*E |
| 888 |
---- |
| 889 |
|
| 890 |
== JPDA Support |
| 891 |
|
| 892 |
The https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/[Java Platform Debugger |
| 893 |
Architecture] in the Java 1.4 release was extended in support of debugging other |
| 894 |
languages. The new APIs and APIs with comments changed to include reference to |
| 895 |
<<TermStratum,strata>> are listed below: |
| 896 |
|
| 897 |
[cols="60%,40%",options="headers"] |
| 898 |
|=== |
| 899 |
|
| 900 |
|New APIs |
| 901 |
|APIs with Changed Comments |
| 902 |
|
| 903 |
2+^|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jvmdi-spec.html[JVMDI] |
| 904 |
|
| 905 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jvmdi-spec.html#GetSourceDebugExtension[`GetSourceDebugExtension`] |
| 906 |
| |
| 907 |
|
| 908 |
2+^|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp-spec.html[JDWP] - |
| 909 |
`ReferenceType` (2) Command Set |
| 910 |
|
| 911 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html#JDWP_ReferenceType_SourceDebugExtension[`SourceDebugExtension`] Command (12) |
| 912 |
| |
| 913 |
|
| 914 |
2+^|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp-spec.html[JDWP] - |
| 915 |
`VirtualMachine` (1) Command Set |
| 916 |
|
| 917 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html#JDWP_VirtualMachine_SetDefaultStratum[`SetDefaultStratum`] Command (19) |
| 918 |
| |
| 919 |
|
| 920 |
2+^|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/index.html[JDI] - |
| 921 |
https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/VirtualMachine.html[`VirtualMachine`] |
| 922 |
interface |
| 923 |
|
| 924 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/VirtualMachine.html#setDefaultStratum(java.lang.String)[`void setDefaultStratum(String stratum)`] |
| 925 |
| |
| 926 |
|
| 927 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/VirtualMachine.html#getDefaultStratum()[`String getDefaultStratum()`] |
| 928 |
| |
| 929 |
|
| 930 |
2+^|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/index.html[JDI] - |
| 931 |
https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html[`ReferenceType`] interface |
| 932 |
|
| 933 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#sourceNames(java.lang.String)[`String sourceNames(String stratum)`] |
| 934 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#sourceName()[`String sourceName()`] |
| 935 |
|
| 936 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#sourcePaths(java.lang.String)[`String sourcePaths(String stratum)`] |
| 937 |
| |
| 938 |
|
| 939 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#allLineLocations(java.lang.String,%20java.lang.String)[`List allLineLocations(String stratum, String sourceName)`] |
| 940 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#allLineLocations()[`List allLineLocations()`] |
| 941 |
|
| 942 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#locationsOfLine(java.lang.String,%20java.lang.String,%20int)[`List locationsOfLine(String stratum, String sourceName, int lineNumber)`] |
| 943 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#locationsOfLine(int)[`List locationsOfLine(int lineNumber)`] |
| 944 |
|
| 945 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#availableStrata()[`List availableStrata()`] |
| 946 |
| |
| 947 |
|
| 948 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#defaultStratum()[`String defaultStratum()`] |
| 949 |
| |
| 950 |
|
| 951 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#sourceDebugExtension()[`String sourceDebugExtension()`] |
| 952 |
| |
| 953 |
|
| 954 |
2+^|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/index.html[JDI] - |
| 955 |
https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Method.html[`Method`] interface |
| 956 |
|
| 957 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Method.html#allLineLocations(java.lang.String,%20java.lang.String)[`List allLineLocations(String stratum, String sourceName)`] |
| 958 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Method.html#allLineLocations()[`List allLineLocations()`] |
| 959 |
|
| 960 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Method.html#locationsOfLine(java.lang.String,%20java.lang.String,%20int)[`List locationsOfLine(String stratum, String sourceName, int lineNumber)`] |
| 961 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Method.html#locationsOfLine(int)[`List locationsOfLine(int lineNumber)`] |
| 962 |
|
| 963 |
2+^|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/index.html[JDI] - |
| 964 |
https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html[`Location`] interface |
| 965 |
|
| 966 |
| |
| 967 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html[class comment] (strata defined) |
| 968 |
|
| 969 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html#lineNumber(java.lang.String)[`int lineNumber(String stratum)`] |
| 970 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html#lineNumber()[`int lineNumber()`] |
| 971 |
|
| 972 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html#sourceName(java.lang.String)[`String sourceName(String stratum)`] |
| 973 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html#sourceName()[`String sourceName()`] |
| 974 |
|
| 975 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html#sourcePath(java.lang.String)[`String sourcePath(String stratum)`] |
| 976 |
| |
| 977 |
|
| 978 |
|https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/Location.html#sourcePath()[`String sourcePath()`] |
| 979 |
| |
| 980 |
|
| 981 |
|=== |
| 982 |
|
| 983 |
== SourceDebugExtension Support |
| 984 |
|
| 985 |
Debugger applications frequently need debugging information about the source |
| 986 |
that exceeds what is delivered by the existing Java^TM^ Virtual Machine class |
| 987 |
file attributes (SourceFile, LineNumber, and LocalVariable). This is |
| 988 |
particularly true for debugging the source of other languages. In a distributed |
| 989 |
environment side files may not be accessible, the information must be directly |
| 990 |
associated with the class. |
| 991 |
|
| 992 |
The solution is the addition of a class file attribute which holds a string. |
| 993 |
The string contains debugging information in a standardized format which allows |
| 994 |
for evolution and vendor extension. |
| 995 |
|
| 996 |
=== SourceDebugExtension Access |
| 997 |
|
| 998 |
This string is made opaquely accessible at the three layers of the |
| 999 |
https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/[Java Platform Debugger Architecture] (JPDA): |
| 1000 |
|
| 1001 |
[cols="10%,90%"] |
| 1002 |
|=== |
| 1003 |
|JVMDI |https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jvmdi-spec.html#GetSourceDebugExtension[`GetSourceDebugExtension(jclass clazz, char **sourceDebugExtensionPtr)`] |
| 1004 |
|JDWP |https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdwp/jdwp-protocol.html#JDWP_ReferenceType_SourceDebugExtension[`SourceDebugExtension`] Command (12) in the `ReferenceType` (2) Command Set |
| 1005 |
|JDI |https://docs.oracle.com/javase/1.5.0/docs/guide/jpda/jdi/com/sun/jdi/ReferenceType.html#sourceDebugExtension()[`String sourceDebugExtension()`] in the `ReferenceType` interface |
| 1006 |
|=== |
| 1007 |
|
| 1008 |
[#attribute] |
| 1009 |
=== SourceDebugExtension Class File Attribute |
| 1010 |
|
| 1011 |
Java virtual machine class file attributes are described in |
| 1012 |
https://docs.oracle.com/javase/specs/jvms/se6/html/ClassFile.doc.html#43817[section 4.7] |
| 1013 |
of the https://docs.oracle.com/javase/specs/jvms/se6/html/VMSpecTOC.doc.html[The Java Virtual Machine Specification]. |
| 1014 |
The definition of the added attribute is in the context of The Java Virtual |
| 1015 |
Machine Specification: |
| 1016 |
|
| 1017 |
[width="100%",cols="100%"] |
| 1018 |
|=== |
| 1019 |
a| |
| 1020 |
The `SourceDebugExtension` attribute is an optional attribute in the |
| 1021 |
`attributes` table of the `ClassFile` structure. There can be no more than one |
| 1022 |
`SourceDebugExtension` attribute in the `attributes` table of a given `ClassFile` |
| 1023 |
structure. |
| 1024 |
|
| 1025 |
The `SourceDebugExtension` attribute has the following format: |
| 1026 |
|
| 1027 |
SourceDebugExtension_attribute { |
| 1028 |
u2 attribute_name_index; |
| 1029 |
u4 attribute_length; |
| 1030 |
u1 debug_extension[attribute_length]; |
| 1031 |
} |
| 1032 |
|
| 1033 |
The items of the `SourceDebugExtension_attribute` structure are as follows: |
| 1034 |
|
| 1035 |
`attribute_name_index`:: |
| 1036 |
The value of the `attribute_name_index` item must be a valid index into the |
| 1037 |
`constant_pool` table. The `constant_pool` entry at that index must be a |
| 1038 |
`CONSTANT_Utf8_info` structure representing the string |
| 1039 |
`"SourceDebugExtension"`. |
| 1040 |
`attribute_length`:: |
| 1041 |
The value of the `attribute_length` item indicates the length of the |
| 1042 |
attribute, excluding the initial six bytes. The value of the |
| 1043 |
`attribute_length` item is thus the number of bytes in the `debug_extension[]` |
| 1044 |
item. |
| 1045 |
`debug_extension[]`:: |
| 1046 |
The `debug_extension` array holds a string, which must be in UTF-8 format. |
| 1047 |
There is no terminating zero byte. + |
| 1048 |
The string in the `debug_extension` item will be interpreted as extended |
| 1049 |
debugging information. The content of this string has no semantic effect on |
| 1050 |
the Java Virtual Machine. |
| 1051 |
|
| 1052 |
|=== |
| 1053 |
|
| 1054 |
== Example |
| 1055 |
|
| 1056 |
The example below shows how the process described above would apply to a tiny |
| 1057 |
JSP program. |
| 1058 |
|
| 1059 |
=== Input Source |
| 1060 |
|
| 1061 |
The input consists of two JSP files, the first is `Hello.jsp`: |
| 1062 |
|
| 1063 |
[cols="10%,90%",] |
| 1064 |
|=== |
| 1065 |
| 1 |` <HTML>` |
| 1066 |
| 2 |` <HEAD>` |
| 1067 |
| 3 |` <TITLE>Hello Example</TITLE>` |
| 1068 |
| 4 |` </HEAD>` |
| 1069 |
| 5 |` <BODY>` |
| 1070 |
| 6 |` <%@ include file="greeting.jsp" %>` |
| 1071 |
| 7 |` </BODY>` |
| 1072 |
| 8 |` </HTML>` |
| 1073 |
|=== |
| 1074 |
|
| 1075 |
The second JSP file is the included file `greeting.jsp`: |
| 1076 |
|
| 1077 |
[cols="10%,90%"] |
| 1078 |
|=== |
| 1079 |
| 1 |` Hello There!<P>` |
| 1080 |
| 2 |` Goodbye on <%= new Date() %>` |
| 1081 |
|=== |
| 1082 |
|
| 1083 |
=== Language Processor |
| 1084 |
|
| 1085 |
When a JSP compiler (the <<TermLanguageProcessor,language-processor>>) compiles |
| 1086 |
these files it will produce two outputs - a Java programming language source |
| 1087 |
file and a <<TermSourceMapFile,SMAP-file>>. The generated Java programming |
| 1088 |
language source file is `HelloServlet.java`: |
| 1089 |
|
| 1090 |
[cols=">10%,90%"] |
| 1091 |
|=== |
| 1092 |
|1 |`import jakarta.servlet.*;` |
| 1093 |
|2 |`import jakarta.servlet.http.*;` |
| 1094 |
|3 | |
| 1095 |
|4 |`public class HelloServlet extends HttpServlet {` |
| 1096 |
|5 |` public void doGet(HttpServletRequest request,` |
| 1097 |
|6 |` HttpServletResponse response)` |
| 1098 |
|7 |` throws ServletException, IOException {` |
| 1099 |
|8 |` response.setContentType("text/html");` |
| 1100 |
|9 |` PrintWriter out = response.getWriter();` |
| 1101 |
|10|` // Hello.jsp:1` |
| 1102 |
|11|` out.println("<HTML>");` |
| 1103 |
|12|` // Hello.jsp:2` |
| 1104 |
|13|` out.println("<HEAD>");` |
| 1105 |
|14|` // Hello.jsp:3` |
| 1106 |
|15|` out.println("<TITLE>Hello Example</TITLE>");` |
| 1107 |
|16|` // Hello.jsp:4` |
| 1108 |
|17|` out.println("</HEAD>");` |
| 1109 |
|18|` // Hello.jsp:5` |
| 1110 |
|19|` out.println("<BODY>");` |
| 1111 |
|20|` // greeting.jsp:1` |
| 1112 |
|21|` out.println("Hello There!<P>");` |
| 1113 |
|22|` // greeting.jsp:2` |
| 1114 |
|23|` out.println("Goodbye on " + new Date() );` |
| 1115 |
|24|` // Hello.jsp:7` |
| 1116 |
|25|` out.println("</BODY>");` |
| 1117 |
|26|` // Hello.jsp:8` |
| 1118 |
|27|` out.println("</HTML>");` |
| 1119 |
|28|` }` |
| 1120 |
|29|`}` |
| 1121 |
|=== |
| 1122 |
|
| 1123 |
The generated <<TermSourceMapFile,SMAP-file>> is `HelloServlet.java.smap`: |
| 1124 |
|
| 1125 |
---- |
| 1126 |
SMAP |
| 1127 |
HelloServlet.java |
| 1128 |
JSP |
| 1129 |
*S JSP |
| 1130 |
*F |
| 1131 |
1 Hello.jsp |
| 1132 |
2 greeting.jsp |
| 1133 |
*L |
| 1134 |
1#1,5:10,2 |
| 1135 |
1#2,2:20,2 |
| 1136 |
7#1,2:24,2 |
| 1137 |
*E |
| 1138 |
---- |
| 1139 |
|
| 1140 |
A couple things are interesting to note about this SMAP -- the user has chosen |
| 1141 |
to make JSP the default stratum (perhaps by a command line option) and even |
| 1142 |
though there are ten lines of input source and 29 lines of generated source, |
| 1143 |
only three LineInfo lines describe the transformation: the first and last are |
| 1144 |
for the lines before and after the include (respectively) and the middle is for |
| 1145 |
the included file `greeting.jsp`. |
| 1146 |
|
| 1147 |
The three LineInfo lines describe these mappings: |
| 1148 |
|
| 1149 |
---- |
| 1150 |
1#1,5:10,2 |
| 1151 |
Hello.jsp: line 1 -> HelloServlet.java: lines 10, 11 |
| 1152 |
line 2 -> lines 12, 13 |
| 1153 |
line 3 -> lines 14, 15 |
| 1154 |
line 4 -> lines 16, 17 |
| 1155 |
line 5 -> lines 18, 19 |
| 1156 |
|
| 1157 |
1#2,2:20,2 |
| 1158 |
greeting.jsp: line 1 -> HelloServlet.java: lines 20, 21 |
| 1159 |
line 2 -> lines 22, 23 |
| 1160 |
|
| 1161 |
7#1,2:24,2 |
| 1162 |
Hello.jsp: line 7 -> HelloServlet.java: lines 24, 25 |
| 1163 |
line 8 -> lines 26, 27 |
| 1164 |
---- |
| 1165 |
|
| 1166 |
=== Post Processor |
| 1167 |
|
| 1168 |
Next `HelloServlet.java` is compiled by a Java programming language compiler |
| 1169 |
(for example `javac`) producing the class file `HelloServlet.class`. Then the |
| 1170 |
<<TermPostProcessor,post-processor>> is run. It takes `HelloServlet.class` and |
| 1171 |
`HelloServlet.java.smap` as input. It creates a |
| 1172 |
<<TermSourceDebugExtension,SourceDebugExtension>> attribute whose content is the |
| 1173 |
SMAP in `HelloServlet.java.smap` and rewrites `HelloServlet.class` with this |
| 1174 |
attribute. |
| 1175 |
|
| 1176 |
=== Debugging |
| 1177 |
|
| 1178 |
Now the program is run under the control of a debugger (which is a client of |
| 1179 |
<<TermJDI,JDI>>). Let's say we are stepping through this code and the debugger |
| 1180 |
has just received a <<TermJDI,JDI>> `StepEvent` for the line that is just about |
| 1181 |
to output `<BODY>`. The debugger's code might look like this (the `StepEvent` |
| 1182 |
is in the variable `stepEvent`): |
| 1183 |
|
| 1184 |
---- |
| 1185 |
Location location = stepEvent.location(); |
| 1186 |
String sourceName = location.sourceName("Java"); |
| 1187 |
int lineNumber = location.lineNumber("Java"); |
| 1188 |
displaySource(sourceName, lineNumber); |
| 1189 |
---- |
| 1190 |
|
| 1191 |
where `displaySource` is a debugger routine that displays a source location. |
| 1192 |
Because the `Java` stratum has been specified `sourceName` would be |
| 1193 |
`HelloServlet.java`, the `lineNumber` would be `19` and the displayed line would |
| 1194 |
be: |
| 1195 |
|
| 1196 |
---- |
| 1197 |
out.println("<BODY>"); |
| 1198 |
---- |
| 1199 |
|
| 1200 |
However, if `sourceName` and `lineNumber` were derived as follows: |
| 1201 |
|
| 1202 |
---- |
| 1203 |
String sourceName = location.sourceName("JSP"); |
| 1204 |
int lineNumber = location.lineNumber("JSP"); |
| 1205 |
---- |
| 1206 |
|
| 1207 |
Since the `JSP` stratum has been specified, `sourceName` would be `Hello.jsp`, |
| 1208 |
the `lineNumber` would be `5` and the displayed line would be: |
| 1209 |
|
| 1210 |
---- |
| 1211 |
<BODY> |
| 1212 |
---- |
| 1213 |
|
| 1214 |
This occurs because the <<TermSourceDebugExtension,SourceDebugExtension>> |
| 1215 |
attribute was stored when the VM read `HelloServlet.class` and it was retrieved |
| 1216 |
with the SourceDebugExtension JDWP command which in turn caused the JVMDI |
| 1217 |
function call GetSourceDebugExtension. The SMAP in the SourceDebugExtension was |
| 1218 |
parsed which provided the above transformation of source location. Specifically, |
| 1219 |
the line: |
| 1220 |
|
| 1221 |
---- |
| 1222 |
1#1,5:10,2 |
| 1223 |
---- |
| 1224 |
|
| 1225 |
is the basis of this transformation - which refers to FileId #1 |
| 1226 |
|
| 1227 |
---- |
| 1228 |
1 Hello.jsp |
| 1229 |
---- |
| 1230 |
|
| 1231 |
and whence the sourceName information. Since the default stratum specified in |
| 1232 |
the SMAP is `JSP`, the code: |
| 1233 |
|
| 1234 |
---- |
| 1235 |
String sourceName = location.sourceName(); |
| 1236 |
int lineNumber = location.lineNumber(); |
| 1237 |
---- |
| 1238 |
|
| 1239 |
would have the same effect. Since this is the form code would have taken before |
| 1240 |
these extensions were introduced, existing debuggers can be utilized if they are |
| 1241 |
run under the new implementation of <<TermJDI,JDI>>. |