Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for other languages #6

Open
egonelbre opened this issue Jul 16, 2022 · 8 comments
Open

add support for other languages #6

egonelbre opened this issue Jul 16, 2022 · 8 comments

Comments

@egonelbre
Copy link
Member

egonelbre commented Jul 16, 2022

Technically the core logic needs:

  1. list of symbols (
    // File represents an object file, a module or anything that contains functions.
    )
  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.

@mcourteaux
Copy link

mcourteaux commented Dec 23, 2022

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

@egonelbre
Copy link
Member Author

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

@mcourteaux
Copy link

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

@egonelbre
Copy link
Member Author

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.

@mcourteaux
Copy link

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. 😄

@egonelbre
Copy link
Member Author

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

@nevakrien
Copy link

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?

@egonelbre
Copy link
Member Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants