19 #include <Poco/NumberParser.h> 20 #include <Poco/DOM/NodeList.h> 21 #include <Poco/DOM/DOMParser.h> 22 #include <Poco/DOM/Document.h> 23 #include <Poco/DOM/Element.h> 24 #include <Poco/DOM/DOMWriter.h> 25 #include <Poco/SAX/InputSource.h> 26 #include <Poco/SAX/SAXException.h> 28 #include <Poco/FileStream.h> 37 const std::string DebugBreakpointManager::BREAKPOINTS_TAG =
"breakpoints";
38 const std::string DebugBreakpointManager::OBJECT_TAG =
"object";
39 const std::string DebugBreakpointManager::SMARTPOINTER_TAG =
"smartpointer";
41 const std::string DebugBreakpointManager::ID_ATTR =
"id";
42 const std::string DebugBreakpointManager::CLASSNAME_ATTR =
"className";
43 const std::string DebugBreakpointManager::OBJECTID_ATTR =
"objectId";
44 const std::string DebugBreakpointManager::ENABLED_ATTR =
"enabled";
50 m_SmartPointerBreakpoints[smartPointerId] = obj;
56 m_ObjectBreakpoints.insert(objectTraceId);
61 m_SmartPointerBreakpoints.erase(smartPointerId);
66 m_ObjectBreakpoints.erase(objectTraceId);
71 return m_ObjectBreakpoints;
76 return m_SmartPointerBreakpoints;
81 return m_ObjectBreakpoints.find(traceId) != m_ObjectBreakpoints.end();
86 return m_SmartPointerBreakpoints.find(spId)
87 != m_SmartPointerBreakpoints.end();
90 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER 93 Poco::XML::Document* doc =
new Poco::XML::Document();
94 Poco::XML::Element* breakpoints = doc->createElement(BREAKPOINTS_TAG);
95 doc->appendChild(breakpoints)->release();
97 for (std::set<unsigned long>::const_iterator i = m_ObjectBreakpoints.begin(); i
98 != m_ObjectBreakpoints.end(); ++i)
100 Poco::XML::Element* objectBreakpoint = doc->createElement(OBJECT_TAG);
101 breakpoints->appendChild(objectBreakpoint)->release();
102 std::stringstream ss;
104 objectBreakpoint->setAttribute(ID_ATTR, ss.str());
109 objectBreakpoint->setAttribute(CLASSNAME_ATTR, obj->
GetClassName().toStdString());
114 for (Poco::HashMap<int, const Object*>::ConstIterator i =
115 m_SmartPointerBreakpoints.begin(); i != m_SmartPointerBreakpoints.end(); ++i)
117 Poco::XML::Element* spBreakpoint = doc->createElement(SMARTPOINTER_TAG);
118 breakpoints->appendChild(spBreakpoint)->release();
119 std::stringstream ss;
121 spBreakpoint->setAttribute(ID_ATTR, ss.str());
123 const Object* obj = i->second;
126 spBreakpoint->setAttribute(CLASSNAME_ATTR, obj->
GetClassName().toStdString());
128 ss << obj->GetTraceId();
129 spBreakpoint->setAttribute(OBJECTID_ATTR, ss.str());
133 Poco::FileOutputStream writer(path.toStdString());
134 Poco::XML::DOMWriter out;
136 out.writeNode(writer, doc);
145 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER 150 Poco::XML::DOMParser parser;
152 Poco::FileInputStream reader(path.toStdString());
153 Poco::XML::InputSource source(reader);
156 Poco::XML::Document* doc = parser.parse(&source);
157 Poco::XML::Element* breakpoints = doc->documentElement();
162 Poco::XML::NodeList* elementList = breakpoints->getElementsByTagName(
164 for (std::size_t i = 0; i < elementList->length(); i++)
166 Poco::XML::Element* elem =
167 dynamic_cast<Poco::XML::Element*
> (elementList->item(i));
169 if (!elem->hasAttribute(ID_ATTR))
172 const std::string& attr = elem->getAttribute(ID_ATTR);
177 traceId = Poco::NumberParser::parse(attr);
178 }
catch (
const Poco::SyntaxException& e)
185 elementList->release();
188 elementList = breakpoints->getElementsByTagName(SMARTPOINTER_TAG);
189 for (std::size_t i = 0; i < elementList->length(); i++)
191 Poco::XML::Element* elem =
192 dynamic_cast<Poco::XML::Element*
> (elementList->item(i));
194 if (!elem->hasAttribute(ID_ATTR))
197 const std::string& attr = elem->getAttribute(ID_ATTR);
202 spId = Poco::NumberParser::parse(attr);
203 }
catch (
const Poco::SyntaxException& e)
210 elementList->release();
214 }
catch (Poco::XML::SAXParseException& e)
218 catch (Poco::FileNotFoundException& )
222 catch (Poco::FileException& e)
void AddSmartpointerBreakpoint(int smartPointerId, const Object *obj=nullptr)
virtual QString GetClassName() const
void RemoveSmartpointerBreakpoint(int smartPointerId)
Light weight base class for most BlueBerry classes.
static const Object * GetObject(unsigned int traceId)
void AddObjectBreakpoint(unsigned long objectTraceId)
void SaveState(const QString &path) const
bool BreakAtSmartpointer(int spId) const
const Poco::HashMap< int, const Object * > & GetSmartPointerBreakpoints() const
static const std::string BREAKPOINTS_XML
void RemoveObjectBreakpoint(unsigned long objectTraceId)
bool BreakAtObject(unsigned long traceId) const
static DebugBreakpointManager * GetBreakpointManager()
const std::set< unsigned long > & GetObjectBreakpoints() const
void RestoreState(const QString &path)