[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting all symbols in a Scheme file as a list

From: Matt Wette
Subject: Re: Getting all symbols in a Scheme file as a list
Date: Sun, 4 Feb 2024 13:39:26 -0800
User-agent: Mozilla Thunderbird

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)))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]