| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-03-05 11:25:49 +01:00
										 |  |  | ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Licensees holding valid Qt Commercial licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the Qt Commercial License Agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
					
						
							|  |  |  | ** packaging of this file.  Please review the following information to | 
					
						
							|  |  |  | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
					
						
							|  |  |  | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you are unsure which license is appropriate for your use, please | 
					
						
							|  |  |  | ** contact the sales department at http://qt.nokia.com/contact.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "attachgdbadapter.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "gdbengine.h"
 | 
					
						
							|  |  |  | #include "procinterrupt.h"
 | 
					
						
							| 
									
										
										
										
											2009-09-25 15:02:16 +02:00
										 |  |  | #include "debuggerstringutils.h"
 | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <utils/qtcassert.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Debugger { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define CB(callback) \
 | 
					
						
							|  |  |  |     static_cast<GdbEngine::AdapterCallback>(&AttachGdbAdapter::callback), \ | 
					
						
							|  |  |  |     STRINGIFY(callback) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // AttachGdbAdapter
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttachGdbAdapter::AttachGdbAdapter(GdbEngine *engine, QObject *parent) | 
					
						
							|  |  |  |     : AbstractGdbAdapter(engine, parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AttachGdbAdapter::startAdapter() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-25 08:35:31 +02:00
										 |  |  |     QTC_ASSERT(state() == EngineStarting, qDebug() << state()); | 
					
						
							| 
									
										
										
										
											2010-06-14 18:19:02 +02:00
										 |  |  |     showMessage(_("TRYING TO START ADAPTER")); | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-20 11:02:16 +02:00
										 |  |  |     if (!m_engine->startGdb()) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 12:41:26 +02:00
										 |  |  |     m_engine->handleAdapterStarted(); | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-29 17:12:35 +02:00
										 |  |  | void AttachGdbAdapter::startInferior() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); | 
					
						
							| 
									
										
										
										
											2009-09-24 11:16:00 +02:00
										 |  |  |     const qint64 pid = startParameters().attachPID; | 
					
						
							| 
									
										
										
										
											2010-01-05 16:51:55 +01:00
										 |  |  |     m_engine->postCommand("attach " + QByteArray::number(pid), CB(handleAttach)); | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  |     // Task 254674 does not want to remove them
 | 
					
						
							|  |  |  |     //qq->breakHandler()->removeAllBreakpoints();
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-24 11:16:00 +02:00
										 |  |  | void AttachGdbAdapter::handleAttach(const GdbResponse &response) | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-30 17:40:29 +01:00
										 |  |  |     QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  |     if (response.resultClass == GdbResultDone) { | 
					
						
							| 
									
										
										
										
											2009-10-30 17:40:29 +01:00
										 |  |  |         setState(InferiorStopped); | 
					
						
							| 
									
										
										
										
											2010-06-14 18:19:02 +02:00
										 |  |  |         showMessage(_("INFERIOR ATTACHED")); | 
					
						
							|  |  |  |         showMessage(msgAttachedToStoppedInferior(), StatusBar); | 
					
						
							| 
									
										
										
										
											2010-07-08 12:41:26 +02:00
										 |  |  |         m_engine->handleInferiorPrepared(); | 
					
						
							| 
									
										
										
										
											2009-09-29 17:12:35 +02:00
										 |  |  |         m_engine->updateAll(); | 
					
						
							| 
									
										
										
										
											2009-10-12 12:00:07 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-01-04 14:11:07 +01:00
										 |  |  |         QString msg = QString::fromLocal8Bit(response.data.findChild("msg").data()); | 
					
						
							| 
									
										
										
										
											2010-07-08 12:41:26 +02:00
										 |  |  |         m_engine->handleInferiorStartFailed(msg); | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AttachGdbAdapter::interruptInferior() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const qint64 pid = startParameters().attachPID; | 
					
						
							| 
									
										
										
										
											2009-10-28 20:03:50 +01:00
										 |  |  |     QTC_ASSERT(pid > 0, return); | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  |     if (!interruptProcess(pid)) | 
					
						
							| 
									
										
										
										
											2010-06-14 18:19:02 +02:00
										 |  |  |         showMessage(_("CANNOT INTERRUPT %1").arg(pid)); | 
					
						
							| 
									
										
										
										
											2009-09-23 15:28:50 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace Internal
 | 
					
						
							|  |  |  | } // namespace Debugger
 |