From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-patches@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH 1/5] Cygwin: Show details of all memory regions details in dumper debug output
Date: Sat, 18 Jul 2020 16:00:24 +0100 [thread overview]
Message-ID: <20200718150028.1709-2-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20200718150028.1709-1-jon.turney@dronecode.org.uk>
---
winsup/utils/dumper.cc | 101 ++++++++++++++++++++++++++++++++---------
1 file changed, 80 insertions(+), 21 deletions(-)
diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc
index ccc4bd12f..46e4b0692 100644
--- a/winsup/utils/dumper.cc
+++ b/winsup/utils/dumper.cc
@@ -289,6 +289,25 @@ dumper::add_module (LPVOID base_address)
#define PAGE_BUFFER_SIZE 4096
+void protect_dump(DWORD protect, char *buf)
+{
+ const char *pt[10];
+ pt[0] = (protect & PAGE_READONLY) ? "RO " : "";
+ pt[1] = (protect & PAGE_READWRITE) ? "RW " : "";
+ pt[2] = (protect & PAGE_WRITECOPY) ? "WC " : "";
+ pt[3] = (protect & PAGE_EXECUTE) ? "EX " : "";
+ pt[4] = (protect & PAGE_EXECUTE_READ) ? "EXRO " : "";
+ pt[5] = (protect & PAGE_EXECUTE_READWRITE) ? "EXRW " : "";
+ pt[6] = (protect & PAGE_EXECUTE_WRITECOPY) ? "EXWC " : "";
+ pt[7] = (protect & PAGE_GUARD) ? "GRD " : "";
+ pt[8] = (protect & PAGE_NOACCESS) ? "NA " : "";
+ pt[9] = (protect & PAGE_NOCACHE) ? "NC " : "";
+
+ buf[0] = '\0';
+ for (int i = 0; i < 10; i++)
+ strcat (buf, pt[i]);
+}
+
int
dumper::collect_memory_sections ()
{
@@ -313,10 +332,65 @@ dumper::collect_memory_sections ()
break;
int skip_region_p = 0;
+ const char *disposition = "dumped";
- if (mbi.Protect & (PAGE_NOACCESS | PAGE_GUARD) ||
- mbi.State != MEM_COMMIT)
- skip_region_p = 1;
+ if (mbi.Protect & PAGE_NOACCESS)
+ {
+ skip_region_p = 1;
+ disposition = "skipped due to noaccess";
+ }
+
+ if (mbi.Protect & PAGE_GUARD)
+ {
+ skip_region_p = 1;
+ disposition = "skipped due to guardpage";
+ }
+
+ if (mbi.State != MEM_COMMIT)
+ {
+ skip_region_p = 1;
+ disposition = "skipped due to uncommited";
+ }
+
+ {
+ char buf[10 * 6];
+ protect_dump(mbi.Protect, buf);
+
+ const char *state = "";
+ const char *type = "";
+
+ if (mbi.State & MEM_COMMIT)
+ {
+ state = "COMMIT";
+ }
+ else if (mbi.State & MEM_FREE)
+ {
+ state = "FREE";
+ type = "FREE";
+ }
+ else if (mbi.State & MEM_RESERVE)
+ {
+ state = "RESERVE";
+ }
+
+ if (mbi.Type & MEM_IMAGE)
+ {
+ type = "IMAGE";
+ }
+ else if (mbi.Type & MEM_MAPPED)
+ {
+ type = "MAPPED";
+ }
+ else if (mbi.Type & MEM_PRIVATE)
+ {
+ type = "PRIVATE";
+ }
+
+ deb_printf ("region 0x%016lx-0x%016lx (protect = %-8s, state = %-7s, type = %-7s, %s)\n",
+ current_page_address,
+ current_page_address + mbi.RegionSize,
+ buf, state, type, disposition);
+ }
if (!skip_region_p)
{
@@ -326,26 +400,11 @@ dumper::collect_memory_sections ()
if (!ReadProcessMemory (hProcess, current_page_address, mem_buf, sizeof (mem_buf), &done))
{
DWORD err = GetLastError ();
- const char *pt[10];
- pt[0] = (mbi.Protect & PAGE_READONLY) ? "RO " : "";
- pt[1] = (mbi.Protect & PAGE_READWRITE) ? "RW " : "";
- pt[2] = (mbi.Protect & PAGE_WRITECOPY) ? "WC " : "";
- pt[3] = (mbi.Protect & PAGE_EXECUTE) ? "EX " : "";
- pt[4] = (mbi.Protect & PAGE_EXECUTE_READ) ? "EXRO " : "";
- pt[5] = (mbi.Protect & PAGE_EXECUTE_READWRITE) ? "EXRW " : "";
- pt[6] = (mbi.Protect & PAGE_EXECUTE_WRITECOPY) ? "EXWC " : "";
- pt[7] = (mbi.Protect & PAGE_GUARD) ? "GRD " : "";
- pt[8] = (mbi.Protect & PAGE_NOACCESS) ? "NA " : "";
- pt[9] = (mbi.Protect & PAGE_NOCACHE) ? "NC " : "";
- char buf[10 * 6];
- buf[0] = '\0';
- for (int i = 0; i < 10; i++)
- strcat (buf, pt[i]);
-
- deb_printf ("warning: failed to read memory at %p-%p (protect = %s), error %ld.\n",
+
+ deb_printf ("warning: failed to read memory at %p-%p, error %ld.\n",
current_page_address,
current_page_address + mbi.RegionSize,
- buf, err);
+ err);
skip_region_p = 1;
}
}
--
2.27.0
next prev parent reply other threads:[~2020-07-18 15:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-18 15:00 [PATCH 0/5] Improve dumper megion region selection Jon Turney
2020-07-18 15:00 ` Jon Turney [this message]
2020-07-18 15:00 ` [PATCH 2/5] Cygwin: Remove reading of PE for section flags from dumper Jon Turney
2020-07-18 15:00 ` [PATCH 3/5] Cygwin: Drop excluded regions list " Jon Turney
2020-07-18 15:00 ` [PATCH 4/5] Cygwin: Don't dump non-writable image regions Jon Turney
2020-07-18 15:00 ` [PATCH 5/5] Cygwin: Use MEMORY_WORKING_SET_EX_INFORMATION in dumper Jon Turney
2020-07-20 8:15 ` Corinna Vinschen
2020-07-28 2:20 ` Takashi Yano
2020-07-28 21:04 ` Jon Turney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200718150028.1709-2-jon.turney@dronecode.org.uk \
--to=jon.turney@dronecode.org.uk \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).