emscripten-core / emscripten-core/emscripten

Missing DWARF entries for passed-by-reference structs

Open
#13,192 16 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Take this example C:

```c
typedef struct A {
int x;
} A;

typedef struct B {
int x;
float y;
} B;

typedef struct C {
float y;
} C;

void accept_a_b_c(A a, B b, C c) {}

int main() {
accept_a_b_c(
(A) { .x = 10 },
(B) { .x = 20, .y = 30 },
(C) { .y = 40 }
);
}
```

When compiled with debug info, the DWARF entry for `accept_a_b_c` looks like this:

```
0x00000026: DW_TAG_subprogram
DW_AT_low_pc (0x00000007)
DW_AT_high_pc (0x0000002d)
DW_AT_frame_base (DW_OP_WASM_location 0x0 0x5, DW_OP_stack_value)
DW_AT_name ("accept_a_b_c")
DW_AT_decl_file (".\temp.c")
DW_AT_decl_line (14)
DW_AT_prototyped (true)
DW_AT_external (true)

0x0000003a: DW_TAG_formal_parameter
DW_AT_location (DW_OP_fbreg +8)
DW_AT_name ("a")
DW_AT_decl_file (".\temp.c")
DW_AT_decl_line (14)
DW_AT_type (0x00000076 "A")

0x00000048: DW_TAG_formal_parameter
DW_AT_location (DW_OP_fbreg +0)
DW_AT_name ("c")
DW_AT_decl_file (".\temp.c")
DW_AT_decl_line (14)
DW_AT_type (0x00000096 "C")

0x00000056: NULL
```

As you can see, the entry for parameter `b` just got skipped. As a result, it's not visible in debuggers either.

This seems to be happening for any structs that are large enough to require passing by-reference instead of by-value. It also seems to be a Clang issue (I can reproduce with bare Clang), but opening here for tracking.

/cc @dschuff @bmeurer for visibility

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.