Bug 22590 – importC: static functions have no debug information generated for them
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-12T19:16:33Z
Last change time
2022-02-12T22:45:59Z
Keywords
DebugInfo, ImportC, pull, wrong-code
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-12-12T19:16:33Z
When a SEGV occurs in a "C" static function, there's no debug information to say what or why it occurred.
The workaround is to remove "static" from both declaration and definition.
Nope, my mistake, I had a stale build with some functions that had "static" removed.
Comment #3 by bugzilla — 2021-12-17T08:02:26Z
Example, please?
Comment #4 by ibuclaw — 2021-12-17T17:48:51Z
(In reply to Walter Bright from comment #3)
> Example, please?
*All* static functions. Just add static to any function and when you step into it with gdb, all debugging is gone.
Looking at an objdump of a program:
---
<1><91>: Abbrev Number: 6 (DW_TAG_subprogram)
<92> DW_AT_sibling : <0xde>
<96> DW_AT_name : test.test_static
<a7> DW_AT_MIPS_linkage_name: test_static
<b3> DW_AT_decl_file : 1
<b4> DW_AT_decl_line : 2
<b6> DW_AT_type : <0x7c>
<ba> DW_AT_pure : 1
<bb> DW_AT_low_pc : 0x0
<c3> DW_AT_high_pc : 0x17
<cb> DW_AT_frame_base : 0x0 (location list)
---
I only see that DW_AT_MIPS_linkage_name is pointlessly set, as static functions don't have any linkage. However removing this tag does not alter the outcome, so there's something else that's broken here.
This is objdump of gcc compiled program of the same function:
---
<1><52>: Abbrev Number: 4 (DW_TAG_subprogram)
<53> DW_AT_name : (indirect string, offset: 0x1f): test_static
<57> DW_AT_decl_file : 1
<58> DW_AT_decl_line : 1
<59> DW_AT_decl_column : 12
<5a> DW_AT_type : <0x4b>
<5e> DW_AT_low_pc : 0x0
<66> DW_AT_high_pc : 0x1a
<6e> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<70> DW_AT_sibling : <0x84>
---
On the surface though, it doesn't look like dmd is doing anything fundamentally wrong, and yet gdb fails to find any debug information for the function.
Comment #5 by ibuclaw — 2021-12-17T21:50:44Z
What might be useful is to debug gdb here to determine at what point does gdb give up attempting to read the debug information for the function.
- Is it DW_AT_MIPS_linkage_name that throws it off?
- Is it because DW_AT_name doesn't match the name of the function?
- What is DW_AT_pure doing there?
Whatever it is, it's not putting two and two together.
Comment #6 by ibuclaw — 2021-12-17T22:50:41Z
Looks like `.debug_line` information isn't being emitted for static functions.
Without `static` (two functions, main and test_static):
---
Line Number Statements:
[0x00000029] Extended opcode 2: set Address to 0x0
[0x00000034] Set File Name to entry 1 in the File Name Table
[0x00000036] Special opcode 6: advance Address by 0 to 0x0 and Line by 1 to 2
[0x00000037] Special opcode 119: advance Address by 8 to 0x8 and Line by 2 to 4
[0x00000038] Special opcode 160: advance Address by 11 to 0x13 and Line by 1 to 5
[0x00000039] Special opcode 34: advance Address by 2 to 0x15 and Line by 1 to 6
[0x0000003a] Advance PC by 2 to 0x17
[0x0000003c] Extended opcode 1: End of Sequence
[0x0000003f] Extended opcode 2: set Address to 0x0
[0x0000004a] Set File Name to entry 1 in the File Name Table
[0x0000004c] Special opcode 13: advance Address by 0 to 0x0 and Line by 8 to 9
[0x0000004d] Special opcode 62: advance Address by 4 to 0x4 and Line by 1 to 10
[0x0000004e] Special opcode 76: advance Address by 5 to 0x9 and Line by 1 to 11
[0x0000004f] Advance PC by 2 to 0xb
[0x00000051] Extended opcode 1: End of Sequence
---
With `static` (same number of functions):
---
Line Number Statements:
[0x00000029] Extended opcode 2: set Address to 0x0
[0x00000034] Set File Name to entry 1 in the File Name Table
[0x00000036] Special opcode 13: advance Address by 0 to 0x0 and Line by 8 to 9
[0x00000037] Special opcode 62: advance Address by 4 to 0x4 and Line by 1 to 10
[0x00000038] Special opcode 76: advance Address by 5 to 0x9 and Line by 1 to 11
[0x00000039] Advance PC by 2 to 0xb
[0x0000003b] Extended opcode 1: End of Sequence
---
> two functions, main and test_static
It's always nice to not make me guess what the functions are. I ask because too many times I've guessed at what the problem code was, and could not duplicate the problem because the trigger for the problem was other than what the submitter thought it was.
Comment #9 by ibuclaw — 2021-12-18T21:13:45Z
(In reply to Walter Bright from comment #8)
> > two functions, main and test_static
>
> It's always nice to not make me guess what the functions are. I ask because
> too many times I've guessed at what the problem code was, and could not
> duplicate the problem because the trigger for the problem was other than
> what the submitter thought it was.
Because it doesn't matter what the function is, the only thing you need to do is add `static ` to any function, and try running a gdb over it.
As I've pointed out, SDsym is not being set for SCstatic functions. Commenting out the above linked code and debugging static functions suddenly works.
Comment #10 by dlang-bot — 2022-02-11T07:09:50Z
@WalterBright created dlang/dmd pull request #13640 "fix Issue 22590 - importC: static functions have no debug information…" fixing this issue:
- fix Issue 22590 - importC: static functions have no debug information generated for them
https://github.com/dlang/dmd/pull/13640
Comment #11 by dlang-bot — 2022-02-12T22:45:59Z
dlang/dmd pull request #13640 "fix Issue 22590 - importC: static functions have no debug information…" was merged into master:
- 821f18e58041ab949c5be086ab2f9b5f99cd4c9a by Walter Bright:
fix Issue 22590 - importC: static functions have no debug information generated for them
https://github.com/dlang/dmd/pull/13640