charles-zablit wrote:

> No, that's not the case. `GetModuleHandleExW` with 
> `GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS` should be fine.

I tried it and it does not work. `GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS` 
resolves the address against the calling process's module list, not the 
debuggee's.

Results when debugging a simple program(`sleeper.exe`):

```
  [sleeper.exe]      base=00007FF660470000
      GetModuleFileNameExW:    \\?\C:\Users\...\sleeper.exe
      GetModuleHandleExW:      FAILED err=126          // ERROR_MOD_NOT_FOUND

  [umppc21108.dll]   base=00000218061A0000
      GetModuleFileNameExW:    C:\windows\System32\umppc21108.dll
      GetModuleHandleExW:      FAILED err=126

  [ntdll.dll]        base=00007FFFB9560000
      GetModuleFileNameExW:    C:\windows\SYSTEM32\ntdll.dll
      GetModuleHandleExW:      HMODULE=00007FFFB9560000
        ...which is:           C:\windows\SYSTEM32\ntdll.dll
      GetFinalPathName(HMOD):  FAILED needed=0 err=6   // ERROR_INVALID_HANDLE
```

Also, I found that instead of truncating a long path, 
`CreateToolhelp32Snapshot(TH32CS_SNAPMODULE)` refuses the process path outright 
with ERROR_MORE_DATA

| exe path | recorded image path (with `\\?\`) | 
`CreateToolhelp32Snapshot(TH32CS_SNAPMODULE)` | `EnumProcessModulesEx` + 
`GetModuleFileNameExW` |
  | -------: | -------------------------------: | 
--------------------------------------------- | 
----------------------------------------------- |
  | 251 | 255 | OK | OK |
  | 257 | 261 | `INVALID_HANDLE_VALUE`, `ERROR_MORE_DATA` (234) | OK |
  | 287 | 291 | `INVALID_HANDLE_VALUE`, `ERROR_MORE_DATA` (234) | OK |

> While ToolHlp32 has its own set of issues, you are certain that the snapshot 
> itself is valid.

I don't think this is true per the documentation: 
https://learn.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot
> if the module list changes during the function call as a result of DLLs being 
> loaded or unloaded, the function might fail with ERROR_BAD_LENGTH or other 
> error code.

https://github.com/llvm/llvm-project/pull/206117
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to