Skip to content

Commit a79a9cb

Browse files
authored
trace_calls: fix v -m32 -trace-calls run vlib/v/tests/testdata/trace_calls/simple.vv (#20556)
1 parent f543440 commit a79a9cb

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

vlib/v/tests/trace_calls_test.v

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22

33
const vexe = @VEXE
4+
const gcc_path = os.find_abs_path_of_executable('gcc') or { '' }
5+
const cdefs_h_32bit_exists = os.exists('/usr/include/i386-linux-gnu/sys/cdefs.h')
46

57
fn test_tracing() {
68
os.chdir(@VROOT)!
@@ -12,28 +14,39 @@ fn test_tracing() {
1214
eprintln('> skipping ${fpath}, because ${should_match_fpath} does not exist.')
1315
continue
1416
}
15-
res := os.execute('${os.quoted_path(vexe)} -trace-calls run ${os.quoted_path(fpath)}')
16-
if res.exit_code != 0 {
17-
eprintln('> compilation output:\n${res.output}')
18-
assert res.exit_code == 0, 'compilation of ${fpath} failed'
17+
run_single_program(fpath, should_match_fpath, '', '64bit')
18+
if cdefs_h_32bit_exists && gcc_path != '' {
19+
// try running the same programs, compiled in 32bit mode too, if gcc is available:
20+
run_single_program(fpath, should_match_fpath, '-cc gcc -m32 -gc none', '32bit')
21+
} else {
22+
eprintln('> skipping -m32 compilation since either 32bit headers are not installed, or you do not have gcc installed')
1923
}
20-
lines := os.read_lines(should_match_fpath) or {
21-
assert false, '${fpath} should be readable'
22-
return
23-
}
24-
if lines.len == 0 {
25-
assert false, '${should_match_fpath} should contain at least one line/glob match pattern'
26-
}
27-
mut matched := false
28-
for line in lines {
29-
if res.output.match_glob(line) {
30-
matched = true
31-
println('> trace output of ${fpath} matches line pattern: ${line}')
32-
continue
33-
} else {
34-
eprintln(res.output)
35-
assert false, '> trace output of ${fpath} DID NOT match the line pattern: ${line}'
36-
}
24+
eprintln('-'.repeat(30))
25+
}
26+
}
27+
28+
fn run_single_program(fpath string, should_match_fpath string, compiler_opts string, label string) {
29+
res := os.execute('${os.quoted_path(vexe)} ${compiler_opts} -trace-calls run ${os.quoted_path(fpath)}')
30+
if res.exit_code != 0 {
31+
eprintln('> ${label} compilation output:\n${res.output}')
32+
assert res.exit_code == 0, 'compilation of ${fpath} failed'
33+
}
34+
lines := os.read_lines(should_match_fpath) or {
35+
assert false, '${fpath} should be readable'
36+
return
37+
}
38+
if lines.len == 0 {
39+
assert false, '${should_match_fpath} should contain at least one line/glob match pattern'
40+
}
41+
mut matched := false
42+
for line in lines {
43+
if res.output.match_glob(line) {
44+
matched = true
45+
println('> ${label} trace output of ${fpath} matches line pattern: ${line}')
46+
continue
47+
} else {
48+
eprintln(res.output)
49+
assert false, '> trace output of ${fpath} DID NOT match the line pattern: ${line}'
3750
}
3851
}
3952
}

vlib/v/trace_calls/tracing_calls.c.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ pub fn on_call(fname string) {
2525
pfbase = &fbase
2626
ssize = u64(g_stack_base) - u64(pfbase)
2727
}
28-
C.fprintf(C.stderr, c'> trace %8d %8ld %8d %s\n', tid, ns, ssize, fname.str)
28+
$if x64 {
29+
C.fprintf(C.stderr, c'> trace %8d %8ld %8ld %s\n', tid, ns, ssize, fname.str)
30+
} $else {
31+
C.fprintf(C.stderr, c'> trace %8d %8lld %8lld %s\n', tid, ns, ssize, fname.str)
32+
}
2933
C.fflush(C.stderr)
3034
}
3135

0 commit comments

Comments
 (0)