From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-patches@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH 2/3] Cygwin: Add addresses as module offsets in .stackdump file
Date: Fri, 28 Oct 2022 16:05:57 +0100 [thread overview]
Message-ID: <20221028150558.2300-3-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20221028150558.2300-1-jon.turney@dronecode.org.uk>
This adds an additional column to the stack trace in a .stackdump file,
which gives the stack frame return address as a module name+offset. This
makes it a possible to convert the address to a function name without
having to guess what module the address belongs to.
> Stack trace:
> Frame Function Args
> 0007FFFFCC30 0001004010E9 (000180048055, 000180046FA0, 000000000002, 00018031E160) segv-test.exe+0x10E9
> 0007FFFFCD30 0001800480C1 (000000000000, 000000000000, 000000000000, 000000000000) cygwin1.dll+0x80C1
> 0007FFFFFFF0 000180045C86 (000000000000, 000000000000, 000000000000, 000000000000) cygwin1.dll+0x5C86
> 0007FFFFFFF0 000180045D34 (000000000000, 000000000000, 000000000000, 000000000000) cygwin1.dll+0x5D34
> End of stack trace
Loosely based on this patch [1] by Brian Dessent.
[1] https://cygwin.com/pipermail/cygwin-patches/2008q1/006306.html
---
winsup/cygwin/exceptions.cc | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index a15bc16c5..1e9ea26bf 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -324,6 +324,34 @@ stack_info::walk ()
return 1;
}
+/*
+ Walk the list of modules in the current process to find the one containing
+ 'func_va'.
+
+ This implementation requires no allocation of memory and minimal system
+ calls, so it should be safe in the context of an exception handler.
+*/
+static char *
+prettyprint_va (PVOID func_va)
+{
+ static char buf[256];
+ buf[0] = '\0';
+
+ PLIST_ENTRY head = &NtCurrentTeb()->Peb->Ldr->InMemoryOrderModuleList;
+ for (PLIST_ENTRY x = head->Flink; x != head; x = x->Flink)
+ {
+ PLDR_DATA_TABLE_ENTRY mod = CONTAINING_RECORD (x, LDR_DATA_TABLE_ENTRY,
+ InMemoryOrderLinks);
+ if (mod->DllBase > func_va)
+ continue;
+
+ __small_sprintf (buf, "%S+0x%x", &mod->BaseDllName,
+ (DWORD_PTR)func_va - (DWORD_PTR)mod->DllBase);
+ }
+
+ return buf;
+}
+
void
cygwin_exception::dumpstack ()
{
@@ -350,7 +378,7 @@ cygwin_exception::dumpstack ()
for (unsigned j = 0; j < NPARAMS; j++)
small_printf ("%s%012X", j == 0 ? " (" : ", ",
thestack.sf.Params[j]);
- small_printf (")\r\n");
+ small_printf (") %s\r\n", prettyprint_va((PVOID)thestack.sf.AddrPC.Offset));
}
small_printf ("End of stack trace%s\r\n",
i == DUMPSTACK_FRAME_LIMIT ?
--
2.38.1
next prev parent reply other threads:[~2022-10-28 15:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 15:05 [PATCH 0/3] Stackdump improvements Jon Turney
2022-10-28 15:05 ` [PATCH 1/3] Cygwin: Tidy up formatting of stackdump Jon Turney
2022-10-28 15:05 ` Jon Turney [this message]
2022-10-28 15:05 ` [PATCH 3/3] Cygwin: Add loaded module base address list to stackdump Jon Turney
2022-10-29 8:32 ` Corinna Vinschen
2022-11-03 17:02 ` Jon Turney
2022-11-04 10:34 ` Corinna Vinschen
2022-10-29 8:34 ` [PATCH 0/3] Stackdump improvements Corinna Vinschen
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=20221028150558.2300-3-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).