23 #include <Poco/NumberParser.h>
24 #include <Poco/DOM/NodeList.h>
25 #include <Poco/DOM/DOMParser.h>
26 #include <Poco/DOM/Document.h>
27 #include <Poco/DOM/Element.h>
28 #include <Poco/DOM/DOMWriter.h>
29 #include <Poco/SAX/InputSource.h>
30 #include <Poco/SAX/SAXException.h>
32 #include <Poco/FileStream.h>
41 const std::string DebugBreakpointManager::BREAKPOINTS_TAG =
"breakpoints";
42 const std::string DebugBreakpointManager::OBJECT_TAG =
"object";
43 const std::string DebugBreakpointManager::SMARTPOINTER_TAG =
"smartpointer";
45 const std::string DebugBreakpointManager::ID_ATTR =
"id";
46 const std::string DebugBreakpointManager::CLASSNAME_ATTR =
"className";
47 const std::string DebugBreakpointManager::OBJECTID_ATTR =
"objectId";
48 const std::string DebugBreakpointManager::ENABLED_ATTR =
"enabled";
54 m_SmartPointerBreakpoints[smartPointerId] = obj;
60 m_ObjectBreakpoints.insert(objectTraceId);
65 m_SmartPointerBreakpoints.erase(smartPointerId);
70 m_ObjectBreakpoints.erase(objectTraceId);
75 return m_ObjectBreakpoints;
80 return m_SmartPointerBreakpoints;
85 return m_ObjectBreakpoints.find(traceId) != m_ObjectBreakpoints.end();
90 return m_SmartPointerBreakpoints.find(spId)
91 != m_SmartPointerBreakpoints.end();
94 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER
97 Poco::XML::Document* doc =
new Poco::XML::Document();
98 Poco::XML::Element* breakpoints = doc->createElement(BREAKPOINTS_TAG);
99 doc->appendChild(breakpoints)->release();
101 for (std::set<unsigned long>::const_iterator i = m_ObjectBreakpoints.begin(); i
102 != m_ObjectBreakpoints.end(); ++i)
104 Poco::XML::Element* objectBreakpoint = doc->createElement(OBJECT_TAG);
105 breakpoints->appendChild(objectBreakpoint)->release();
106 std::stringstream ss;
108 objectBreakpoint->setAttribute(ID_ATTR, ss.str());
113 objectBreakpoint->setAttribute(CLASSNAME_ATTR, obj->
GetClassName().toStdString());
118 for (Poco::HashMap<int, const Object*>::ConstIterator i =
119 m_SmartPointerBreakpoints.begin(); i != m_SmartPointerBreakpoints.end(); ++i)
121 Poco::XML::Element* spBreakpoint = doc->createElement(SMARTPOINTER_TAG);
122 breakpoints->appendChild(spBreakpoint)->release();
123 std::stringstream ss;
125 spBreakpoint->setAttribute(ID_ATTR, ss.str());
127 const Object* obj = i->second;
130 spBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName().toStdString());
132 ss << obj->GetTraceId();
133 spBreakpoint->setAttribute(OBJECTID_ATTR, ss.str());
137 Poco::FileOutputStream writer(path.toStdString());
138 Poco::XML::DOMWriter out;
140 out.writeNode(writer, doc);
149 #ifdef BLUEBERRY_DEBUG_SMARTPOINTER
154 Poco::XML::DOMParser parser;
156 Poco::FileInputStream reader(path.toStdString());
157 Poco::XML::InputSource source(reader);
160 Poco::XML::Document* doc = parser.parse(&source);
161 Poco::XML::Element* breakpoints = doc->documentElement();
166 Poco::XML::NodeList* elementList = breakpoints->getElementsByTagName(
168 for (std::size_t i = 0; i < elementList->length(); i++)
170 Poco::XML::Element* elem =
171 dynamic_cast<Poco::XML::Element*
> (elementList->item(i));
173 if (!elem->hasAttribute(ID_ATTR))
176 const std::string& attr = elem->getAttribute(ID_ATTR);
181 traceId = Poco::NumberParser::parse(attr);
182 }
catch (
const Poco::SyntaxException& e)
189 elementList->release();
192 elementList = breakpoints->getElementsByTagName(SMARTPOINTER_TAG);
193 for (std::size_t i = 0; i < elementList->length(); i++)
195 Poco::XML::Element* elem =
196 dynamic_cast<Poco::XML::Element*
> (elementList->item(i));
198 if (!elem->hasAttribute(ID_ATTR))
201 const std::string& attr = elem->getAttribute(ID_ATTR);
206 spId = Poco::NumberParser::parse(attr);
207 }
catch (
const Poco::SyntaxException& e)
214 elementList->release();
218 }
catch (Poco::XML::SAXParseException& e)
222 catch (Poco::FileNotFoundException& )
226 catch (Poco::FileException& e)
void AddSmartpointerBreakpoint(int smartPointerId, const Object *obj=nullptr)
bool BreakAtObject(unsigned long traceId) const
void RemoveSmartpointerBreakpoint(int smartPointerId)
Light weight base class for most BlueBerry classes.
const Poco::HashMap< int, const Object * > & GetSmartPointerBreakpoints() const
static const Object * GetObject(unsigned int traceId)
void AddObjectBreakpoint(unsigned long objectTraceId)
bool BreakAtSmartpointer(int spId) const
virtual QString GetClassName() const
static const std::string BREAKPOINTS_XML
void RemoveObjectBreakpoint(unsigned long objectTraceId)
void SaveState(const QString &path) const
static DebugBreakpointManager * GetBreakpointManager()
const std::set< unsigned long > & GetObjectBreakpoints() const
void RestoreState(const QString &path)