Cannot access STL C++ container values with GDB - c++

I am debugging C++ code and I have problems when trying to access to an std::list.
The problem is that I cannot get the address associated to the head node ($3 refers to the list):
p $3._M_impl._M_node
$21 = {
_M_next = 0x240ee70,
_M_prev = 0x240ee70
}
I get the following error message when I try to get the head node address:
(gdb) p &($3._M_impl._M_node)
Attempt to take address of value not located in memory.
I also have tried with the STL extension available from the Internet and it also fails at the same point.
set $head = &$arg0._M_impl._M_node
I have looked at Google an this is all I can find about the problem:
http://permalink.gmane.org/gmane.comp.gdb.devel/9496
But it doesn't solve my problem. Any suggestions are more than welcomed.
Thanks in advance

Related

ROOT - pyroot: Branch seen as leaf, can't access actual leaves

I am trying to extract information from a root file using pyroot.
I tried using the usual GetBranch, GetLeaf, GetValue but it does not work as usual, so I tried alternatives.
I found an equivalent code in c++ which is extracting the values just fine from my ROOT file but when applying the same thing in pyroot, I get an empty object as my "mcinfo" (see below).
I also tried displaying the branches and leaves with GetListOfBranches() and GetListOfLeaves(). I get the proper list of branches with the first but when looking at the list of leaves (here MC but it's the same with all branches), I get out of MC.GetListOfLeaves() that the only leaf is MC too... I have several leaves (for instance energy) that I can access just fine with the c++ code and directly with data.Scan("energy") too...
Anyone has an idea of how to fix this? Sorry, I am not that familiar with ROOT yet. I assume it is a rather easy fix, but I don't see what is wrong with this...
C++ code:
TFile *file = new TFile(fname);
TTree *data = (TTree*)file->Get("data");
TBranch * McinfoBranch;
MCInfo* mcinfo = (MCInfo*)file->GetList()->FindObject("MC");
data->SetBranchAddress("MC", &mcinfo, &McinfoBranch);
pyroot version:
infile = ROOT.TFile(fname)
data = infile.Get("data")
mcinfo = infile.GetList().FindObject("MC")
which gives me this when printing mcinfo: <cppyy.gbl.TObject object at 0x(nil)>.

Gdb printing std::map elements

I have a std::map data member inside a class called ExecState:
class ExecState { // ...
std::map<int,ref<Expr> > ab_size;
// ...
};
When I print it from gdb I see the expected values:
(gdb) print state.ab_size
$1 = std::map with 1 elements = {[1] = {ptr = 0x2a221d0}}
However, when I try to access the element itself, gdb fails:
(gdb) print state.ab_size[1]
Attempt to take address of value not located in memory.
What am I doing wrong here? thanks!
When I print it from gdb I see the expected values:
You see this because of the magic of pretty-printers. To see the actual contents of the variable, try print/r state.ab_size.
However, when I try to access the element itself, gdb fails:
GDB didn't fail, but the pretty printers aren't magical enough to grant your wish. You'll have to "fish out" the value by using the actual data elements, not the illusion that pretty printers create (and this is hard).

SFML getFullscreenModes

Have you ever run into issue where function in SFML 2 to get availiable modes returns you:
availiableVideoModes [3]({width=3131961357 height=3131961357 bitsPerPixel=3131961357 },{width=3131961357 height=3131961357 bitsPerPixel=3131961357 },{width=3131961357 height=3131961357 bitsPerPixel=3131961357 }) std::vector >
max int values in vector? Interesting is why 3? I tried quick debugging without luck so in parallel I thought to raise question here.
code:
std::vector<sf::VideoMode> availiableVideoModes;
availiableVideoModes = sf::VideoMode::getFullscreenModes();
interesting is that
desktopVideoMode = sf::VideoMode::getDesktopMode();
returns correct value.
The issue was in libraries link, I have linked 32bits one instead of 64bits.

Boost Shared Memory Map reattach

My Issue is the following:
Why can my program not re-attach to the shared memory map?
I do the following in my program(it might be easier to use the example from the boost page for you while this is only a small fragment from my program):
First time, initialize it:
m_sharedMemory = new managed_shared_memory(create_only, segmentName.c_str() , 1000000);
m_hashMap = m_sharedMemory->construct<MyHashMap>(segmentName.c_str())( 3, boost::hash<std::string>(), std::equal_to<std::string>() , m_sharedMemory->get_allocator<ValueType>());
Second time "Re-Attach"
m_sharedMemory = new managed_shared_memory(open_only, segmentName.c_str());
m_hashMap = m_sharedMemory->find<MyHashMap>(segmentName.c_str()).first;
My Issue here is ,if 2 items get inserted the .second call on the returned object from find will show "1" which is actually wrong, its supposed to show 2, after this if my program tries to find anything in the stored map the program crashes. Has somebody been doing this already.
If i do the same thing in the initial program run it is no problem to lookup values from the hash. This only occurs if the program was initialized and later the program is restarted and does the attach and tries to retrieve values formerly inserted.
Thanks for the help.
Boost Quick Ref Map Example
While i was talking to the "maker" of this library he told me that it will only be possible to use the map within the same process.

binary tree doesn't rebuild from file

I'm new on data structures and we were assigned to make a guessing game using binary tree implementation. I have accomplished the program flow without file implementation. I have saved the binary tree preorderly on an external file now I have problem in rebuilding tree from file
in my file I have:
Is it Angel Locsin?:#Neneng B?Is it Sam Pinto? ##White Beauty?Is it
Marian Rivera? ##HotandSexy?Is it Cristine Reyes? ###
The "#" is for a NULL node.
I have also my code. I follow the algorithm of what my professor gave me. I searched on the internet and gave me same algorithm as of what my prof said. My problem is on every third non-null data the program crashes. I think the main reason of crashing is a node that was not set to null after the third non-null data is inserted. If so, how could I set it to NULL so that my program will not crash.I assigned the data from file into array of strings and set a "\0" at the last index of array.
void read(node *temp)
{
while(array[j]=="#")
j++;
if(array[j]=="\0")
return;
node *nNode;
nNode = new node;
nNode->yes=NULL;
nNode->no=NULL;
nNode->data=array[j];
j++;
temp=nNode;
read(temp->yes);
read(temp->no);
}
Your problem is in the definition of your read function. I guess the idea is that "temp" is an output parameter of type "node*". But this is not what you have written.
You need to have a pointer or a reference to the "node*" parameter like e.g. so:
void read(node** temp)
Then adjust the rest of the code such that is compiles by proper (de)referencing. This should solve your crash.