add support for other languages
Technically the core logic needs:
- list of symbols (https://github.com/loov/lensm/blob/d9771339009f7ac9663afc6de248d7f98b63f011/internal/disasm/file.go#L3)
- 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.
Yes please! C++ source isn't loading right now.
@mcourteaux can you provide a minimal repro, it'll be easier to test.
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:

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.
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 if it doesn't work, then my guess was just wrong :).
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 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:
- Implement loading all the function symbols from the binary.
- Implement disassembling the function itself.
- Implement jump offset calculation, from offset or PC to actual target; including the jump layer (it might be possible to share this between backends)
- 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.