Improve gdb_realpath for Windows hosts
On Windows hosts, gdb_realpath is just an xstrdup. This makes filename comparisons on Windows very chancy. Normally, we would normalize both paths, and then compare. But since the normalization doesn't do anything, two equivalent names on Windows might not match. This can happen when trying to insert a breakpoint using the fullpath of a file. For instance, if the compiler generated debug info that says that the compilation directory is: `c:\\some\\double\\slashes\\dir', then trying to insert a breakpoint on `c:/some/double/slashes/dir/foo.c:4' does not work: (gdb) b c:/some/double/slashes/dir/foo.c:4 No source file named c:/some/double/slashes/dir/foo.c:4. (gdb) b c:\some\double\slashes\dir\foo.c:4 No source file named c:\some\double\slashes\dir\foo.c:4. This fixes the problem by enhancing gdb_realpath on Windows hosts. The code is inspired from libiberty's lrealpath. gdb/ChangeLog: * utils.c (gdb_realpath): Add better support for Windows hosts.
This commit is contained in:
parent
ca5202fb32
commit
9c5e43861d
2 changed files with 23 additions and 0 deletions
19
gdb/utils.c
19
gdb/utils.c
|
@ -3341,6 +3341,25 @@ gdb_realpath (const char *filename)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* The MS Windows method. If we don't have realpath, we assume we
|
||||
don't have symlinks and just canonicalize to a Windows absolute
|
||||
path. GetFullPath converts ../ and ./ in relative paths to
|
||||
absolute paths, filling in current drive if one is not given
|
||||
or using the current directory of a specified drive (eg, "E:foo").
|
||||
It also converts all forward slashes to back slashes. */
|
||||
/* The file system is case-insensitive but case-preserving.
|
||||
So we do not lowercase the path. Otherwise, we might not
|
||||
be able to display the original casing in a given path. */
|
||||
#if defined (_WIN32)
|
||||
{
|
||||
char buf[MAX_PATH];
|
||||
DWORD len = GetFullPathName (filename, MAX_PATH, buf, NULL);
|
||||
|
||||
if (len > 0 && len < MAX_PATH)
|
||||
return xstrdup (buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This system is a lost cause, just dup the buffer. */
|
||||
return xstrdup (filename);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue