How to get gdb on Linux to find source file for binary cross compiled on windows How to get gdb on Linux to find source file for binary cross compiled on windows windows windows

How to get gdb on Linux to find source file for binary cross compiled on windows


Although it's rather old question, I did encountered the same problem. I managed to resolve it but using sed on binary executable... (yeah, a 'bit' hack-ish, but did not found another way). With sed I've managed to replace symbols paths right inside the executable, the trick is that new path's length should be the same as the old one.

sed -i "s#C:/srcpath#/srcpath/.#g" ./executable

Be sure to make new path the same length, otherwise the executable will brake.


I also have this same problem. Your option 1 isn't as bad as you think because you can script creating all the 'directory' commands with something like this python code:

def get_directory_paths():    return_array = list()    unix_path = os.path.join('my','unix','path')    for root, dirs, files in os.walk(unix_path):        for dir in dirs:            full_unix_path = os.path.join(root,dir)            escaped_unix_path = re.sub("\s", "\\\\ ", full_unix_path)            return_array.insert(0, "directory " + escaped_unix_path)    return '\n'.join(return_array)

The downside is that if you have two source files with the same name in different directories, I don't think gcc can pick the right one. That worries me, but in my particular situation, I think I'm safe.

For option 2 (which I suspect would fix the aliasing condition from #1), I think the problem is that the substitutions are not ending with a "file separator" according to the linux so they aren't applied:

To avoid unexpected substitution results, a rule is applied only if the from part of the directory name ends at a directory separator. For instance, a rule substituting /usr/source into /mnt/cross will be applied to /usr/source/foo-1.0 but not to /usr/sourceware/foo-2.0. And because the substitution is applied only at the beginning of the directory name, this rule will not be applied to /root/usr/source/baz.c either." (from https://sourceware.org/gdb/current/onlinedocs/gdb/Source-Path.html#index-set-substitute_002dpath )

I haven't tried anything like your #3 and I also considered something like @dragn suggestion, but in my situation the paths are not even close to the same length, so that will be an issue.

I think I'm stuck with #1 and a script, but if anyone has other suggestions, I'm interested options :-)