diff options
author | Tom Tromey <tromey@adacore.com> | 2020-04-08 14:33:35 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2020-04-08 14:47:58 -0600 |
commit | 9d8679cc712d4c31d218cc141fe700d8e6394964 (patch) | |
tree | 41c6b2c0658250425f1bbd76aa5392ff7e38433d /gdb/nat | |
parent | 28688adf8f883fdd8b642a446ec5578236e84b1e (diff) | |
download | gdb-9d8679cc712d4c31d218cc141fe700d8e6394964.zip gdb-9d8679cc712d4c31d218cc141fe700d8e6394964.tar.gz gdb-9d8679cc712d4c31d218cc141fe700d8e6394964.tar.bz2 |
Share get_image_name between gdb and gdbserver
This moves get_image_name to nat/windows-nat.c so that it can be
shared between gdb and gdbserver.
gdb/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* windows-nat.c (get_image_name): Move to nat/windows-nat.c.
(handle_load_dll): Update.
* nat/windows-nat.c (get_image_name): Move from windows-nat.c.
gdbserver/ChangeLog
2020-04-08 Tom Tromey <tromey@adacore.com>
* win32-low.c (get_image_name): Remove.
(handle_load_dll): Update.
Diffstat (limited to 'gdb/nat')
-rw-r--r-- | gdb/nat/windows-nat.c | 57 | ||||
-rw-r--r-- | gdb/nat/windows-nat.h | 7 |
2 files changed, 64 insertions, 0 deletions
diff --git a/gdb/nat/windows-nat.c b/gdb/nat/windows-nat.c index 6c0218c..8217a98 100644 --- a/gdb/nat/windows-nat.c +++ b/gdb/nat/windows-nat.c @@ -69,4 +69,61 @@ windows_thread_info::resume () suspended = 0; } +const char * +get_image_name (HANDLE h, void *address, int unicode) +{ +#ifdef __CYGWIN__ + static char buf[MAX_PATH]; +#else + static char buf[(2 * MAX_PATH) + 1]; +#endif + DWORD size = unicode ? sizeof (WCHAR) : sizeof (char); + char *address_ptr; + int len = 0; + char b[2]; + SIZE_T done; + + /* Attempt to read the name of the dll that was detected. + This is documented to work only when actively debugging + a program. It will not work for attached processes. */ + if (address == NULL) + return NULL; + +#ifdef _WIN32_WCE + /* Windows CE reports the address of the image name, + instead of an address of a pointer into the image name. */ + address_ptr = address; +#else + /* See if we could read the address of a string, and that the + address isn't null. */ + if (!ReadProcessMemory (h, address, &address_ptr, + sizeof (address_ptr), &done) + || done != sizeof (address_ptr) + || !address_ptr) + return NULL; +#endif + + /* Find the length of the string. */ + while (ReadProcessMemory (h, address_ptr + len++ * size, &b, size, &done) + && (b[0] != 0 || b[size - 1] != 0) && done == size) + continue; + + if (!unicode) + ReadProcessMemory (h, address_ptr, buf, len, &done); + else + { + WCHAR *unicode_address = (WCHAR *) alloca (len * sizeof (WCHAR)); + ReadProcessMemory (h, address_ptr, unicode_address, len * sizeof (WCHAR), + &done); +#ifdef __CYGWIN__ + wcstombs (buf, unicode_address, MAX_PATH); +#else + WideCharToMultiByte (CP_ACP, 0, unicode_address, len, buf, sizeof buf, + 0, 0); +#endif + } + + return buf; +} + } diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index e63ef75..4176ed7 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -111,6 +111,13 @@ enum thread_disposition_type extern windows_thread_info *thread_rec (ptid_t ptid, thread_disposition_type disposition); +/* Return the name of the DLL referenced by H at ADDRESS. UNICODE + determines what sort of string is read from the inferior. Returns + the name of the DLL, or NULL on error. If a name is returned, it + is stored in a static buffer which is valid until the next call to + get_image_name. */ +extern const char *get_image_name (HANDLE h, void *address, int unicode); + } #endif |