Try linking static members' definitions to their declarations.

This does not help anything though: gdb would follow the
DW_AT_specification link only in the opposite direction, which LLVM
cannot emit.
This commit is contained in:
Tau 2024-06-28 16:58:25 +02:00
parent 3bfa63aa61
commit 52e4cdb45e

View File

@ -2465,18 +2465,52 @@ pub const Object = struct {
try o.builder.metadataString(decl_name),
try o.getDebugFile(namespace.fileScope(zcu)),
fwd_ref,
0,
0, // Line
try o.lowerDebugType(nested_type, false),
0, // Align
));
} else if (decl.val.getVariable(zcu)) |v| {
fields.appendAssumeCapacity(try o.builder.debugStaticMemberType(
try o.builder.metadataString(decl_name),
try o.getDebugFile(namespace.fileScope(zcu)),
// Imitate a C++ static member variable since neither
// GDB or LLDB can really cope with regular variables
// directly inside a struct type.
const vglobal = (o.decl_map.get(decl_id) orelse continue).ptr(&o.builder);
const linkage_name = try o.builder.metadataStringFromStrtabString(vglobal.kind.variable.name(&o.builder));
const var_name = try o.builder.metadataString(decl.name.toSlice(ip));
const var_type = try o.lowerDebugType(Type.fromInterned(v.ty), false);
const debug_file = try o.getDebugFile(namespace.fileScope(zcu));
const debug_line = decl.navSrcLine(zcu) + 1;
const static_member = try o.builder.debugStaticMemberType(
var_name,
debug_file,
fwd_ref,
0,
try o.lowerDebugType(Type.fromInterned(v.ty), false),
));
debug_line,
var_type,
);
fields.appendAssumeCapacity(static_member);
const debug_global_var = try o.builder.debugGlobalVar(
var_name,
linkage_name,
debug_file,
debug_file,
debug_line,
var_type,
vglobal.kind.variable,
static_member,
.internal,
);
const debug_expression = try o.builder.debugExpression(&.{});
const resolved_var = try o.builder.debugGlobalVarExpression(
debug_global_var,
debug_expression,
);
vglobal.dbg = resolved_var;
try o.debug_globals.append(o.gpa, resolved_var);
}
}
}
@ -4742,58 +4776,34 @@ pub const DeclGen = struct {
if (!owner_mod.strip) {
const debug_file = try o.getDebugFile(file_scope);
const debug_scope = try o.namespaceToDebugScope(decl.src_namespace);
const linkage_name = try o.builder.metadataStringFromStrtabString(variable_index.name(&o.builder));
const debug_global_var = if (!decl.isExtern(zcu)) blk: {
// Imitate a C++ static member variable since neither
// GDB or LLDB can really cope with regular variables
// directly inside a struct type.
const ty = try o.lowerDebugType(decl.typeOf(zcu), true);
const name = try o.builder.metadataString(decl.name.toSlice(ip));
const variable = try o.builder.debugGlobalVar(
name,
if (!decl.isExtern(zcu)) {
// Make it a static member variable, which is resolved later in genNamespaces.
_ = try o.namespaceToDebugScope(decl.src_namespace);
} else {
const debug_global_var = try o.builder.debugGlobalVar(
linkage_name,
linkage_name,
debug_file,
debug_file,
line_number,
ty,
try o.lowerDebugType(decl.typeOf(zcu), true),
variable_index,
.none,
.external,
);
const debug_expression = try o.builder.debugExpression(&.{});
try o.debug_imports.append(o.gpa, try o.builder.debugImportDeclaration(
name,
debug_file,
debug_scope,
line_number,
variable,
));
const debug_global_var_expression = try o.builder.debugGlobalVarExpression(
debug_global_var,
debug_expression,
);
break :blk variable;
} else try o.builder.debugGlobalVar(
linkage_name,
linkage_name,
debug_file,
debug_file,
line_number,
try o.lowerDebugType(decl.typeOf(zcu), true),
variable_index,
.none,
.external,
);
const debug_expression = try o.builder.debugExpression(&.{});
const debug_global_var_expression = try o.builder.debugGlobalVarExpression(
debug_global_var,
debug_expression,
);
variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder);
try o.debug_globals.append(o.gpa, debug_global_var_expression);
variable_index.setGlobalVariableExpression(debug_global_var_expression, &o.builder);
try o.debug_globals.append(o.gpa, debug_global_var_expression);
}
}
}