[LLDB][Windows] Handle C calling convention mangling
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
On Windows, C functions can be mangled/decorated based on the calling convention. See [Microsoft docs](https://learn.microsoft.com/en-us/cpp/build/reference/decorated-names#FormatC). A complication is that this is dependent on the environment (x86 vs. amd64 vs. ARM). Take the following example:
```cpp
extern "C" {
int /* __cdecl (default) */ FuncCCall() { return 0; }
int __stdcall FuncStdCall() { return 0; }
int __fastcall FuncFastCall() { return 0; }
int __vectorcall FuncVectorCall() { return 0; }
}
```
| Function Name | Mangled Name (x86) | Mangled Name (amd64/x86_64) | Mangled Name (ARM) |
|---|---|---|---|
| `FuncCCall` | `_FuncCCall` | `FuncCCall` | `FuncCCall` |
| `FuncStdCall` | `_FuncStdCall@0` | `FuncStdCall` | `FuncStdCall` |
| `FuncFastCall` | `@FuncFastCall@0` | `FuncFastCall` | `FuncFastCall` |
| `FuncVectorCall` | `FuncVectorCall@@0` | `FuncVectorCall@@0` | `FuncVectorCall` |
Additionally, `FuncCCall` shows up as `FuncCCall` on x86 when using DWARF (instead of `_FuncCCall`):
```
0x0000009c: DW_TAG_subprogram
DW_AT_low_pc (0x00000000)
DW_AT_high_pc (0x00000007)
DW_AT_frame_base (DW_OP_reg5 EBP)
DW_AT_name ("CFuncCCall")
DW_AT_decl_file ("/app/example.cpp")
DW_AT_decl_line (2)
DW_AT_type (0x00000041 "int")
DW_AT_external (true)
```
From https://godbolt.org/z/TzcqWPd8j (see also discussion in https://github.com/llvm/llvm-project/pull/160930).
On PDB, in the publics stream, however, the "true" mangled name (`_FuncCCall`) shows.
As of (PR TBD), the native PDB plugin will strip the leading underscore from the function symbol to match DWARF.
We should still strip these pre-/suffixes _somewhere_, because currently, functions will show up with the mangled name. Note that the mangling might be nested. For example, on x86, `__Z7recursei` is a `__cdecl` function (leading underscore) and the rest is a mangled itanium name.
Contributor guide
Research direction
Start with LLDB's native PDB plugin and the symbol-name handling around the examples in the issue; compare the DWARF and PDB names using the linked Compiler Explorer case. Trace how x86, amd64, and ARM calling-convention decorations interact with nested Itanium names. Done means displayed function names no longer retain the relevant Windows prefixes or suffixes across these formats.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100