comparison lisp/progmodes/gdb-mi.el @ 103886:d9b3b49cf6d3

(json-partial-output): Fix broken GDB/MI output in -break-info command (Emacs bug #3794).
author Dmitry Dzhus <dima@sphinx.net.ru>
date Tue, 14 Jul 2009 08:40:58 +0000
parents d8f620ade0dc
children 67efbd930fef
comparison
equal deleted inserted replaced
103885:adbe0e36df45 103886:d9b3b49cf6d3
1434 1434
1435 (defun gdb-clear-partial-output () 1435 (defun gdb-clear-partial-output ()
1436 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer) 1436 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1437 (erase-buffer))) 1437 (erase-buffer)))
1438 1438
1439 (defun json-partial-output (&optional fix-key) 1439 (defun json-partial-output (&optional fix-key fix-list)
1440 "Parse gdb-partial-output-buffer with `json-read'. 1440 "Parse gdb-partial-output-buffer with `json-read'.
1441 1441
1442 If FIX-KEY is non-nil, strip all \"FIX-KEY=\" occurences from 1442 If FIX-KEY is non-nil, strip all \"FIX-KEY=\" occurences from
1443 partial output. This is used to get rid of useless keys in lists 1443 partial output. This is used to get rid of useless keys in lists
1444 in MI messages, e.g.: [key=.., key=..]. -stack-list-frames and 1444 in MI messages, e.g.: [key=.., key=..]. -stack-list-frames and
1445 -break-info are examples of MI commands which issue such 1445 -break-info are examples of MI commands which issue such
1446 responses. 1446 responses.
1447 1447
1448 If FIX-LIST is non-nil, \"FIX-LIST={..}\" is replaced with
1449 \"FIX-LIST=[..]\" prior to parsing. This is used to fix broken
1450 -break-info output when it contains breakpoint script field
1451 incompatible with GDB/MI output syntax.
1452
1448 Note that GDB/MI output syntax is different from JSON both 1453 Note that GDB/MI output syntax is different from JSON both
1449 cosmetically and (in some cases) structurally, so correct results 1454 cosmetically and (in some cases) structurally, so correct results
1450 are not guaranteed." 1455 are not guaranteed."
1451 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer) 1456 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
1452 (goto-char (point-min)) 1457 (goto-char (point-min))
1453 (while (re-search-forward (concat "[\\[,]\\(" fix-key "=\\)") nil t) 1458 (when fix-key
1454 (replace-match "" nil nil nil 1)) 1459 (save-excursion
1455 (goto-char (point-min)) 1460 (while (re-search-forward (concat "[\\[,]\\(" fix-key "=\\)") nil t)
1456 (insert "{") 1461 (replace-match "" nil nil nil 1))))
1462 (when fix-list
1463 (save-excursion
1464 ;; Find positions of brackets which enclose broken list
1465 (while (re-search-forward (concat fix-list "={\"") nil t)
1466 (let ((p1 (goto-char (- (point) 2)))
1467 (p2 (progn (forward-sexp)
1468 (1- (point)))))
1469 ;; Replace braces with brackets
1470 (save-excursion
1471 (goto-char p1)
1472 (delete-char 1)
1473 (insert "[")
1474 (goto-char p2)
1475 (delete-char 1)
1476 (insert "]"))))))
1477 (goto-char (point-min))
1478 (insert "{")
1457 ;; Wrap field names in double quotes and replace equal sign with 1479 ;; Wrap field names in double quotes and replace equal sign with
1458 ;; semicolon. 1480 ;; semicolon.
1459 ;; TODO: This breaks badly with foo= inside constants 1481 ;; TODO: This breaks badly with foo= inside constants
1460 (while (re-search-forward "\\([[:alpha:]-_]+\\)=" nil t) 1482 (while (re-search-forward "\\([[:alpha:]-_]+\\)=" nil t)
1461 (replace-match "\"\\1\":" nil nil)) 1483 (replace-match "\"\\1\":" nil nil))
1540 1562
1541 (defun gdb-breakpoints-list-handler-custom () 1563 (defun gdb-breakpoints-list-handler-custom ()
1542 (setq gdb-pending-triggers (delq 'gdb-invalidate-breakpoints 1564 (setq gdb-pending-triggers (delq 'gdb-invalidate-breakpoints
1543 gdb-pending-triggers)) 1565 gdb-pending-triggers))
1544 (let ((breakpoints-list (gdb-get-field 1566 (let ((breakpoints-list (gdb-get-field
1545 (json-partial-output "bkpt") 1567 (json-partial-output "bkpt" "script")
1546 'BreakpointTable 'body))) 1568 'BreakpointTable 'body)))
1547 (setq gdb-breakpoints-list breakpoints-list) 1569 (setq gdb-breakpoints-list breakpoints-list)
1548 (insert "Num\tType\t\tDisp\tEnb\tHits\tAddr What\n") 1570 (insert "Num\tType\t\tDisp\tEnb\tHits\tAddr What\n")
1549 (dolist (breakpoint breakpoints-list) 1571 (dolist (breakpoint breakpoints-list)
1550 (insert 1572 (insert