Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DWARF] Make the GC of child tags conservative by default #9829

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions crates/cranelift/src/debug/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,52 @@ fn build_unit_dependencies(
}

fn has_die_back_edge(die: &read::DebuggingInformationEntry<Reader<'_>>) -> read::Result<bool> {
// DIEs can be broadly divided into three categories:
// 1. Extensions of their parents; effectively attributes: DW_TAG_variable, DW_TAG_member, etc.
// 2. Standalone entities referred to by other DIEs via 'reference' class attributes: types.
// 3. Structural entities that organize how the above relate to each other: namespaces.
// Here, we must make sure to return 'true' for DIEs in the first category since stripping them,
// provided their parent is alive, is always wrong. To be conservatively correct in the face
// of new/vendor tags, we maintain a "(mostly) known good" list of tags of the latter categories.
let result = match die.tag() {
constants::DW_TAG_variable
| constants::DW_TAG_constant
| constants::DW_TAG_inlined_subroutine
| constants::DW_TAG_lexical_block
| constants::DW_TAG_label
| constants::DW_TAG_with_stmt
| constants::DW_TAG_try_block
| constants::DW_TAG_catch_block
| constants::DW_TAG_template_type_parameter
| constants::DW_TAG_enumerator
| constants::DW_TAG_member
| constants::DW_TAG_variant_part
| constants::DW_TAG_variant
| constants::DW_TAG_formal_parameter => true,
constants::DW_TAG_array_type
| constants::DW_TAG_atomic_type
| constants::DW_TAG_base_type
| constants::DW_TAG_class_type
| constants::DW_TAG_const_type
| constants::DW_TAG_dwarf_procedure
| constants::DW_TAG_entry_point
| constants::DW_TAG_enumeration_type
| constants::DW_TAG_pointer_type
| constants::DW_TAG_ptr_to_member_type
| constants::DW_TAG_reference_type
| constants::DW_TAG_restrict_type
| constants::DW_TAG_rvalue_reference_type
| constants::DW_TAG_string_type
| constants::DW_TAG_structure_type
| constants::DW_TAG_typedef
| constants::DW_TAG_union_type
| constants::DW_TAG_unspecified_type
| constants::DW_TAG_volatile_type
| constants::DW_TAG_coarray_type
| constants::DW_TAG_common_block
| constants::DW_TAG_dynamic_type
| constants::DW_TAG_file_type
| constants::DW_TAG_immutable_type
| constants::DW_TAG_interface_type
| constants::DW_TAG_set_type
| constants::DW_TAG_shared_type
| constants::DW_TAG_subroutine_type
| constants::DW_TAG_packed_type
| constants::DW_TAG_template_alias
| constants::DW_TAG_namelist
| constants::DW_TAG_namespace
| constants::DW_TAG_imported_unit
| constants::DW_TAG_imported_declaration
| constants::DW_TAG_imported_module
| constants::DW_TAG_module => false,
constants::DW_TAG_subprogram => die.attr(constants::DW_AT_declaration)?.is_some(),
_ => false,
_ => true,
};
Ok(result)
}
Expand Down
11 changes: 6 additions & 5 deletions tests/all/debug/lldb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,14 @@ pub fn test_debug_dwarf_generic_lldb() -> Result<()> {
"-Ddebug-info",
"tests/all/debug/testsuite/generic.wasm",
],
r#"b MainDefinedFunction
r#"br set -n debug_break -C up
r
p __vmctx->set()
n
p (x + x)
b SatelliteFunction
c
n
p (x + x)
c
p inst.BaseValue + inst.DerivedValue
c"#,
)?;

Expand All @@ -198,8 +197,10 @@ c"#,
r#"
check: stop reason = breakpoint 1.1
check: 2
check: stop reason = breakpoint 2.1
check: stop reason = breakpoint 1.1
check: 4
check: stop reason = breakpoint 1.1
check: 3
check: exited with status = 0
"#,
)?;
Expand Down
1 change: 1 addition & 0 deletions tests/all/debug/testsuite/generic-satellite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

int SomeClass::SatelliteFunction(int x) {
x *= 2;
debug_break();
return x;
}
20 changes: 18 additions & 2 deletions tests/all/debug/testsuite/generic.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// clang generic.cpp generic-satellite.cpp -o generic.wasm -g -target
// wasm32-unknown-wasip1
// clang-format off
// clang generic.cpp generic-satellite.cpp -o generic.wasm -g -target wasm32-unknown-wasip1
// clang-format on
//
#include "generic.h"

int SomeClass::MainDefinedFunction() {
int x = HIDE_FROM_CHECKER(1);
debug_break();
int y = SatelliteFunction(x);
return x + y;
}
Expand All @@ -14,8 +16,22 @@ int TestClassDefinitionSpreadAcrossCompileUnits() {
return result != 3 ? 1 : 0;
}

struct BaseType {
int BaseValue = 1;
};
struct DerivedType : BaseType {
long long DerivedValue = 2;
};

int TestInheritance() {
DerivedType inst;
debug_break();
return inst.BaseValue + inst.DerivedValue != 3 ? 1 : 0;
}

int main() {
int exitCode = 0;
exitCode += TestClassDefinitionSpreadAcrossCompileUnits();
exitCode += TestInheritance();
return exitCode;
}
2 changes: 2 additions & 0 deletions tests/all/debug/testsuite/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ class SomeClass {
static int MainDefinedFunction();
static int SatelliteFunction(int x);
};

inline void debug_break() {}
Binary file modified tests/all/debug/testsuite/generic.wasm
Binary file not shown.
Loading