Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a hexadecimal watch in CLion?

I need to add a watch in hexadecimal format in CLion.

ltoa(variable, 16) doesn't work, at least, on my system.

In Java/Python, I can have a workaround: write a custom toString()/__str__ for my class and have it displayed the way I need. gdb has p/x. How do I do it in CLion?

Edit: ltoa(variable, 16) works if I define ltoa in my code, as it's not always present in standard library.

like image 345
Victor Sergienko Avatar asked Dec 12 '16 19:12

Victor Sergienko


2 Answers

set output-radix 16

You can set this as a default option in a file called .gdbinit, which you can put in your home directory, or the working directory from which you start GDB (project root, for instance).

like image 141
Jimadilo Avatar answered Nov 05 '22 13:11

Jimadilo


They added hex view as an experimental feature: Hexadecimal view

To enable:

  1. Invoke the Maintenance popup: press Ctrl+Alt+Shift+/, or call Help | Find Action and search for Maintenance. Choose Experimental features.
  2. Select the cidr.debugger.value.numberFormatting.hex checkbox
  3. Go to Settings / Preferences | Build, Execution, Deployment | Debugger | Data Views | C/C++ and set the checkbox Show hex values for numbers. Choose to have hexadecimal values displayed instead or alongside the original values.

Now the hexadecimal formatting is shown both in the Variables pane of the Debug tool window and in the editor's inline variables view.

like image 36
robsn Avatar answered Nov 05 '22 13:11

robsn