From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Matt Wette <matt.wette@gmail.com>
Newsgroups: gmane.lisp.guile.user
Subject: Re: Getting all symbols in a Scheme file as a list
Date: Sun, 4 Feb 2024 13:39:26 -0800
Message-ID: <0b465cca-ccef-4e34-a758-0500544e676f@gmail.com>
References: <03f7199a-daf2-e070-8156-6837d7e20e32@mutix.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="8042"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Mozilla Thunderbird
To: guile-user@gnu.org
Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Feb 04 22:40:10 2024
Return-path: <guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org>
Envelope-to: guile-user@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org>)
	id 1rWkDi-0001zN-Rq
	for guile-user@m.gmane-mx.org; Sun, 04 Feb 2024 22:40:10 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <guile-user-bounces@gnu.org>)
	id 1rWkDA-0001ZH-KF; Sun, 04 Feb 2024 16:39:36 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <matt.wette@gmail.com>)
 id 1rWkD8-0001Yp-0i
 for guile-user@gnu.org; Sun, 04 Feb 2024 16:39:34 -0500
Original-Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <matt.wette@gmail.com>)
 id 1rWkD5-00036V-QR
 for guile-user@gnu.org; Sun, 04 Feb 2024 16:39:33 -0500
Original-Received: by mail-pl1-x632.google.com with SMTP id
 d9443c01a7336-1d746ce7d13so31570025ad.0
 for <guile-user@gnu.org>; Sun, 04 Feb 2024 13:39:30 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1707082768; x=1707687568; darn=gnu.org;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:to:subject:user-agent:mime-version:date:message-id:from
 :to:cc:subject:date:message-id:reply-to;
 bh=5aV4QvfRG1u7LH7+GQwWiZ1gPfnJLp2pyn5n/ggLaeY=;
 b=fsxEady5OhGrTg38IcTMI1/nV34mPssknbVFEiuqBhMGUq3lI3qWpUd8+5qiYVTyrf
 TRdXOp/jFySa0q34LmTlWTCipRdipC23zxpt6Rbq4YIRxCZySAN5CuMOgKAxVlHr5A6M
 qqGlCEKYLjrUEKp7T5tLh5Pduzmqn9LtlpBxn0tvCFJnbQzd4REM41xsOamiyjZcIU+4
 ExN3AsYJOC7xcc2YvljnevhUQP+BwunbgHH1gNGthbslpIFIQ9AvacfEed6jQ0HHKBbe
 KTdfcT+YqwjtS7ZZn9HN+e4K7211QcEcgaCsfNP54hVYI1i1Lhmqu4lm6CM6DaSDGjNX
 Vpgg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1707082768; x=1707687568;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:to:subject:user-agent:mime-version:date:message-id
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=5aV4QvfRG1u7LH7+GQwWiZ1gPfnJLp2pyn5n/ggLaeY=;
 b=EjNgf4b5bVECNpwL/8XJ+Sy/pq9XRzm2CbmuJWwffMXK4kYe2YsGZLOQCcafzeG6So
 xF0wve4M8x7wDrjWjwrkSso79Q3RkkNzcOR2MJPxiAOS9YlCC5yP2hrrMALTtZ7266PU
 0tqKPbhnIcVnDWyQ2e76eSof9yr5+RyLHjMGq1Rh4VZIeP4y0jfmoe2KApyT6ErxB01F
 9IBKwDR+zS5MNRxmVLauuQOGKX6ULLLativda9eTV8nTg4oQTCqJ3tipKKWe5BI0taIU
 nVgrICQK0uK8NV8ZSRkAxyh9MkrHduzCUW5QSmiXywsyQXiPh3e1GoJQAkdkQU+2ns/B
 8j+g==
X-Gm-Message-State: AOJu0YwKz/4xEln45MpDfMpld8tWl6PQez8ZVdQtZPXoS4MDkIbmdXmP
 CXmPjbElAcqhiCuwwWKzOl6vwrWqjoO6B9Y0sMsiyj2d/zQ9jFLFxk2cRiV+
X-Google-Smtp-Source: AGHT+IHHxA+009JUK3E2r4OUoJCyiTfQEiZEoyFcH+chfOqQW4+S5Lxeyq0oRo+wFg2Aunt6IUnfSA==
X-Received: by 2002:a17:902:e5c4:b0:1d9:b27b:1b66 with SMTP id
 u4-20020a170902e5c400b001d9b27b1b66mr2120573plf.7.1707082768356; 
 Sun, 04 Feb 2024 13:39:28 -0800 (PST)
Original-Received: from [192.168.2.154] (64-52-138-37.championbroadband.com.
 [64.52.138.37]) by smtp.gmail.com with ESMTPSA id
 ka5-20020a170903334500b001d9b0990cc5sm768001plb.126.2024.02.04.13.39.27
 for <guile-user@gnu.org>
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Sun, 04 Feb 2024 13:39:27 -0800 (PST)
Content-Language: en-US
In-Reply-To: <03f7199a-daf2-e070-8156-6837d7e20e32@mutix.org>
Received-SPF: pass client-ip=2607:f8b0:4864:20::632;
 envelope-from=matt.wette@gmail.com; helo=mail-pl1-x632.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: guile-user@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Guile related discussions <guile-user.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/guile-user>,
 <mailto:guile-user-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/guile-user>
List-Post: <mailto:guile-user@gnu.org>
List-Help: <mailto:guile-user-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/guile-user>,
 <mailto:guile-user-request@gnu.org?subject=subscribe>
Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org
Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.lisp.guile.user:19439
Archived-At: <http://permalink.gmane.org/gmane.lisp.guile.user/19439>

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