Something in this direction should be done:
(let ((result '())) (mapatoms (lambda (x) (when (boundp x) (let ((file (ignore-errors (find-lisp-object-file-name x 'defvar)))) (when file (push (cons x file) result)))))) result)
Warning: it takes a long time to complete.
source share