standard library integrates with knowledge of stripped debug info

This commit is contained in:
Andrew Kelley 2019-06-14 18:45:41 -04:00
parent 362c79140f
commit 7c5ceb0c4c
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 20 additions and 5 deletions

View File

@ -203,6 +203,10 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
get_target_triple(&g->triple_str, g->zig_target);
g->pointer_size_bytes = target_arch_pointer_bit_width(g->zig_target->arch) / 8;
if (!target_has_debug_info(g->zig_target)) {
g->strip_debug_symbols = true;
}
return g;
}
@ -248,6 +252,9 @@ void codegen_set_errmsg_color(CodeGen *g, ErrColor err_color) {
void codegen_set_strip(CodeGen *g, bool strip) {
g->strip_debug_symbols = strip;
if (!target_has_debug_info(g->zig_target)) {
g->strip_debug_symbols = true;
}
}
void codegen_set_out_name(CodeGen *g, Buf *out_name) {
@ -7514,7 +7521,7 @@ static bool detect_single_threaded(CodeGen *g) {
}
static bool detect_err_ret_tracing(CodeGen *g) {
return !target_is_wasm(g->zig_target) &&
return !g->strip_debug_symbols &&
g->build_mode != BuildModeFastRelease &&
g->build_mode != BuildModeSmallRelease;
}

View File

@ -1585,3 +1585,7 @@ void target_libc_enum(size_t index, ZigTarget *out_target) {
out_target->vendor = ZigLLVM_UnknownVendor;
out_target->is_native = false;
}
bool target_has_debug_info(const ZigTarget *target) {
return !target_is_wasm(target);
}

View File

@ -177,6 +177,7 @@ bool target_is_musl(const ZigTarget *target);
bool target_is_wasm(const ZigTarget *target);
bool target_is_single_threaded(const ZigTarget *target);
bool target_supports_stack_probing(const ZigTarget *target);
bool target_has_debug_info(const ZigTarget *target);
uint32_t target_arch_pointer_bit_width(ZigLLVM_ArchType arch);

View File

@ -85,8 +85,8 @@ fn wantTtyColor() bool {
/// TODO multithreaded awareness
pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
const stderr = getStderrStream() catch return;
if (os.wasi.is_the_target) {
stderr.print("Unable to dump stack trace: unimplemented on WASI\n") catch return;
if (builtin.strip_debug_info) {
stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
return;
}
const debug_info = getSelfDebugInfo() catch |err| {
@ -151,8 +151,8 @@ pub fn captureStackTrace(first_address: ?usize, stack_trace: *builtin.StackTrace
/// TODO multithreaded awareness
pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
const stderr = getStderrStream() catch return;
if (os.wasi.is_the_target) {
stderr.print("Unable to dump stack trace: unimplemented on WASI\n") catch return;
if (builtin.strip_debug_info) {
stderr.print("Unable to dump stack trace: debug info stripped\n") catch return;
return;
}
const debug_info = getSelfDebugInfo() catch |err| {
@ -223,6 +223,7 @@ pub fn writeStackTrace(
debug_info: *DebugInfo,
tty_color: bool,
) !void {
if (builtin.strip_debug_info) return error.MissingDebugInfo;
var frame_index: usize = 0;
var frames_left: usize = std.math.min(stack_trace.index, stack_trace.instruction_addresses.len);
@ -783,6 +784,8 @@ pub const OpenSelfDebugInfoError = error{
};
pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
if (builtin.strip_debug_info)
return error.MissingDebugInfo;
if (windows.is_the_target) {
return openSelfDebugInfoWindows(allocator);
}