Implement custom operators with GDB python API - gdb

As an example lets say I have a linked list implemented in C. Can I use the GDB python API to implement a custom array access operator so that I can get a value from the list like myList[0] while debugging?
Have tried reading through the docs but could find nothing on it

Related

How to create Apache Arrow vectors in Java, pass them to C++ code through JNI, read/write them in C++

I've been reading the Apache Arrow docs, and I've figured out how to use it in Java and C++. But what I'd like to do is offload some work to JNI (C/C++) code from Java, and the documentation (e.g. https://arrow.apache.org/docs/java/cdata.html) just doesn't seem to cover my use cases, and methods in the example (e.g. getMemoryAddress on IntVector) just don't seem to exist like they do in the examples. I want to start simple, so here's what I'd like to do:
Allocate two Arrow IntVector's in Java and fill them with data
Allocate space for another IntVector in Java for the result
Get whatever native pointers I need from those vectors and pass them through a JNI call
Wrap those vectors in C++ so I can access them.
Do whatever work I want to offload and finalize the result vector
Return to Java and have the result accessible.
Can anyone point me to an example or some tips on how to do this?
BTW, the examples also use JavaCPP instead of JNI. But I already have a bunch of JNI code in this project, and I'd rather not mix in another kind of bridge if it's not necessary.
Thanks.
I tried allocating IntVector objects in Java, but I can't tell which naive pointers I have to retrieve to pass to C++ to provide proper access to those vectors.
JavaCPP is merely a convenience for the example, JNI is fine.
The C Data Interface is still what you want. When you say "get whatever native pointers I need": that is exactly what a struct ArrowArray is in the C Data Interface. Use the C Data Interface module in Java to export your Java arrays and get the address of a struct ArrowArray, and then pass that address to your C++ code via JNI. Then, use libarrow's C Data Interface implementation to import the arrays and work with them.
When the C++ side is done, it does the same thing: it exports the result vector and returns an address to Java via JNI; the Java code then imports the vector from that address.

Equivalent of "description" for a C++ class in Objective-C++?

I want to be able to debug objective-c++ code which contains instances of a c++ class quickly.
With objective-c classes, I can simply implement description to return a human readable string, and then when I po var in lldb I immediately know anything I need to know about the instance.
Is there any way I can achieve this for c++ classes used from objective-c++ code as well?
The easiest way to do this in lldb is to add a "summary formatter" for the C++ class. This web page gives a pretty good intro to how to do this:
http://lldb.llvm.org/varformats.html
Look for the section on "Type Summaries".
If the class's ivar values directly contain all you want to see about the class, then you can cons up a summary string that will present the ivar values and any markup text you think desirable without having to use the LLDB Python API's to take apart the class. If you need to do more work to produce your summary, you will have to use the Python API's as trojanfoe suggests.
For instance, if you wrote a "description" method for your C++ class, you could use LLDB's Python API's to call that method and return the string as the summary. But if possible, it is preferable to produce the summary from static knowledge of the class, since running code in the debugger is generally slower than inspecting memory.
There is also information on how to use the LLDB Python interface to produce summaries on the same page.
The Type Summaries you write can be added in your .lldbinit file, and the summary values will show up when you print an instance of the class in lldb, and also in the summary column in the Locals view in Xcode.
Note, you can do this for any type, C, C++ or ObjC. Many of the C++ STL classes and the more common Foundation classes have built-in summaries that use the same mechanism. That, and not the description method, is how lldb produces the one-line summaries you see in Xcode.

Documenting fake classes

I have a function which exposes all of my required C++ functions to Lua, there are various tables representing different aspects of my "Scripting API", what I wish to do is use doxygen to make a scripting reference using the C++ code that exposes these script functions.
I have tried to make 'fake' classes in the body of the function, which successfully makes a new entry with the name I have given it, for instance if I make a table named 'Math' which has several functions exposed on it, how would I also make 'fake' member functions in this 'fake' class, I have tried to simply pass in \fn defining the function, however it does not show up as they are not actually real members to add a description to. How would I create this sort of effect in doxygen without hand righting a verbatim definition of every class, but instead treat the comment block as if it were a real class with real members?
It sounds like you're trying to document Lua code as if they were C++. Maybe it's possible, but it's probably more trouble than it's worth.
If you're trying to document Lua code with doxygen, maybe you could try doxygen-lua.
If your Lua API is small, you could just write a page by hand, with \ref's to the relavent C++ code. (Kind of hacky, but I've done this before.)
You could also consider using some other doc generator for your Lua API, such as LuaDoc, or anything else listed on the lua-users wiki DocumentingLuaCode.
I ended up writing a fake .doxy file which had typenames similar to lua values, apparently doxygen will document any type to throw at it.

how to see values of a map in gdb?

I have wrapper classes for all STL containers. And I want to see values contained in one of the map while debugging my code base on gdb. I already have .gdbinit with all stl-views. And currently my gdb is recognizing all stl commands like pmap, pvector etc. but when I provide my wrapper map (or any other container) object as an argument to stl commands I am getting following error.
(gdb) pmap wrapperMapObj
Invalid type combination in equality test.
How can I see values in wrapper objects?
I already have .gdbinit with all stl-views
STL-views are so last century. If you are using GDB-7.x, the new python pretty printers will likely provide much better user experience.
but when I provide my wrapper map
Since you haven't explained what your "wrapper map" is, how could we possibly answer your question about it?

Instantiating shared_ptr's in boost::python

I had a question about boost python. I've been working on exporting some functionality of a project into boost python, and I haven't found a way to solve the following problem:
I have a set of StatusEffect objects that i store and use throughout the game. At the game startup, I want to be able to call a python script that will populate/add to the set of status effect objects. I'm having no problems exposing the StatusEffect class and it's derived class to python and calling the script.
The problem is that I'm storing that StatusEffect objects in an std::vector<boost::shared_ptr<StatusEffect> > Effects;
I have no idea how to create new instances of boost::shared_ptr<StatusEffect> aside from the method of adding a static create method as described here http://wiki.python.org/moin/boost.python/PointersAndSmartPointers Given the large number of constructors and the wide variety of derived classes I have, this seems an unoptimal solution at best. I'd like to be able to create instances of boost::shared_ptr directly using the constructors of the StatusEffect objects, and be able to add those to the vector. Is this possible?
An answer or some helpful suggestions would be helpful. I asked a simialr question yesterday but unfortunately it wasn't of much help.
Thanks in advance
I hope I am understanding your question. If you declare your python class with the shared_ptr as shown at http://wiki.python.org/moin/boost.python/PointersAndSmartPointers, then boost::python will automatically convert StatusEffect objects you create in python to shared_ptr<StatusEffect> if necessary (you can try this e.g. by .def-ing a function which takes const shared_ptr<StatusEffect>& or shared_ptr<StatusEffect> as argument, and call it with StatusEffect instance created in python.
If you want to assign an attribute of type vector<shared_ptr<StatusEffect> >, you must create converters for it (from python sequences, and back), that's described in documentation. For an example, see c++ to python converter template (line 120), python to c++ template (line 127), and then using it for various types (including shared_ptr's) contained in the sequences (line 212).
Then you can write something like yourObject.listOfStatusEffects=[StatusEffect(),StatusEffect(),StatusEffect()]