From 3a03481a15fd1873189317dc8e1164c0d0f0fd31 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 23 Nov 2012 22:45:53 +0100 Subject: [PATCH] Adjust breakpoint parser to a different syntax. When a new breakpoint is set, GDB's response is used to seed the internal table of breakpoints with file name and line number information. This is in turn needed to display the new breakpoint in the source code window. So far, we have expected that GDB's response is of this kind: Breakpoint 1 at 0x400b94: file multibrkpt.cpp, line 9. But Luka Hranjec reported a case where the response looked like this: Breakpoint 4 at 0x804f158: lotto739.cpp:95. Adjust the parser to accept this alternate syntax. Note that neither of the two unambiguously identifies the file name and line number. Hence, we just use the best-effort result that favors the former syntax. --- kdbg/gdbdriver.cpp | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/kdbg/gdbdriver.cpp b/kdbg/gdbdriver.cpp index c08496b..9bb3fee 100644 --- a/kdbg/gdbdriver.cpp +++ b/kdbg/gdbdriver.cpp @@ -2101,17 +2101,38 @@ static bool parseNewBreakpoint(const char* o, int& id, ++p; address = QString::fromLatin1(start, p-start); } - - // file name + + /* + * Mostly, GDB responds with this syntax: + * + * Breakpoint 1 at 0x400b94: file multibrkpt.cpp, line 9. (2 locations) + * + * but sometimes it uses this syntax: + * + * Breakpoint 4 at 0x804f158: lotto739.cpp:95. (3 locations) + */ + char* fileEnd, *numStart = 0; char* fileStart = strstr(p, "file "); - if (fileStart == 0) - return !address.isEmpty(); /* parse error only if there's no address */ - fileStart += 5; - - // line number - char* numStart = strstr(fileStart, ", line "); - QString fileName = QString::fromLatin1(fileStart, numStart-fileStart); - numStart += 7; + if (fileStart != 0) + { + fileStart += 5; + fileEnd = strstr(fileStart, ", line "); + if (fileEnd != 0) + numStart = fileEnd + 7; + } + if (numStart == 0 && p[0] == ':' && p[1] == ' ') + { + fileStart = p+2; + while (isspace(*fileStart)) + ++fileStart; + fileEnd = strchr(fileStart, ':'); + if (fileEnd != 0) + numStart = fileEnd + 1; + } + if (numStart == 0) + return !address.isEmpty(); /* parse error only if there's no address */ + + QString fileName = QString::fromLatin1(fileStart, fileEnd-fileStart); int line = strtoul(numStart, &p, 10); if (numStart == p) return false; -- 2.11.4.GIT