lensm icon indicating copy to clipboard operation
lensm copied to clipboard

add support for other languages

Open egonelbre opened this issue 3 years ago • 8 comments

Technically the core logic needs:

  1. list of symbols (https://github.com/loov/lensm/blob/d9771339009f7ac9663afc6de248d7f98b63f011/internal/disasm/file.go#L3)
  2. a way to disassemble and get line number for each instruction (https://github.com/loov/lensm/blob/main/internal/disasm/code.go#L1)

Rest of the code should work fine.

egonelbre avatar Jul 16 '22 18:07 egonelbre

Yes please! C++ source isn't loading right now.

mcourteaux avatar Dec 23 '22 18:12 mcourteaux

@mcourteaux can you provide a minimal repro, it'll be easier to test.

egonelbre avatar Dec 23 '22 22:12 egonelbre

Sure:

#include <cstdio>

int main(int argc, char** argv) {
  std::printf("hello\n");
  return 0;
}

Compile it:

g++ main.cpp -o repro

Start lensm (not even sure if this is the default way, I don't use use go):

go run loov.dev/lensm@main repro

Result: image

mcourteaux avatar Dec 24 '22 10:12 mcourteaux

You also need to include dwarf information in the binary -- i.e. g++ -gdwarf main.cpp -o repro. It might work on linux already, but I haven't tested.

For installing the tool go install loov.dev/lensm@main, it'll put it in $HOME/go/bin by default. But using go run is fine as well, except it might try to fetch the latest version every time.

egonelbre avatar Dec 24 '22 12:12 egonelbre

Just tried your suggestion, and it still isn't working. Is there some verbose mode that could give you more information? Thanks for telling me about go install. :smile:

mcourteaux avatar Dec 26 '22 10:12 mcourteaux

@mcourteaux if it doesn't work, then my guess was just wrong :).

egonelbre avatar Dec 26 '22 13:12 egonelbre

I would really like a general language tool for doing what this does for C Rust C++ etc. I am willing to put the time to make this happen

is this a direction this project is willing to go or should I make my own tool?

nevakrien avatar Nov 08 '24 00:11 nevakrien

@nevakrien I'm definitely interested in it, but other things in life have gotten in the way, so I haven't had too much time for personal coding projects.

So, if you are interested in implementing that part there are few things that are needed. The main interfaces that need to be implemented are in ./internal/disasm.

For reference you can see the ./internal/goobj implementation, it roughly involves:

  1. Implement loading all the function symbols from the binary.
  2. Implement disassembling the function itself.
  3. Implement jump offset calculation, from offset or PC to actual target; including the jump layer (it might be possible to share this between backends)
  4. Load sources for the disassembled parts (with some extra context as necessary)

https://github.com/google/pprof already does many of these things and for multiple languages, but in a different form. For example https://github.com/google/pprof/blob/main/internal/binutils/addr2liner.go is a good starting point. For this project the approach would be similar -- hook into clang/gcc tooling to do the disassembly and symbolization.

I currently also have partial WASM support. Search for workInProgressWASM, that shows a hacky way for now to plug in a new disassembler.

egonelbre avatar Nov 08 '24 06:11 egonelbre