Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view the contents of a map in codeblocks while debugging?

I am using Codeblocks for my C++ programs. How do I view the contents of a map while debugging.

My map is defined as follows -

map< int , int > myMap;

I enter data as follows -

myMap[1]=5;

I see the following in my watches window while debugging after the above 2 lines have been executed.
Watches Window Image

Why don't I see map[1]=5 ? And how do I do that.

Sorry, I'm new to c++, coming from python on visual studio code, I never had any problems like this.

I'm using 8.1.0 gcc and 8.1 gdb. I am getting the following on runnning print myMap

{_M_t = {_M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<int const, int> > >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<int const, int> > >> = {<No data fields>}, <No data fields>}, <std::_Rb_tree_key_compare<std::less<int> >> = {_M_key_compare = {<std::binary_function<int, int, bool>> = {<No data fields>}, <No data fields>}}, <std::_Rb_tree_header> = {_M_header = {_M_color = std::_S_red, _M_parent = 0x3e3720, _M_left = 0x3e3720, _M_right = 0x3e3720}, _M_node_count = 1}, <No data fields>}}}
like image 574
SmarthBansal Avatar asked Nov 22 '25 06:11

SmarthBansal


1 Answers

Please search for gdbinit in the MinGW directory.

Debugger setting --> default --> Initialization command

source $(TARGET_COMPILER_DIR)etc\gdbinit

enter image description here

like image 166
Nederxus Avatar answered Nov 23 '25 19:11

Nederxus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!