void DebugBreakpointManager::SaveState(const Poco::Path& path) const { Poco::XML::Document* doc = new Poco::XML::Document(); Poco::XML::Element* breakpoints = doc->createElement(BREAKPOINTS_TAG); doc->appendChild(breakpoints)->release(); for (std::set<unsigned long>::const_iterator i = m_ObjectBreakpoints.begin(); i != m_ObjectBreakpoints.end(); ++i) { Poco::XML::Element* objectBreakpoint = doc->createElement(OBJECT_TAG); breakpoints->appendChild(objectBreakpoint)->release(); std::stringstream ss; ss << *i; objectBreakpoint->setAttribute(ID_ATTR, ss.str()); const Object* obj = DebugUtil::GetObject(*i); if (obj) { objectBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName()); } } for (Poco::HashMap<int, const Object*>::ConstIterator i = m_SmartPointerBreakpoints.begin(); i != m_SmartPointerBreakpoints.end(); ++i) { Poco::XML::Element* spBreakpoint = doc->createElement(SMARTPOINTER_TAG); breakpoints->appendChild(spBreakpoint)->release(); std::stringstream ss; ss << i->first; spBreakpoint->setAttribute(ID_ATTR, ss.str()); const Object* obj = i->second; if (i->second) { spBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName()); ss.clear(); ss << obj->GetTraceId(); spBreakpoint->setAttribute(OBJECTID_ATTR, ss.str()); } } Poco::FileOutputStream writer(path.toString()); Poco::XML::DOMWriter out; out.setOptions(3); //write declaration and pretty print out.writeNode(writer, doc); doc->release(); }
void DebugUtil::SaveState() { Poco::Path path; if (!GetPersistencePath(path)) return; path.setFileName(DEBUG_UTIL_XML); Poco::XML::Document* doc = new Poco::XML::Document(); Poco::XML::Element* debugutil = doc->createElement(DEBUGUTIL_TAG); doc->appendChild(debugutil)->release(); for (std::set<unsigned int>::const_iterator i = m_TracedObjects.begin(); i != m_TracedObjects.end(); ++i) { Poco::XML::Element* traceObject = doc->createElement(TRACEOBJECT_TAG); debugutil->appendChild(traceObject)->release(); std::stringstream ss; ss << *i; traceObject->setAttribute(ID_ATTR, ss.str()); } for (std::set<std::string>::const_iterator i = m_TracedClasses.begin(); i != m_TracedClasses.end(); ++i) { Poco::XML::Element* traceClass = doc->createElement(TRACECLASS_TAG); debugutil->appendChild(traceClass)->release(); traceClass->setAttribute(NAME_ATTR, *i); } try { Poco::FileOutputStream writer(path.toString()); Poco::XML::DOMWriter out; out.setOptions(3); //write declaration and pretty print out.writeNode(writer, doc); doc->release(); // save BreakpointManager path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML); GetBreakpointManager()->SaveState(path); } catch (Poco::FileException& e) { BERRY_WARN << e.displayText(); } }
void DebugBreakpointManager::RestoreState(const Poco::Path& path) { try { Poco::XML::DOMParser parser; Poco::FileInputStream reader(path.toString()); Poco::XML::InputSource source(reader); //source.setSystemId(baseDir); Poco::XML::Document* doc = parser.parse(&source); Poco::XML::Element* breakpoints = doc->documentElement(); if (breakpoints) { // restore object breakpoints Poco::XML::NodeList* elementList = breakpoints->getElementsByTagName( OBJECT_TAG); for (std::size_t i = 0; i < elementList->length(); i++) { Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (elementList->item(i)); if (!elem->hasAttribute(ID_ATTR)) continue; const std::string& attr = elem->getAttribute(ID_ATTR); int traceId = 0; try { traceId = Poco::NumberParser::parse(attr); } catch (const Poco::SyntaxException& e) { BERRY_WARN << e.displayText(); } DebugUtil::GetBreakpointManager()->AddObjectBreakpoint(traceId); } elementList->release(); // restore smartpointer breakpoints elementList = breakpoints->getElementsByTagName(SMARTPOINTER_TAG); for (std::size_t i = 0; i < elementList->length(); i++) { Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (elementList->item(i)); if (!elem->hasAttribute(ID_ATTR)) continue; const std::string& attr = elem->getAttribute(ID_ATTR); int spId = 0; try { spId = Poco::NumberParser::parse(attr); } catch (const Poco::SyntaxException& e) { BERRY_WARN << e.displayText(); } DebugUtil::GetBreakpointManager()->AddSmartpointerBreakpoint(spId); } elementList->release(); } doc->release(); } catch (Poco::XML::SAXParseException& e) { BERRY_WARN << e.displayText(); } catch (Poco::FileNotFoundException& /*e*/) { } catch (Poco::FileException& e) { BERRY_WARN << e.displayText(); } }
void DebugUtil::RestoreState() { Poco::Path path; if (!GetPersistencePath(path)) return; path.setFileName(DEBUG_UTIL_XML); try { Poco::XML::DOMParser parser; Poco::FileInputStream reader(path.toString()); Poco::XML::InputSource source(reader); //source.setSystemId(baseDir); Poco::XML::Document* doc = parser.parse(&source); Poco::XML::Element* debugutil = doc->documentElement(); if (debugutil) { // restore traced objects Poco::XML::NodeList* elementList = debugutil->getElementsByTagName(TRACEOBJECT_TAG); for (std::size_t i = 0; i < elementList->length(); i++) { Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i))); if (!elem->hasAttribute(ID_ATTR)) continue; const std::string& attr = elem->getAttribute(ID_ATTR); int traceId = 0; try { traceId = Poco::NumberParser::parse(attr); } catch (const Poco::SyntaxException& e) { BERRY_WARN << e.displayText(); } DebugUtil::TraceObject(traceId); } elementList->release(); // restore traced classes elementList = debugutil->getElementsByTagName(TRACECLASS_TAG); for (std::size_t i = 0; i < elementList->length(); i++) { Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i))); if (!elem->hasAttribute(NAME_ATTR)) continue; const std::string& traceClass = elem->getAttribute(NAME_ATTR); if (!traceClass.empty()) DebugUtil::TraceClass(traceClass); } elementList->release(); } doc->release(); } catch (Poco::XML::SAXParseException& e) { BERRY_WARN << e.displayText(); } catch (Poco::FileNotFoundException&) { } catch (Poco::FileException& e) { BERRY_WARN << e.displayText(); } // restore BreakpointManager path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML); GetBreakpointManager()->RestoreState(path); }