Skip to content

Commit f85fa75

Browse files
authored
[trace-view] Fixed breakpoints problem in no-source bytecode files (#22048)
## Description This PR fixes a problem with setting breakpoints in disassembly files that do not have a corresponding source file. The problem was related to the fact that a no-source disassembly file is treated as a source file by the runtime if no actual source file exists. This was reflected everywhere but not in the code responsible for checking validity of breakpoints... ## Test plan A test verifying that no-source disassembly file is debugged correctly was modified. This test was previously incorrect actually (note that the stack never showed disassembly file frame) so in addition to adding breakpoint test, stepping through source/disassembly combination has also been fixed.
1 parent 9c64c2d commit f85fa75

File tree

8 files changed

+46
-16
lines changed

8 files changed

+46
-16
lines changed

external-crates/move/crates/move-analyzer/trace-adapter/src/runtime.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,15 @@ export class Runtime extends EventEmitter {
810810
if (fileExt !== MOVE_FILE_EXT && fileExt !== BCODE_FILE_EXT) {
811811
return [];
812812
}
813-
const tracedLines = fileExt === MOVE_FILE_EXT
814-
? this.trace.tracedSrcLines.get(filePath)
815-
: this.trace.tracedBcodeLines.get(filePath);
813+
// For a source file, `tracedLines` will be in `tracedSrcLines`,
814+
// but if no source file exists (only bytecode) then it may be
815+
// in `tracedSourceLines` for the bytecode file as well, so simply
816+
// use the path for search. If not found, and it's the bytecode file
817+
// then search in `tracedBcodeLines` as well.
818+
let tracedLines = this.trace.tracedSrcLines.get(filePath);
819+
if (!tracedLines && fileExt === BCODE_FILE_EXT) {
820+
tracedLines = this.trace.tracedBcodeLines.get(filePath);
821+
}
816822
// Set all breakpoints to invalid and validate the correct ones in the loop,
817823
// otherwise let them all be invalid if there are no traced lines.
818824
// Valid breakpoints are those that are on lines that have at least

external-crates/move/crates/move-analyzer/trace-adapter/tests/disassembly_no_source/build/disassembly_no_source/debug_info/m2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

external-crates/move/crates/move-analyzer/trace-adapter/tests/disassembly_no_source/build/disassembly_no_source/sources/m2.move

Lines changed: 0 additions & 8 deletions
This file was deleted.

external-crates/move/crates/move-analyzer/trace-adapter/tests/disassembly_no_source/sources/m.move

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Tests a scenario when there is no source file for a given module
22
// but there is a disasembled bytecode file for this module. Note
3-
// that module m2 does not have source map (or source file in the build
3+
// that module m2 does not have source debug info (or source file in the build
44
// directory) but it has a disassembled bytecode file which is automatically
5-
// used during debugging.
5+
// used during debugging. It also tests setting breakpoints in bytecode
6+
// files that do not have a corresponding source file.
67
module disassembly_no_source::m;
78

89
use disassembly_no_source::m2::foo;
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
current frame stack:
22
function: test (m.move:12)
33
scope 0 :
4+
line breakpoints
5+
m2.mvb
6+
12
47
current frame stack:
58
function: test (m.move:12)
69
scope 0 :
7-
function: foo (m2.move:6)
10+
function: foo (m2.mvb:8)
811
scope 0 :
912
p : 42
1013
type: u64
1114

15+
line breakpoints
16+
m2.mvb
17+
12
1218
current frame stack:
19+
function: test (m.move:12)
20+
scope 0 :
21+
function: foo (m2.mvb:11)
22+
scope 0 :
23+
function: bar (m3.move:4)
24+
scope 0 :
25+
p : 84
26+
type: u64
27+
28+
line breakpoints
29+
m2.mvb
30+
12
31+
current frame stack:
32+
function: test (m.move:12)
33+
scope 0 :
34+
function: foo (m2.mvb:12)
35+
scope 0 :
36+
line breakpoints
37+
m2.mvb
38+
12

external-crates/move/crates/move-analyzer/trace-adapter/tests/disassembly_no_source/trace.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const path = require('path');
22
let action = (runtime) => {
3+
const pkgName = path.basename(__dirname);
4+
const filePath = path.join(__dirname, 'build', pkgName, 'disassembly', `m2.mvb`);
35
let res = '';
6+
runtime.setLineBreakpoints(filePath, [ 12 ]);
47
// we are in a functino that has source file
58
res += runtime.toString();
69
// step into a function which does not have source file
@@ -12,6 +15,9 @@ let action = (runtime) => {
1215
runtime.step(false);
1316
runtime.step(false);
1417
res += runtime.toString();
18+
// continue until you reach breakpoint at the end of the caller function
19+
runtime.continue();
20+
res += runtime.toString();
1521
return res;
1622
};
1723
run_spec(__dirname, action);

external-crates/move/crates/move-analyzer/trace-debug/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"publisher": "mysten",
66
"icon": "images/move.png",
77
"license": "Apache-2.0",
8-
"version": "0.0.6",
8+
"version": "0.0.7",
99
"preview": true,
1010
"repository": {
1111
"url": "https://github.com/MystenLabs/sui.git",

0 commit comments

Comments
 (0)