Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tobias Hunger
qt-creator
Commits
3dfe96eb
Commit
3dfe96eb
authored
Oct 20, 2009
by
Oswald Buddenhagen
Browse files
refactor attachAdapter
parent
3a84440e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/plugins/debugger/gdb/coregdbadapter.cpp
View file @
3dfe96eb
...
...
@@ -36,6 +36,7 @@
#include <utils/qtcassert.h>
#include <QtCore/QFileInfo>
#include <QtGui/QMessageBox>
namespace
Debugger
{
namespace
Internal
{
...
...
@@ -70,60 +71,33 @@ void CoreGdbAdapter::startAdapter()
void
CoreGdbAdapter
::
startInferior
()
{
QTC_ASSERT
(
state
()
==
InferiorStarting
,
qDebug
()
<<
state
());
QFileInfo
fi
(
startParameters
().
coreFile
);
m_executable
=
startParameters
().
executable
;
if
(
m_executable
.
isEmpty
())
{
#ifdef EXE_FROM_CORE
// Extra round trip to get executable name from core file.
// This is sometimes not the full name, so it can't be used
// as the generic solution.
// Quoting core name below fails in gdb 6.8-debian.
QString
coreName
=
fi
.
absoluteFilePath
();
m_engine
->
postCommand
(
_
(
"target core "
)
+
coreName
,
CB
(
handleTargetCore1
));
}
else
{
// Directly load symbols.
QFileInfo
fi
(
m_executable
);
m_engine
->
postCommand
(
_
(
"-file-exec-and-symbols
\"
%1
\"
"
)
.
arg
(
fi
.
absoluteFilePath
()),
CB
(
handleFileExecAndSymbols
));
}
}
void
CoreGdbAdapter
::
handleTargetCore1
(
const
GdbResponse
&
response
)
{
QTC_ASSERT
(
state
()
==
InferiorStarting
,
qDebug
()
<<
state
());
if
(
response
.
resultClass
==
GdbResultDone
)
{
showStatusMessage
(
tr
(
"Attached to core temporarily."
));
GdbMi
console
=
response
.
data
.
findChild
(
"consolestreamoutput"
);
int
pos1
=
console
.
data
().
indexOf
(
'`'
);
int
pos2
=
console
.
data
().
indexOf
(
'\''
);
if
(
pos1
==
-
1
||
pos2
==
-
1
)
{
emit
inferiorStartFailed
(
tr
(
"No binary found."
));
}
else
{
m_executable
=
console
.
data
().
mid
(
pos1
+
1
,
pos2
-
pos1
-
1
);
// Strip off command line arguments. FIXME: make robust.
if
(
m_executable
.
contains
(
' '
))
m_executable
=
m_executable
.
section
(
' '
,
0
,
0
);
QTC_ASSERT
(
!
m_executable
.
isEmpty
(),
/**/
);
// Finish extra round.
m_engine
->
postCommand
(
_
(
"detach"
),
CB
(
handleDetach1
));
}
}
else
{
const
QByteArray
msg
=
response
.
data
.
findChild
(
"msg"
).
data
();
emit
inferiorStartFailed
(
msg
);
m_round
=
1
;
loadCoreFile
();
#else
showMessageBox
(
QMessageBox
::
Warning
,
tr
(
"Error Loading Symbols"
),
tr
(
"No executable to load symbols from specified."
));
#endif
return
;
}
#ifdef EXE_FROM_CORE
m_round
=
2
;
#endif
loadExeAndSyms
();
}
void
CoreGdbAdapter
::
handleDetach1
(
const
GdbResponse
&
response
)
void
CoreGdbAdapter
::
loadExeAndSyms
(
)
{
QTC_ASSERT
(
state
()
==
InferiorStarting
,
qDebug
()
<<
state
());
if
(
response
.
resultClass
==
GdbResultDone
)
{
// Load symbols.
QFileInfo
fi
(
m_executable
);
m_engine
->
postCommand
(
_
(
"-file-exec-and-symbols
\"
%1
\"
"
)
.
arg
(
fi
.
absoluteFilePath
()),
CB
(
handleFileExecAndSymbols
));
}
else
{
const
QByteArray
msg
=
response
.
data
.
findChild
(
"msg"
).
data
();
emit
inferiorStartFailed
(
msg
);
}
// Do that first, otherwise no symbols are loaded.
QFileInfo
fi
(
m_executable
);
m_engine
->
postCommand
(
_
(
"-file-exec-and-symbols
\"
%1
\"
"
)
.
arg
(
fi
.
absoluteFilePath
()),
CB
(
handleFileExecAndSymbols
));
}
void
CoreGdbAdapter
::
handleFileExecAndSymbols
(
const
GdbResponse
&
response
)
...
...
@@ -131,32 +105,58 @@ void CoreGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
QTC_ASSERT
(
state
()
==
InferiorStarting
,
qDebug
()
<<
state
());
if
(
response
.
resultClass
==
GdbResultDone
)
{
showStatusMessage
(
tr
(
"Symbols found."
));
// Quoting core name below fails in gdb 6.8-debian.
QFileInfo
fi
(
startParameters
().
coreFile
);
QString
coreName
=
fi
.
absoluteFilePath
();
m_engine
->
postCommand
(
_
(
"target core "
)
+
coreName
,
CB
(
handleTargetCore2
));
}
else
{
QString
msg
=
tr
(
"Symbols not found in
\"
%1
\"
failed:
\n
%2"
)
.
arg
(
__
(
response
.
data
.
findChild
(
"msg"
).
data
()));
setState
(
InferiorUnrunnable
);
m_engine
->
updateAll
();
// emit inferiorStartFailed(msg);
QString
msg
=
tr
(
"Loading symbols from
\"
%1
\"
failed:
\n
"
).
arg
(
m_executable
)
+
__
(
response
.
data
.
findChild
(
"msg"
).
data
());
showMessageBox
(
QMessageBox
::
Warning
,
tr
(
"Error Loading Symbols"
),
msg
);
}
loadCoreFile
();
}
void
CoreGdbAdapter
::
handleTargetCore2
(
const
GdbResponse
&
response
)
void
CoreGdbAdapter
::
loadCoreFile
()
{
// Quoting core name below fails in gdb 6.8-debian.
QFileInfo
fi
(
startParameters
().
coreFile
);
QString
coreName
=
fi
.
absoluteFilePath
();
m_engine
->
postCommand
(
_
(
"target core "
)
+
coreName
,
CB
(
handleTargetCore
));
}
void
CoreGdbAdapter
::
handleTargetCore
(
const
GdbResponse
&
response
)
{
QTC_ASSERT
(
state
()
==
InferiorStarting
,
qDebug
()
<<
state
());
if
(
response
.
resultClass
==
GdbResultDone
)
{
#ifdef EXE_FROM_CORE
if
(
m_round
==
1
)
{
m_round
=
2
;
GdbMi
console
=
response
.
data
.
findChild
(
"consolestreamoutput"
);
int
pos1
=
console
.
data
().
indexOf
(
'`'
);
int
pos2
=
console
.
data
().
indexOf
(
'\''
);
if
(
pos1
!=
-
1
&&
pos2
!=
-
1
)
{
m_executable
=
console
.
data
().
mid
(
pos1
+
1
,
pos2
-
pos1
-
1
);
// Strip off command line arguments. FIXME: make robust.
int
idx
=
m_executable
.
indexOf
(
_c
(
' '
));
if
(
idx
>=
0
)
m_executable
.
truncate
(
idx
);
if
(
!
m_executable
.
isEmpty
())
{
// Finish extra round ...
showStatusMessage
(
tr
(
"Attached to core temporarily."
));
m_engine
->
postCommand
(
_
(
"detach"
));
// ... and retry.
loadExeAndSyms
();
return
;
}
}
showMessageBox
(
QMessageBox
::
Warning
,
tr
(
"Error Loading Symbols"
),
tr
(
"Unable to determine executable from core file."
));
}
#endif
showStatusMessage
(
tr
(
"Attached to core."
));
setState
(
InferiorUnrunnable
);
m_engine
->
updateAll
();
}
else
{
QString
msg
=
tr
(
"Attach to core
\"
%1
\"
failed:
\n
%2"
)
.
arg
(
__
(
response
.
data
.
findChild
(
"msg"
).
data
()));
setState
(
InferiorUnrunnable
);
m_engine
->
updateAll
();
// emit inferiorStartFailed(msg);
QString
msg
=
tr
(
"Attach to core
\"
%1
\"
failed:
\n
"
).
arg
(
startParameters
().
coreFile
)
+
__
(
response
.
data
.
findChild
(
"msg"
).
data
());
emit
inferiorStartFailed
(
msg
);
}
}
...
...
src/plugins/debugger/gdb/coregdbadapter.h
View file @
3dfe96eb
...
...
@@ -32,6 +32,10 @@
#include "abstractgdbadapter.h"
#ifdef Q_OS_LINUX
# define EXE_FROM_CORE
#endif
namespace
Debugger
{
namespace
Internal
{
...
...
@@ -55,11 +59,14 @@ public:
void
interruptInferior
();
private:
void
handleTargetCore1
(
const
GdbResponse
&
response
);
void
handleDetach1
(
const
GdbResponse
&
response
);
void
loadExeAndSyms
(
);
void
loadCoreFile
(
);
void
handleFileExecAndSymbols
(
const
GdbResponse
&
response
);
void
handleTargetCore
2
(
const
GdbResponse
&
response
);
void
handleTargetCore
(
const
GdbResponse
&
response
);
#ifdef EXE_FROM_CORE
int
m_round
;
#endif
QString
m_executable
;
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment