unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: guile-user@gnu.org
Subject: Re: Getting all symbols in a Scheme file as a list
Date: Sun, 4 Feb 2024 13:39:26 -0800	[thread overview]
Message-ID: <0b465cca-ccef-4e34-a758-0500544e676f@gmail.com> (raw)
In-Reply-To: <03f7199a-daf2-e070-8156-6837d7e20e32@mutix.org>

On 2/4/24 11:50 AM, Christina O'Donnell wrote:
> I'm trying to write a Guile script to trace symbol definition and 
> reference
> between modules in a large Guile repo (GNU/Guix), for the purposes of 
> large
> scale refactoring.

> ? Seems a little bit baroque to me, I'd expect a simpler way of doing 
> it. Any
> libraries anyone knows of?

Maybe use something from (system vm elf ) on the .go files?

$ cd .../ice-9/
$ nm safe.go
00000000000002ac r
0000000000000248 r make-safe-module
00000000000001c4 r safe-environment


I use guile elf to extract info from C-sourced files, but maybe some 
tidbits may help:

   (let* ((bv (call-with-input-file filename
                (lambda (port)
                  (get-bytevector-n port (and=> (stat port) stat:size)))))
          (elf (parse-elf bv))
    (pretty-print (elf-named-syms elf))

(define (elf-named-syms elf)
   (define (less a b) (< (elf-symbol-value (cdr a)) (elf-symbol-value 
(cdr b))))
   (let* ((.symtab (elf-section-by-name elf ".symtab"))
          (strtab (elf-section elf (elf-section-link .symtab)))
          (tbl-len (elf-symbol-table-len .symtab)))
     (let loop ((symd '()) (ix 0))
       (if (< ix tbl-len)
           (let* ((sym (elf-symbol-table-ref elf .symtab ix strtab))
                  (name (elf-symbol-name sym))
                  (nlen (string-length name)))
             (loop (if (positive? nlen) (acons name sym symd) symd) (1+ 
ix)))
           (sort symd less)))))





      parent reply	other threads:[~2024-02-04 21:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-04 19:50 Getting all symbols in a Scheme file as a list Christina O'Donnell
2024-02-04 21:03 ` M
2024-02-05 13:04   ` Christina O'Donnell
2024-02-04 21:39 ` Matt Wette [this message]

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0b465cca-ccef-4e34-a758-0500544e676f@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=guile-user@gnu.org \
    /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).