Ryan
Ryan

Reputation: 3619

Netbeans print debug value C / C++

I am interested in displaying a struct / class object in a specific way using Netbean's default GDB debugger for C and C++ projects so I can step through the code quicker. For Java there is an easy way to do this using the "Variable Formatters" section under Tools -> Options -> Misc -> Variable Formatters. I am looking for something similar for C / C++. Does this method exist?

EDIT: To clarify my question, in the debugger variables tag there is a "Value" column. I wish to represent this as a call from an object, for example printf("%s", MyObject.getHeight());

Upvotes: 0

Views: 1035

Answers (2)

user2785987
user2785987

Reputation: 21

I believe what you're looking for can be accomplished using the Python pretty printing feature of gdb, as explained at the following:

https://sourceware.org/gdb/current/onlinedocs/gdb/Pretty-Printing.html#Pretty-Printing https://sourceware.org/gdb/current/onlinedocs/gdb/Pretty-Printing-API.html#Pretty-Printing-API

Using the Python pretty printing mechanism, you can control how gdb will present the value of a given type to NetBeans. I've used this myself to customize the display, in the Variables tab, for my own classes. It takes a bit of reading and a tiny bit of Python knowledge, but it's wonderfully powerful once you get the hang of it, and definitely worth learning.

Upvotes: 2

Sepp
Sepp

Reputation: 16

I don't know Netbeans enough to help you with a macro to do that but there is an easier solution, either:

  • let the debugger access a variable (made 'public' instead of private in your C++ class)

or

  • add this code in your program: int height = MyObject.getHeight(); so you can display the variable in the debugger.

Things are usually done by simplifying a problem.

Upvotes: 0

Related Questions