jart / cosmopolitan

build-once run-anywhere c library
ISC License
17.71k stars 605 forks source link

Display file and line number information in stack traces on Windows #293

Open Keithcat1 opened 2 years ago

Keithcat1 commented 2 years ago

This works on Linux and WSL, but not on windows. I know that the *.com.dbg binary must be in the same folder.

jart commented 2 years ago

I've confirmed it's possible to do this.

image

Here's what needs to happen. First, we need to delete this line:

https://github.com/jart/cosmopolitan/blob/30cd28b1f8a6cfbb20a1819c1d90a975f8d4d77c/libc/log/backtrace2.c#L61

Secondly, we might want to update:

https://github.com/jart/cosmopolitan/blob/30cd28b1f8a6cfbb20a1819c1d90a975f8d4d77c/libc/log/addr2linepath.c#L21-L23

To be a little smarter on Windows. Possibly by explicitly looking for the standard msys2 using fileexists() and returning that if the environment variable is null.

Note: The way I got the crashreport.com binary on my Windows computer was I built it on Linux first:

~/cosmo$ make -j8 o//examples/crashreport.com && scp o//examples/crashreport.com{,.dbg} win10:

Newcomers: We recommend the Linux (or WSL) build environment, but it is possible to build Cosmopolitan programs on Windows too. Instructions are here: https://justine.lol/cosmopolitan/windows-compiling.html

jart commented 2 years ago

One further note, if someone wants a more technically challenging problem than hunting addr2line, I would also welcome a contribution that allows Cosmopolitan Libc to read this information directly from the DWARF ELF .com.dbg file itself. I would be thrilled to see that happen, but keep in mind that DWARF is a daunting format.

alexey-milovidov commented 2 years ago

Reference: https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/Dwarf.h https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/Dwarf.cpp