This is an archive of the discontinued LLVM Phabricator instance.

[Clang][DebugInfo] Make DIFile filename and directory native to target architecture
Needs ReviewPublic

Authored by saudi on May 15 2020, 6:30 AM.

Details

Summary

In one of our games, we cross-compile a Linux target from Windows.
We are currently having issues debugging the executable under Linux (e.g. debugging a core dump), since Windows-style paths are stored in the debug info.
GDB could not find the source file paths, even relative, as it interprets \ as a regular character inside a directory or file name.

This patch takes the approach of creating the DIFile with the native format of the target architecture, for both its filename and directory properties.

Using this patch and the -fdebug-prefix-map= argument, we can create fully compatible paths for gdb.

Diff Detail

Event Timeline

saudi created this revision.May 15 2020, 6:30 AM

As long as the tests are working, I'm OK with this. But please hold off until others chime in. I know @thakis and others have been dealing with making cross-platform builds work better with relative paths, so they may know about more constraints on file names in debug info.

clang/lib/CodeGen/CGDebugInfo.cpp
443

It looks like sys::path::native adjusts the slant of the slashes to match the target style, but it doesn't cope with things like drive letters, UNC paths, etc. I see how that would work for most cases when cross compiling from Windows to Posix, but I worry whether functions like sys::path::is_absolute will work properly when going the other way.

But the tests go both ways, so I guess it works well enough.

MaskRay added inline comments.May 15 2020, 10:17 AM
clang/lib/CodeGen/CGDebugInfo.cpp
443

I may have asked and someone may have explained, but I do not remember that.

Can we store / internally in IR (so tests can consistently use /) and pick \\ or / only when the information is emitted?

rnk added inline comments.May 15 2020, 2:40 PM
clang/lib/CodeGen/CGDebugInfo.cpp
443

We should just go ahead and do that. It's just like how we convert all wchar_t paths to UTF-8 internally. We should probably start by ensuring that source paths in the source manager all use forward slashes.

saudi added inline comments.May 21 2020, 1:13 PM
clang/lib/CodeGen/CGDebugInfo.cpp
443

@rnk, how would you see that first step?
After a quick look, the source manager seems to reference its paths from the FileManager, so the change might have an impact a large amount of code.
It might also have a performance issue when building under windows, as conversions would be doubled.
WDYT?

It's not obvious why using the target format would be the desirable behavior for cross-compiling. For example, when cross-compiling for an embedded device, many developers would also cross-debug the code from their workstation rather than on the embedded device. OTOH, this is really about Windows and presumably to make things work with the native tools there, and all other tools likely understand both formats, so why not.

saudi added inline comments.Jun 11 2020, 8:29 AM
clang/lib/CodeGen/CGDebugInfo.cpp
443

Ping!
If the best thing is to change the paths in IR and/or in the SourceManager, I think I will need a pointer for where to start, as it seems to involve important changes.

I have seen some -fdebug-prefix-map= traffic. Is this still needed? If it is still needed, can someone pick it up?