From: Fredrik Tolf Date: Mon, 10 Mar 2025 16:20:16 +0000 (+0100) Subject: pstack: Add some name resolution options. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=HEAD;hp=0756cac45415c20db394f851107411afe1448996;p=utils.git pstack: Add some name resolution options. --- diff --git a/acmecert b/acmecert index 84c212a..14d0f00 100755 --- a/acmecert +++ b/acmecert @@ -462,8 +462,9 @@ def mkorder(acct, csr): def httptoken(acct, ch): from cryptography.hazmat.primitives import hashes - jwk = {"kty": "RSA", "e": ebignum(acct.key.e), "n": ebignum(acct.key.n)} - dig = hashes.Hash(hashes.SHA256()) + pub = acct.key.public_key().public_numbers() + jwk = {"kty": "RSA", "e": ebignum(pub.e), "n": ebignum(pub.n)} + dig = hashes.Hash(hashes.SHA256(), backend=cryptobke()) dig.update(json.dumps(jwk, separators=(',', ':'), sort_keys=True).encode("us-ascii")) khash = base64url(dig.finalize()) return ch["token"], ("%s.%s" % (ch["token"], khash)) diff --git a/pstack.c b/pstack.c index 2c5be1f..9a04a66 100644 --- a/pstack.c +++ b/pstack.c @@ -11,10 +11,10 @@ static void usage(FILE *out) { - fprintf(out, "usage: pstack [-h] PID\n"); + fprintf(out, "usage: pstack [-hna] PID\n"); } -static int dumpstack(pid_t pid) +static int dumpstack(pid_t pid, int resolve) { int rv, s; unw_addr_space_t rps; @@ -27,21 +27,26 @@ static int dumpstack(pid_t pid) ptd = _UPT_create(pid); rv = 0; if((s = unw_init_remote(&uw, rps, ptd)) != 0) { - fprintf(stderr, "pstack: init_remote: %i\n", s); + fprintf(stderr, "pstack: init_remote: %s\n", unw_strerror(s)); rv = 1; goto out; } do { - if(!(s = unw_get_proc_name(&uw, pnm, sizeof(pnm), &pcoff)) || (s == -UNW_ENOMEM)) { + if(resolve && (!(s = unw_get_proc_name(&uw, pnm, sizeof(pnm), &pcoff)) || (s == -UNW_ENOMEM))) { pnm[sizeof(pnm) - 1] = 0; - printf("%s+%jx\n", pnm, (intmax_t)pcoff); + if(resolve == 2) { + unw_get_reg(&uw, UNW_REG_IP, ®); + printf("%s(%jx)+%jx\n", pnm, (intmax_t)(reg - pcoff), (intmax_t)pcoff); + } else { + printf("%s+%jx\n", pnm, (intmax_t)pcoff); + } } else { unw_get_reg(&uw, UNW_REG_IP, ®); printf("%jx\n", (intmax_t)reg); } } while((s = unw_step(&uw)) > 0); if(s < 0) { - fprintf(stderr, "pstack: step: %i\n", s); + fprintf(stderr, "pstack: step: %s\n", unw_strerror(s)); } out: _UPT_destroy(ptd); @@ -51,14 +56,21 @@ out: int main(int argc, char **argv) { - int c, s; + int c, s, res; pid_t pid; - while((c = getopt(argc, argv, "h")) != -1) { + res = 1; + while((c = getopt(argc, argv, "hna")) != -1) { switch(c) { case 'h': usage(stdout); exit(0); + case 'n': + res = 0; + break; + case 'a': + res = 2; + break; default: usage(stderr); exit(1); @@ -81,7 +93,7 @@ int main(int argc, char **argv) if(WIFSTOPPED(s)) break; } - dumpstack(pid); + dumpstack(pid, res); if(ptrace(PTRACE_DETACH, pid, NULL, NULL)) { fprintf(stderr, "pstack: detach: %s\n", strerror(errno)); }