Debugger: Avoid exception with GDB 10 to fix running dumper tests

Since GDB commit 1ba1ac88011703abcd0271e4f5d00927dc69a09a [1]
("gdb: Enable stdin on exception in execute_gdb_command",
committed 2020-01-24), stdin for GDB is re-enabled whenever
an exception is caught during 'gdb.execute()'.

When running the dumper tests for GDB, such an exception
was thrown when loading the qtcore library, resulting
in the GDB commands after the 'run' command (s.
'tst_Dumpers::dumper') to be be handled by GDB prematurely
when loading the library instead of when reaching the
end of the test program.

This resulted in the dumper tests failing with output like

    29: (gdb)
    29: &"up 0\n"
    29: &"No stack.\n"
    29: ^error,msg="No stack."
    29: (gdb)
    29: &"python theDumper.fetchVariables({'token':2,'fancy':1,'forcens':1,'autoderef':1,'dyntype':1,'passexceptions':1,'testing':1,'qobjectnames':1,'expanded':['local']})\n"
    29: &"Traceback (most recent call last):\n"
    29: &"  File \"<string>\", line 1, in <module>\n"
    29: &"  File \".../qt-creator/share/qtcreator/debugger/gdbbridge.py\", line 711, in fetchVariables\n"
    29: &"    variables = self.listLocals(partialName)\n"
    29: &"  File \".../qt-creator/share/qtcreator/debugger/gdbbridge.py\", line 597, in listLocals\n"
    29: &"    frame = gdb.selected_frame()\n"
    29: &"gdb.error: No frame is currently selected.\n"
    29: &"Error while executing Python code.\n"
    29: ^error,msg="Error while executing Python code."

Avoid the exception by first trying to 'gdb.execute' the
command that works for GDB 8+ and fall back to the command
for earlier GDB versions, i.e. reverse the order. That
should be fine for all GDB versions, given the commit
mentioned above is only contained from GDB 10 on.

While at it, move the assignment to 'cmd' into the
corresponding 'try' blocks to make the context a bit
clearer.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=1ba1ac88011703abcd0271e4f5d00927dc69a09a

Change-Id: I2d1bb52a777801e6bd77a5eda581a2fd5dd3a18f
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Michael Weghorn
2021-02-18 17:17:58 +01:00
parent ee77958998
commit 2d8dff4a8a

View File

@@ -1074,13 +1074,13 @@ class Dumper(DumperBase):
def handleQtCoreLoaded(self, objfile):
fd, tmppath = tempfile.mkstemp()
os.close(fd)
cmd = 'maint print msymbols %s "%s"' % (tmppath, objfile.filename)
try:
cmd = 'maint print msymbols -objfile "%s" -- %s' % (objfile.filename, tmppath)
symbols = gdb.execute(cmd, to_string=True)
except:
# command syntax depends on gdb version - below is gdb 8+
cmd = 'maint print msymbols -objfile "%s" -- %s' % (objfile.filename, tmppath)
try:
# command syntax depends on gdb version - below is gdb < 8
cmd = 'maint print msymbols %s "%s"' % (tmppath, objfile.filename)
symbols = gdb.execute(cmd, to_string=True)
except:
pass