[SERVER-59314] Report file and line in stack traces Created: 12/Aug/21  Updated: 19/Oct/23

Status: Backlog
Project: Core Server
Component/s: Build
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 4
Labels: sa-remove-fv-backlog-22
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File source_location_demo.mov    
Issue Links:
Depends
depends on SERVER-74053 vendor libdw and libelf as third parties Closed
Related
related to SERVER-71420 Print clickable file/line in unittest... Backlog
related to SERVER-58046 add demangled name to printStackTrace Closed
Assigned Teams:
Service Arch
Sprint: Service Arch 2022-12-26, Service Arch 2022-07-11, Service Arch 2022-07-25, Service Arch 2022-08-08, Service Arch 2022-08-22, Service Arch 2022-09-05, Service Arch 2022-09-19, Service Arch 2022-10-31, Service Arch 2022-11-14, Service Arch 2022-11-28, Service Arch 2022-12-12, Service Arch 2023-01-09, Service Arch 2023-01-23, Service Arch 2023-02-06, Service Arch 2023-02-20
Participants:

 Description   

It'll be nice to get line numbers by default in stack traces so that for local development, there'd be less need for symbolizing for local runs.

gcc -g1 or -g2 should be sufficient on Linux

Windows already has line numbers, I believe.



 Comments   
Comment by Billy Donahue [ 23/Mar/23 ]

Ok thank you for doing the due diligence on that.

I might be able to do it with libdwarf, which is under the "CC-BY" license, aka:
"Creative Commons Attribution 4.0 International License"
https://www.prevanders.net/libdwarfdoc/
Which is always ok to use.

It would only affect the internals of the DwarfMetadataResolver class in my PR.

https://github.com/10gen/mongo/pull/10425/files#diff-1327b3e3e961390f9e4a6bd09e62b2c857b1e1c02785ef4b185cfdb9f6f7d84a

Next time I'm working on this ticket I'll try that.

Comment by Juan Gu [ 23/Mar/23 ]

Hi billy.donahue@mongodb.com , alexander.neben@mongodb.com , daniel.moody@mongodb.com , and I have discussed this with the legal department, and unfortunately, we don't believe it's currently possible to add what you've requested. While it may be possible, it would require a highly technical lift. From https://sourceware.org/elfutils/, it has been licensed with 'License. The libraries and backends are dual GPLv2+/LGPLv3+. The utilities are GPLv3+.' it has a conflict with our Inbound Open Source Policy

Comment by Charlie Swanson [ 15/Feb/23 ]

Very cool! Thanks for looking into this billy.donahue@mongodb.com!

Comment by Billy Donahue [ 08/Feb/23 ]

draft PoC PR:
https://github.com/10gen/mongo/pull/10425

Demo!

Cause a mongod to crash, click on the filename:line:col source locations in the stack trace. VSCode jumps to those cursor positions.

source_location_demo.mov

Comment by Jason Chan [ 08/Jul/22 ]

robert.guo@mongodb.com, would someone from DAG be able to follow-up on daniel.gottlieb@mongodb.com's questions? I don't think Service Arch has knowledge about the current state.

Comment by Robert Guo (Inactive) [ 13/Sep/21 ]

Thanks for the insight Drew! geert.bosch Since it looks like more investigation's needed here , would you have recommendations for next steps?

Comment by Andrew Morrow (Inactive) [ 13/Sep/21 ]

robert.guo and geert.bosch - I'm not sure I understand the request here. We already always build with -ggdb which implies -g. Per https://gcc.gnu.org/onlinedocs/gcc-8.5.0/gcc/Debugging-Options.html#Debugging-Options the default -glevel is 2. So I believe we are already effectively building with -g2. Note further that all of the debug info generation levels include line number tables, except for -g0, which disables debug info entirely.

Building a trivial hello_world.cpp with the v3 mongodbtoolchain using -ggdb and -g2 and then comparing sizes suggests that they produce identical output:

$ ~/opt/src/bloaty/bloaty a.out.g2 -- a.out.ggdb
     VM SIZE                  FILE SIZE
 --------------            --------------
  [ = ]       0 [Unmapped]      +2  +0.1%
  [ = ]       0 .debug_str      -2  -0.0%
  [ = ]       0 TOTAL            0  [ = ]

The two byte difference is due to the DWARF recording of the command line, and that can be eliminated entirely by building with -gno-record-gcc-switches.

1703612c1703612
<                     DW_AT_producer              GNU C++14 8.3.0 -mtune=generic -march=x86-64 -ggdb
---
>                     DW_AT_producer              GNU C++14 8.3.0 -mtune=generic -march=x86-64 -g2

If the request is to have the mongodb stacktrace code emit file and line numbers, I think the debug info we are currently generating is sufficient for that purpose, but we would likely need to either teach libunwind how to do it, or to integrate with elfutils and dig that information out ourselves while iterating with libunwind.

Comment by Robert Guo (Inactive) [ 12/Aug/21 ]

cc geert.bosch, who came up with the idea.

Generated at Thu Feb 08 05:46:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.