From: Andrew Jones <andrew.jones@linux.dev>
To: Nadav Amit <nadav.amit@gmail.com>
Cc: kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu,
kvm@vger.kernel.org, Nikos Nikoleris <nikos.nikoleris@arm.com>,
Nadav Amit <namit@vmware.com>
Subject: Re: [kvm-unit-tests PATCH 2/6] lib/stack: print base addresses on efi
Date: Sat, 24 Jun 2023 12:13:19 +0200 [thread overview]
Message-ID: <20230624-9983c4a6d41751719785a95c@orel> (raw)
In-Reply-To: <20230617014930.2070-3-namit@vmware.com>
On Sat, Jun 17, 2023 at 01:49:26AM +0000, Nadav Amit wrote:
> From: Nadav Amit <namit@vmware.com>
>
> Making sense from dumped stacks when running EFI tests is very hard due
> to the relocation. Fix it by adjusting the address back to the original
> address.
>
> Signed-off-by: Nadav Amit <namit@vmware.com>
> ---
> lib/stack.c | 31 +++++++++++++++++++++++++++++--
> 1 file changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/lib/stack.c b/lib/stack.c
> index bdb23fd..c3c7c24 100644
> --- a/lib/stack.c
> +++ b/lib/stack.c
> @@ -6,13 +6,38 @@
> */
>
> #include <libcflat.h>
> +#include <stdbool.h>
> #include <stack.h>
>
> #define MAX_DEPTH 20
>
> +#ifdef CONFIG_EFI
We also relocate when building non-efi arm64 unit tests, so this should be
#if defined(CONFIG_EFI) || defined(__aarch64__)
Or, we could create a new config, CONFIG_RELOC, which gets set by
--enable-efi and --arch=arm64.
> +extern char _text, _etext;
> +
> +static bool base_address(const void *rebased_addr, unsigned long *addr)
> +{
> + unsigned long ra = (unsigned long)rebased_addr;
> + unsigned long start = (unsigned long)&_text;
> + unsigned long end = (unsigned long)&_etext;
> +
> + if (ra < start || ra >= end)
> + return false;
> +
> + *addr = ra - start;
> + return true;
> +}
> +#else
> +static bool base_address(const void *rebased_addr, unsigned long *addr)
> +{
> + *addr = (unsigned long)rebased_addr;
> + return true;
> +}
> +#endif
> +
> static void print_stack(const void **return_addrs, int depth,
> bool top_is_return_address)
> {
> + unsigned long addr;
> int i = 0;
>
> printf("\tSTACK:");
> @@ -20,12 +45,14 @@ static void print_stack(const void **return_addrs, int depth,
> /* @addr indicates a non-return address, as expected by the stack
> * pretty printer script. */
> if (depth > 0 && !top_is_return_address) {
> - printf(" @%lx", (unsigned long) return_addrs[0]);
> + if (base_address(return_addrs[0], &addr))
> + printf(" @%lx", addr);
> i++;
> }
>
> for (; i < depth; i++) {
> - printf(" %lx", (unsigned long) return_addrs[i]);
> + if (base_address(return_addrs[i], &addr))
> + printf(" %lx", addr);
> }
> printf("\n");
> }
> --
> 2.34.1
>
Thanks,
drew
next prev parent reply other threads:[~2023-06-24 10:13 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-17 1:49 [kvm-unit-tests PATCH 0/6] arm64: improve debuggability Nadav Amit
2023-06-17 1:49 ` [kvm-unit-tests PATCH 1/6] arm: keep efi debug information in a separate file Nadav Amit
2023-06-24 10:12 ` Andrew Jones
2023-06-24 10:31 ` Andrew Jones
2023-06-25 19:21 ` Nadav Amit
2023-06-17 1:49 ` [kvm-unit-tests PATCH 2/6] lib/stack: print base addresses on efi Nadav Amit
2023-06-24 10:13 ` Andrew Jones [this message]
2023-06-25 19:23 ` Nadav Amit
2023-06-17 1:49 ` [kvm-unit-tests PATCH 3/6] arm64: enable frame pointer and support stack unwinding Nadav Amit
2023-06-24 10:13 ` Andrew Jones
2023-06-25 19:22 ` Nadav Amit
2023-06-26 5:42 ` Andrew Jones
2023-06-17 1:49 ` [kvm-unit-tests PATCH 4/6] arm64: stack: update trace stack on exception Nadav Amit
2023-06-24 10:18 ` Andrew Jones
2023-06-17 1:49 ` [kvm-unit-tests PATCH 5/6] efi: Print address of image Nadav Amit
2023-06-17 1:49 ` [kvm-unit-tests PATCH 6/6] arm64: dump stack on bad exception Nadav Amit
2023-06-17 1:52 ` Nadav Amit
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=20230624-9983c4a6d41751719785a95c@orel \
--to=andrew.jones@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=kvmarm@lists.linux.dev \
--cc=nadav.amit@gmail.com \
--cc=namit@vmware.com \
--cc=nikos.nikoleris@arm.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