0

Assume that we have:

(defalias 'my-f (lambda () (message "a")))
(byte-compile 'my-f)
=> #f(compiled-function
      ()
      #<bytecode 0x1dc01052127a>)

(setq my-g (byte-compile (lambda () (message "b"))))
=> #f(compiled-function
      ()
     #<bytecode 0x1dc010521246>)

Then I can call disassemble later and select my-f, but that's not the same for my-g, although we know that my-g holds #<bytecode 0x1dc010521246>.

Is it possible to disassemble by supplying #<bytecode 0x1dc010521246> directly?

Edit: my-g is just an example, sometimes I inspect from places such as the backtrace, profiler report buffer, etc., only the address is shown:

361  26%                  - documentation
302  21%                   - substitute-command-keys
287  20%                    - #<compiled -0x1c8af252237f110f>
219  15%                     - kill-buffer
Drew
  • 75,699
  • 9
  • 109
  • 225
Daanturo
  • 180
  • 8

1 Answers1

1

Did you try it? You can pass any function, with or without a name, to disassemble:

(disassemble my-g)

results in:

byte code:
  args: nil
0       constant  message
1       constant  "b"
2       call      1
3       return    

Edit: Ok, based on your revision to the question, what you’re asking really has nothing to do with disassembly. What you’re actually trying to do is retrieve a value given a printed representation of its address.

There is no way to do that from Elisp, because that address could refer to a memory that has been garbage collected or reused by now, or because you might supply the wrong type information (whether accidentally or on purpose), etc. Furthermore, the value you see might not actually be an address; in some cases it will be a hash of the value instead.

In the specific case of debugging or profiling some code, you should track the compiled function back to where it came from; what variables or arguments it was stored in, etc, until you find out which function it is. Then you’ll be able to disassemble it. In the specific case you mention, you could modify substitute-command-keys to call disassemble on the function for you, if you couldn’t figure out where it came from or if it was simply never stored in a variable you could access.

db48x
  • 15,741
  • 1
  • 19
  • 23
  • But how do I do the same if only `#` is known, but the fact that `my-g` is set to it isn't acknowledged? – Daanturo May 11 '22 at 14:11