Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.0 KiB

  1. ;; Copyright (C) 2015-2016, 2019 Free Software Foundation, Inc
  2. ;; Author: Rocky Bernstein <rocky@gnu.org>
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;; `realgud:gdb' Main interface to gdb via Emacs
  14. (require 'load-relative)
  15. (require-relative-list '("../../common/cmds"
  16. "../../common/helper"
  17. "../../common/utils")
  18. "realgud-")
  19. (require-relative-list '("../../common/buffer/command"
  20. "../../common/buffer/source")
  21. "realgud-buffer-")
  22. (require-relative-list '("core" "track-mode") "realgud:gdb-")
  23. (declare-function realgud-cmdbuf? 'realgud-buffer-command)
  24. (declare-function realgud:cmdbuf-associate 'realgud-buffer-source)
  25. (declare-function realgud-parse-command-arg 'realgud-core)
  26. ;; This is needed, or at least the docstring part of it is needed to
  27. ;; get the customization menu to work in Emacs 24.
  28. (defgroup realgud:gdb nil
  29. "The realgud interface to gdb"
  30. :group 'realgud
  31. :version "25.1")
  32. ;; -------------------------------------------------------------------
  33. ;; User definable variables
  34. ;;
  35. (defcustom realgud:gdb-command-name
  36. ;;"gdb --emacs 3"
  37. "gdb"
  38. "File name for executing the and command options.
  39. This should be an executable on your path, or an absolute file name."
  40. :type 'string
  41. :group 'realgud:gdb)
  42. (declare-function realgud:gdb-track-mode 'realgud:gdb-track-mode)
  43. (declare-function realgud-command 'realgud:cmds)
  44. (declare-function realgud:gdb-parse-cmd-args 'realgud:gdb-core)
  45. (declare-function realgud:gdb-query-cmdline 'realgud:gdb-core)
  46. (declare-function realgud:run-process 'realgud-core)
  47. (declare-function realgud:flatten 'realgud-utils)
  48. ;; -------------------------------------------------------------------
  49. ;; The end.
  50. ;;
  51. (defun realgud:gdb-pid-command-buffer (pid)
  52. "Return the command buffer used when gdb -p PID is invoked"
  53. (format "*gdb %d shell*" pid)
  54. )
  55. (defun realgud:gdb-find-command-buffer (pid)
  56. "Find the among current buffers a buffer that is a realgud command buffer
  57. running gdb on process number PID"
  58. (let ((find-cmd-buf (realgud:gdb-pid-command-buffer pid))
  59. (found-buf))
  60. (dolist (buf (buffer-list))
  61. (if (and (equal find-cmd-buf (buffer-name buf))
  62. (realgud-cmdbuf? buf)
  63. (get-buffer-process buf))
  64. (setq found-buf buf)))
  65. found-buf))
  66. (defun realgud:gdb-pid (pid)
  67. "Start debugging gdb process with pid PID."
  68. (interactive "nEnter the pid that gdb should attach to: ")
  69. (realgud:gdb (format "%s -p %d" realgud:gdb-command-name pid))
  70. ;; FIXME: should add code to test if attach worked.
  71. )
  72. (defun realgud:gdb-pid-associate (pid)
  73. "Start debugging gdb process with pid PID and associate the
  74. current buffer to that realgud command buffer."
  75. (interactive "nEnter the pid that gdb should attach to and associate the current buffer to: ")
  76. (let* ((command-buf)
  77. (source-buf (current-buffer))
  78. )
  79. (realgud:gdb-pid pid)
  80. (setq command-buf (realgud:gdb-find-command-buffer pid))
  81. (if command-buf
  82. (with-current-buffer source-buf
  83. (realgud:cmdbuf-associate))
  84. )))
  85. ;;;###autoload
  86. (defun realgud:gdb (&optional opt-cmd-line no-reset)
  87. "Invoke the gdb debugger and start the Emacs user interface.
  88. OPT-CMD-LINE is treated like a shell string; arguments are
  89. tokenized by `split-string-and-unquote'.
  90. Normally, command buffers are reused when the same debugger is
  91. reinvoked inside a command buffer with a similar command. If we
  92. discover that the buffer has prior command-buffer information and
  93. NO-RESET is nil, then that information which may point into other
  94. buffers and source buffers which may contain marks and fringe or
  95. marginal icons is reset. See `loc-changes-clear-buffer' to clear
  96. fringe and marginal icons.
  97. "
  98. (interactive)
  99. (let* ((cmd-str (or opt-cmd-line (realgud:gdb-query-cmdline "gdb")))
  100. (cmd-args (split-string-and-unquote cmd-str))
  101. (parsed-args (realgud:gdb-parse-cmd-args cmd-args))
  102. (script-args (cl-caddr parsed-args))
  103. (script-name (or (car script-args) ""))
  104. (parsed-cmd-args
  105. (cl-remove-if-not 'stringp (realgud:flatten parsed-args)))
  106. (cmd-buf (realgud:run-process realgud:gdb-command-name
  107. script-name parsed-cmd-args
  108. 'realgud:gdb-minibuffer-history
  109. nil))
  110. )
  111. (if cmd-buf
  112. (let ((process (get-buffer-process cmd-buf)))
  113. (if (and process (eq 'run (process-status process)))
  114. (with-current-buffer cmd-buf
  115. (realgud-command "set annotate 1" nil nil nil)
  116. )))
  117. )
  118. ))
  119. (provide-me "realgud-")
  120. ;; Local Variables:
  121. ;; byte-compile-warnings: (not cl-functions)
  122. ;; End: