6 ms·
Inspector – A drop-anywhere C++ REPL
- seletz 9y agoHmm -- I wonder why they chose to not use Jupyter as an REPL "backend" (Jupyter calls them "kernels").
- seletz 9y agoJust noticed that Inspector seems to be related to cling, and cling has a built-in Jupyter kernel IIUC.
- Mic92 9y agoCling (the underlying just-in-time compiler) supports this. However Cling is more a standalone REPL and has a different execution flow. Here the idea of Inspector is to be executed from within running, compiled programs
- seletz 9y agoThanks -- I wasn't aware that something like cling exists. How does Inspector differentiate itself from embedding cling to an application? It's very interesting to me because I've been trying to get something like an IPython console / IPdb prompt inside Java using Jython for a long time, and I'd very much like to read more about some design decisions in that area.
- Mic92 9y agoTo access local variables, as you can see in the example, Inspector uses libclang ahead of compile-time to generate code that captures all local variables where the REPL is invoked. In JVM you could probably use introspection to achieve the same at run-time. I also gave a brief presentation about the design: https://www.youtube.com/watch?v=Cl5RSlW6xAc https://www.youtube.com/watch?v=Cl5RSlW6xAc
- bfelds 9y agothis exists! recently released: https://github.com/QuantStack/xeus-cling https://github.com/QuantStack/xeus-cling
- seletz 9y agoOh wow! Even a backend for Jupyter's interactive widgets!
- SylvainCorlay 9y agoCheck out our blog post on the C++ backend to Jupyter widgets: https://blog.jupyter.org/interactive-workflows-for-c-with-jupyter-fe9b54227d92 https://blog.jupyter.org/interactive-workflows-for-c-with-ju...
- seletz 9y agoJust reading up on xeus (nice name!) -- very exciting! Do you know it xeus happens to build on Windows 10? I'm thinking about to try to use SWIG to create a JNI wrapper for it.
- bfelds 9y agoit does build on windows. we got it working with windows10 using visual studio 2015 build toolchain
- Dangeranger 9y agoInjecting a REPL into a given section of code is my favorite means of debugging and interactively developing. I've gotten into the habit of building up a class interactively within Emacs and re-evaluating files after they have been changed. It feels a bit like test driven development, but much more concrete. When I don't really know what I want to build, or what is possible, it's a fun way to spike out some functionality. Then after you see what sort of path could exist from your interactive session you can use the code as a scaffold and re-implement the functionality by writing a test and implementing the code to satisfy it.
- zitterbewegung 9y agoEven just knowing the variables in the Stack frame is useful also. The error pages for Django and pyramid have this. Also, at a previous job someone created a toolbar that had all of the relevant server variables in your session.
- majewsky 9y agoAt a previous job, I built a server-side debugging tool which would record the requests that you made. For each request, you could see the HTTP request, the HTTP response, and events like SQL statements and log messages. (Sort of like Sentry.) There was also a button that re-ran the same request under a profiler. Sadly the tool was never merged into mainline, so the feature branch has probaly rotten away by now.
- vog 9y agoShlightly off-topic: Maybe it's just me, but this is exactly why I'm not a fan of feature branches. I do like to have local branches which sometimes serve as feature branches. But those are short-lived, so these either make it into mainline within a few days, or are deliberately marked as dead ends. (Or developed into a separate project, but this is very seldom and even then quickly moved into a new repository.)
- Ono-Sendai 9y agoA decent debugger will show all the local variables and their values.
- jclay 9y agoThis comes at a good time as it's something I've been looking for. We have a physics engine and we want to allow users to write custom c++ functions that can be linked in at run-time. We'd like to allow our users to swap in their own custom integration or timestep methods for example. As an aside, do you know if it is possible to use this to JIT C++ for CUDA kernels?
- Mic92 9y agoYou probably want to use libcling directly instead.
- zokier 9y ago> We have a physics engine and we want to allow users to write custom c++ functions that can be linked in at run-time. We'd like to allow our users to swap in their own custom integration or timestep methods for example. Can't you achieve that with plain old dlopen etc? I suppose name mangling can be bit of pita if you want to have truly c++ interfaces instead of extern c ones.
- lahwran 9y agoAre you imagining this running inside a cuda kernel? If yes, the problem with doing anything of the kind is that, even if you run your kernel with one warp and mask all but one thread, you still then need round trips to the cpu to do io, and you need to dynamically load code, both of which the gpu is quite bad about. If no, it is probably doable if a bit hard to generate kernels on the fly.
- tmearnest 9y ago
- Asooka 9y agoHow is this better than just attaching GDB?
- Mic92 9y ago1. You can enter arbitrarily C++ code (gdb can only call some functions, it cannot even instantiate c++ classes) 2. Variables in Inspector's scope are never optimized away by the compiler 3. You can use it with default optimizations flags (In gdb you often want `-O0 -g`)
- pjmlp 9y agoOn some university projects (to be delivered in C), as part of my edit-compile-debug loop, I was usually writing additional functions just to navigate the data structures using the GDB expression evaluator.
- Asooka 9y ago1. GDB can instantiate classes, but it's a bit wonky, I agree. You have to evaluate malloc manually and then cast the pointer to the right type and call the constructor. You can write python scripts to automate this. 2. That's good. 3. You can generally compile with -Og -g for faster execution while preserving enough of the program's structure to make sense of what's happening. I can see how it can be useful though. Do you have to prebuild every cpp file, or just the one you put "#include INSPECTOR" in? Can you include inspector in more than one file?
- Mic92 9y agoYou only need to prebuild files, where the include statement is included. Ideally this task would be also automatically done in future by sneaking into the build system.
- kyberias 9y agoDo people create stuff like this because they don't have access to good interactive debuggers? Visual Studio user here.
- Mic92 9y agoI tried visual studio once. It does not allow me to include all kinds of code in the edit-and-compile feature. Also the code I enter in a REPL, I usually don't want to see in my projects. Finally I miss the intermediate feedback of printing the values, when I have entered an expression.
- ken 9y agoThis is an interesting question, but the phrasing sounds a little funny to me. Don't REPLs predate symbolic debuggers? As someone coming from the Lisp world, I've occasionally wondered about the converse: did people create interactive debuggers because their language didn't have a good REPL? I've used Visual Studio before, and it's an impressive technical achievement, but for personal productivity, I'll take a good REPL any day -- as long as the language supports it. That said, good REPLs contain a debugger, and good symbolic debuggers contain a REPL, so they're not entirely exclusive.
- therein 9y agoVery interesting. Does it require a C++17 compiler? Also is there any way to simply use a different way of interacting with the REPL? For instance over sockets rather than stdio.
- Mic92 9y agoThe REPL is a C++17 just-in-time compiler as a library. The project can use a different compiler. Even C could be supported with some small modifications. It uses TCP sockets + simple json messages for IPC. The REPL prompt runs in a different process independent from the program running the REPL. That means, there could be different frontends added. It also enables multi-process/multi-threading support.