google / lldb-eval

lldb-eval is a library for evaluating expressions in the debugger context
Apache License 2.0
70 stars 17 forks source link

dumb question: how exactly do you use this? #159

Open makslevental opened 3 years ago

makslevental commented 3 years ago

sorry if this is a dumb question but how exactly do i use lldb-eval in tandem with lldb? I've got it built (which wasn't completely straightforward) but e.g.

(pytorch_dev) [mlevental@devgpu019:lldb-eval (master)]$ LLVM_INSTALL_PATH=/data/users/mlevental/llvm-project/llvm bazel run tools:exec -- "(1 + 2) * 42 / 4"
INFO: Analyzed target //tools:exec (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //tools:exec up-to-date:
  bazel-bin/tools/exec
INFO: Elapsed time: 0.133s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/tools/exec '(1' + '2)' bazel-bin bazel-lldb-eval bazel-out bazel-testlogs BUILD build_defs CONTRIBUTING.md docs LICENSE lldb-eval README.md testdata tools WORKSPACEINFO: Build completed successfully, 1 total action
Can't find the breakpoint location.
(pytorch_dev) [mlevental@devgpu019:lldb-eval (master)]$ 

so it necessitates being run within the context of lldb even for this.

does one need to rebuild lldb,lldb-server linking against liblldb-eval.so or something like that?

werat commented 3 years ago

Hi, thanks for your interest in the project! No dumb questions here :)

I'd be happy to learn more about your use case and help any way I can.

lldb-eval is supposed to be used as a library and it requires lldb to work (it links against liblldb.so|dll). You don't need to rebuild lldb or lldb-server, they don't know anything about lldb-eval.

Typically lldb-eval would be used like this:

tools/exec is a sample application for testing that basically implements the flow described above.

It would be possible to write a dynamic plugin for LLDB for evaluating expressions using lldb-eval, however nobody asked for that yet :)

Which OS are you using? I've tested lldb-eval on Linux (Ubuntu) and Windows, not sure if there are any problems on macos. The command in your example should work, however it says "Can't find the breakpoint location", which suggests something fails very early in the process (link).

I've got it built (which wasn't completely straightforward)

Can you elaborate which steps were problematic? I can imagine building LLDB from scratch can be challenging, but would like to know about other difficulties as well.

tonkosi commented 3 years ago

Hi, in this particular example the issue could be the way your shell processes arguments.

tools/exec should only take a single argument "(1 + 2) * 42 / 4", however, your shell interprets this as a list of arguments (1, +, 2), followed by the content of working dir (multiplication operator * treated as expansion operation).

Maybe your shell passes multi-word arguments in a different way or there are multiple levels of escaping somehow? E.g. what happens if you try to pass the argument as '(1 + 2) * 42 / 4' or "\"(1 + 2) * 42 / 4\""?