@@ -75,52 +75,53 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool {
7575 $if tinyc {
7676 C.tcc_backtrace (c 'Backtrace' )
7777 return false
78- }
79- buffer := [100 ]voidptr {}
80- nr_ptrs := C.backtrace (& buffer[0 ], 100 )
81- if nr_ptrs < 2 {
82- eprintln ('C.backtrace returned less than 2 frames' )
83- return false
84- }
85- nr_actual_frames := nr_ptrs - skipframes
86- mut sframes := []string {}
87- // ////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
88- csymbols := C.backtrace_symbols (voidptr (& buffer[skipframes]), nr_actual_frames)
89- for i in 0 .. nr_actual_frames {
90- sframes << unsafe { tos2 (& u8 (csymbols[i])) }
91- }
92- for sframe in sframes {
93- executable := sframe.all_before ('(' )
94- addr := sframe.all_after ('[' ).all_before (']' )
95- beforeaddr := sframe.all_before ('[' )
96- cmd := 'addr2line -e ${executable} ${addr} '
97- // taken from os, to avoid depending on the os module inside builtin.v
98- f := C.popen (& char (cmd.str), c 'r' )
99- if f == unsafe { nil } {
100- eprintln (sframe)
101- continue
102- }
103- buf := [1000 ]u8 {}
104- mut output := ''
105- unsafe {
106- bp := & buf[0 ]
107- for C.fgets (& char (bp), 1000 , f) != 0 {
108- output + = tos (bp, vstrlen (bp))
109- }
78+ } $else {
79+ buffer := [100 ]voidptr {}
80+ nr_ptrs := C.backtrace (& buffer[0 ], 100 )
81+ if nr_ptrs < 2 {
82+ eprintln ('C.backtrace returned less than 2 frames' )
83+ return false
11084 }
111- output = output.trim_space () + ':'
112- if C.pclose (f) != 0 {
113- eprintln (sframe)
114- continue
85+ nr_actual_frames := nr_ptrs - skipframes
86+ mut sframes := []string {}
87+ // ////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
88+ csymbols := C.backtrace_symbols (voidptr (& buffer[skipframes]), nr_actual_frames)
89+ for i in 0 .. nr_actual_frames {
90+ sframes << unsafe { tos2 (& u8 (csymbols[i])) }
11591 }
116- if output in ['??:0:' , '??:?:' ] {
117- output = ''
92+ for sframe in sframes {
93+ executable := sframe.all_before ('(' )
94+ addr := sframe.all_after ('[' ).all_before (']' )
95+ beforeaddr := sframe.all_before ('[' )
96+ cmd := 'addr2line -e ${executable} ${addr} '
97+ // taken from os, to avoid depending on the os module inside builtin.v
98+ f := C.popen (& char (cmd.str), c 'r' )
99+ if f == unsafe { nil } {
100+ eprintln (sframe)
101+ continue
102+ }
103+ buf := [1000 ]u8 {}
104+ mut output := ''
105+ unsafe {
106+ bp := & buf[0 ]
107+ for C.fgets (& char (bp), 1000 , f) != 0 {
108+ output + = tos (bp, vstrlen (bp))
109+ }
110+ }
111+ output = output.trim_space () + ':'
112+ if C.pclose (f) != 0 {
113+ eprintln (sframe)
114+ continue
115+ }
116+ if output in ['??:0:' , '??:?:' ] {
117+ output = ''
118+ }
119+ // See http://wiki.dwarfstd.org/index.php?title=Path_Discriminators
120+ // Note: it is shortened here to just d. , just so that it fits, and so
121+ // that the common error file:lineno: line format is enforced.
122+ output = output.replace (' (discriminator' , ': (d.' )
123+ eprintln ('${output:-55s} | ${addr:14s} | ${beforeaddr} ' )
118124 }
119- // See http://wiki.dwarfstd.org/index.php?title=Path_Discriminators
120- // Note: it is shortened here to just d. , just so that it fits, and so
121- // that the common error file:lineno: line format is enforced.
122- output = output.replace (' (discriminator' , ': (d.' )
123- eprintln ('${output:-55s} | ${addr:14s} | ${beforeaddr} ' )
124125 }
125126 }
126127 }
0 commit comments