builtin: support -d no_backtrace, to ease compiling V code on older distros easier
							parent
							
								
									f807fd973e
								
							
						
					
					
						commit
						48b117618d
					
				|  | @ -87,48 +87,52 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool { | |||
| 		C.tcc_backtrace("Backtrace") | ||||
| 		return false | ||||
| 	} | ||||
| 	buffer := [100]byteptr{} | ||||
| 	nr_ptrs := C.backtrace(voidptr(buffer), 100) | ||||
| 	if nr_ptrs < 2 { | ||||
| 		eprintln('C.backtrace returned less than 2 frames') | ||||
| 	$if no_backtrace ? { | ||||
| 		return false | ||||
| 	} | ||||
| 	nr_actual_frames := nr_ptrs - skipframes | ||||
| 	mut sframes := []string{} | ||||
| 	//////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
 | ||||
| 	csymbols := C.backtrace_symbols(voidptr(&buffer[skipframes]), nr_actual_frames) | ||||
| 	for i in 0 .. nr_actual_frames { | ||||
| 		sframes << unsafe {tos2( byteptr(csymbols[i]) )} | ||||
| 	} | ||||
| 	for sframe in sframes { | ||||
| 		executable := sframe.all_before('(') | ||||
| 		addr := sframe.all_after('[').all_before(']') | ||||
| 		beforeaddr := sframe.all_before('[') | ||||
| 		cmd := 'addr2line -e $executable $addr' | ||||
| 		// taken from os, to avoid depending on the os module inside builtin.v
 | ||||
| 		f := C.popen(charptr(cmd.str), 'r') | ||||
| 		if isnil(f) { | ||||
| 			eprintln(sframe) | ||||
| 			continue | ||||
| 	} $else { | ||||
| 		buffer := [100]byteptr{} | ||||
| 		nr_ptrs := C.backtrace(voidptr(buffer), 100) | ||||
| 		if nr_ptrs < 2 { | ||||
| 			eprintln('C.backtrace returned less than 2 frames') | ||||
| 			return false | ||||
| 		} | ||||
| 		buf := [1000]byte{} | ||||
| 		mut output := '' | ||||
| 		for C.fgets(charptr(buf), 1000, f) != 0 { | ||||
| 			output += tos(byteptr(buf), vstrlen(byteptr(buf))) | ||||
| 		nr_actual_frames := nr_ptrs - skipframes | ||||
| 		mut sframes := []string{} | ||||
| 		//////csymbols := backtrace_symbols(*voidptr(&buffer[skipframes]), nr_actual_frames)
 | ||||
| 		csymbols := C.backtrace_symbols(voidptr(&buffer[skipframes]), nr_actual_frames) | ||||
| 		for i in 0 .. nr_actual_frames { | ||||
| 			sframes << unsafe {tos2( byteptr(csymbols[i]) )} | ||||
| 		} | ||||
| 		output = output.trim_space() + ':' | ||||
| 		if C.pclose(f) != 0 { | ||||
| 			eprintln(sframe) | ||||
| 			continue | ||||
| 		for sframe in sframes { | ||||
| 			executable := sframe.all_before('(') | ||||
| 			addr := sframe.all_after('[').all_before(']') | ||||
| 			beforeaddr := sframe.all_before('[') | ||||
| 			cmd := 'addr2line -e $executable $addr' | ||||
| 			// taken from os, to avoid depending on the os module inside builtin.v
 | ||||
| 			f := C.popen(charptr(cmd.str), 'r') | ||||
| 			if isnil(f) { | ||||
| 				eprintln(sframe) | ||||
| 				continue | ||||
| 			} | ||||
| 			buf := [1000]byte{} | ||||
| 			mut output := '' | ||||
| 			for C.fgets(charptr(buf), 1000, f) != 0 { | ||||
| 				output += tos(byteptr(buf), vstrlen(byteptr(buf))) | ||||
| 			} | ||||
| 			output = output.trim_space() + ':' | ||||
| 			if C.pclose(f) != 0 { | ||||
| 				eprintln(sframe) | ||||
| 				continue | ||||
| 			} | ||||
| 			if output in ['??:0:', '??:?:'] { | ||||
| 				output = '' | ||||
| 			} | ||||
| 			// See http://wiki.dwarfstd.org/index.php?title=Path_Discriminators
 | ||||
| 			// NB: it is shortened here to just d. , just so that it fits, and so
 | ||||
| 			// that the common error file:lineno: line format is enforced.
 | ||||
| 			output = output.replace(' (discriminator', ': (d.') | ||||
| 			eprintln('${output:-46s} | ${addr:14s} | $beforeaddr') | ||||
| 		} | ||||
| 		if output in ['??:0:', '??:?:'] { | ||||
| 			output = '' | ||||
| 		} | ||||
| 		// See http://wiki.dwarfstd.org/index.php?title=Path_Discriminators
 | ||||
| 		// NB: it is shortened here to just d. , just so that it fits, and so
 | ||||
| 		// that the common error file:lineno: line format is enforced.
 | ||||
| 		output = output.replace(' (discriminator', ': (d.') | ||||
| 		eprintln('${output:-46s} | ${addr:14s} | $beforeaddr') | ||||
| 	} | ||||
| 	return true | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue