On Wed, Aug 28, 2013 at 11:25 AM, Enrico Granata <[email protected]> wrote:
> 2. For std::vector, GetNumChildren() returns -1 (with preference for
> synthetic)! However, reading children using GetChildAtIndex() etc.
> still succeeds.
>
>
> Interesting. Test case?
See attached files for debugger and debugee programs.
The output of debugger is always:
count = -1
val = 11
val = 12
val = 13
This is when both debugger and debugee are built either with clang or gcc.
#include <vector>
int main()
{
std::vector<int> foo {11,12,13};
return 0;
}
#include <iostream>
#include <string>
#include <lldb/API/LLDB.h>
using namespace lldb;
using namespace std;
const int BREAKPOINT_LINE = 5;
bool breakpoint_callback (void *baton, SBProcess &process, SBThread &thread, SBBreakpointLocation &location);
int main(int argc, char *argv[])
{
SBDebugger::Initialize();
SBError error;
SBDebugger debugger = SBDebugger::Create(false);
if (!debugger.IsValid())
{
cerr << "Error creating debugger." << endl;
return 1;
}
SBTarget target ( debugger.CreateTarget("./debugee", "", "", true, error) );
if (!error.Success())
{
cerr << "Error creating target: " << error.GetCString() << endl;
return 1;
}
if (!target.IsValid())
{
cerr << "Error: target invalid." << endl;
return 1;
}
SBBreakpoint bp;
bp = target.BreakpointCreateByLocation("debugee.cpp", BREAKPOINT_LINE);
bp.SetCallback( breakpoint_callback, nullptr );
SBProcess process = target.LaunchSimple(nullptr, nullptr, nullptr);
if (!process.IsValid())
{
cerr << "Error: Invalid process." << endl;
return 1;
}
SBListener listener = debugger.GetListener();
assert(listener.IsValid());
bool running = true;
while (running)
{
SBEvent event;
bool ok = listener.WaitForEvent(UINT32_MAX, event);
if (!ok || !event.IsValid())
continue;
const uint32_t event_type = event.GetType();
if (SBProcess::EventIsProcessEvent (event))
{
if (event_type & SBProcess::eBroadcastBitStateChanged)
{
StateType event_state = SBProcess::GetStateFromEvent (event);
switch (event_state)
{
case eStateExited:
case eStateCrashed:
running = false;
break;
default:
break;
}
}
}
}
return 0;
}
bool breakpoint_callback (void *baton, SBProcess &process, SBThread &thread, SBBreakpointLocation &location)
{
SBError error;
SBFrame frame( thread.GetSelectedFrame() );
assert(frame.IsValid());
{
SBValue foo_value = frame.FindVariable("foo");
foo_value.SetPreferSyntheticValue(true);
int count = foo_value.GetNumChildren();
cout << "count = " << count << endl;
count = 3;
for (int i = 0; i < count; ++i)
{
SBError error;
int x = 0;
SBValue child = foo_value.GetChildAtIndex(i, eNoDynamicValues, false);
if (child.IsValid())
{
x = child.GetValueAsSigned();
}
cout << "val = " << x << endl;
}
}
return false;
}
_______________________________________________
lldb-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev