On Jun 10 17:44, Corinna Vinschen wrote: > On Jun 10 16:18, Corinna Vinschen wrote: > > On Jun 10 16:11, Corinna Vinschen wrote: > > > Hi Jon, > > > > > > On Jun 10 13:05, Jon TURNEY wrote: > > > > Not sure if this is wanted, but on a couple of occasions recently I have been > > > > presented with strace output which contains an exception at an address in an > > > > unknown module (i.e. not in the cygwin DLL or the main executable), so here is a > > > > patch which adds some more information, including DLL load addresses, to help > > > > interpret such straces. > > > > > > That's a nice addition. Two points, though: > > > > > > - Do we *always* want that output or do we want a way to switch it on > > > and off? If the latter, we can simply add another _STRACE_foo option > > > for it. > > > > > > - The GetFileNameFromHandle function could be much simpler. Rather than > > > opening a mapping object for ev.u.LoadDll.hFile, just use the existing > > > mapping object from ev.u.LoadDll.lpBaseOfDll. > > > > ...with the process handle taken from get_child(ev.dwProcessId). > > And since I'm generally fuzzy and unclear in my first reply: > > Of course, ev.u.LoadDll.lpBaseOfDll is not the mapping *object*, but the > mapping *address*. So you neither have to call CreateFileMapping nor > MapViewOfFile. Just call GetMappedFileNameW (get_child (ev.dwProcessId), > ev.u.LoadDll.lpBaseOfDll, ...) This works for me resulting in Win32 pathnames. These are only the affected diff hunks, I omited the rest. Does that work for you? Btw., I don't like using MAX_PATH as maximum path length, but I think DLL paths can't be longer anyway, so that should be ok... diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc index 73096ab..0661e17 100644 --- a/winsup/utils/strace.cc +++ b/winsup/utils/strace.cc @@ -54,6 +54,8 @@ static BOOL close_handle (HANDLE h, DWORD ok); #define CloseHandle(h) close_handle(h, 0) +static void *drive_map; + struct child_list { DWORD id; @@ -637,6 +639,30 @@ handle_output_debug_string (DWORD id, LPVOID p, unsigned mask, FILE *ofile) fflush (ofile); } +static BOOL +GetFileNameFromHandle(HANDLE hFile, WCHAR pszFilename[MAX_PATH+1]) +{ + BOOL result = FALSE; + ULONG len = 0; + OBJECT_NAME_INFORMATION *ntfn = (OBJECT_NAME_INFORMATION *) alloca (65536); + NTSTATUS status = NtQueryObject (hFile, ObjectNameInformation, + ntfn, 65536, &len); + if (NT_SUCCESS (status)) + { + PWCHAR win32path = ntfn->Name.Buffer; + win32path[ntfn->Name.Length / sizeof (WCHAR)] = L'\0'; + + /* NtQueryObject returns a native NT path. (Try to) convert to Win32. */ + if (drive_map) + win32path = (PWCHAR) cygwin_internal (CW_MAP_DRIVE_MAP, drive_map, + win32path); + pszFilename[0] = L'\0'; + wcsncat (pszFilename, win32path, MAX_PATH); + result = TRUE; + } + return result; +} + static DWORD proc_child (unsigned mask, FILE *ofile, pid_t pid) { @@ -1090,7 +1143,13 @@ character #%d.\n", optarg, (int) (endptr - optarg), endptr); if (toggle) dotoggle (pid); else - ExitProcess (dostrace (mask, ofile, pid, argv + optind)); + { + drive_map = (void *) cygwin_internal (CW_ALLOC_DRIVE_MAP); + DWORD ret = dostrace (mask, ofile, pid, argv + optind); + if (drive_map) + cygwin_internal (CW_FREE_DRIVE_MAP, drive_map); + ExitProcess (ret); + } return 0; } Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat