 
 (defun rdebug-populate-debugger-menu (map)
   "Populate the Rdebug 'Debugger' menu."
-  (let ((menu (make-sparse-keymap)))
+  (let ((menu (make-sparse-keymap))
+        (common-map (make-sparse-keymap)))
+    ;; Use a simple common map to find the best key sequence to display in menu.
+    (rdebug-populate-common-keys common-map)
+
     (define-key map [menu-bar debugger] (cons "Debugger" menu))
 
     (define-key menu [break-delete]
-      '(menu-item "Delete breakpoint" gud-remove))
+      (rdebug-menu-item common-map "Delete breakpoint" 'gud-remove))
 
     (define-key menu [break]
-      '(menu-item "Set breakpoint" gud-break))
-
-    (define-key menu [finish] '(menu-item "Step out" gud-finish))
-    (define-key menu [step] '(menu-item "Step into" gud-step))
-    (define-key menu [next] '(menu-item "Step over" gud-next))
-    (define-key menu [cont] '(menu-item "Continue" gud-cont))
-    (define-key menu [start] '(menu-item "Start the debugger" rdebug))
+      (rdebug-menu-item common-map "Set breakpoint" 'gud-break))
+
+    (define-key menu [finish] (rdebug-menu-item common-map "Step out" 'gud-finish))
+    (define-key menu [step]   (rdebug-menu-item common-map "Step into" 'gud-step))
+    (define-key menu [next]   (rdebug-menu-item common-map "Step over" 'gud-next))
+    (define-key menu [cont]   (rdebug-menu-item common-map "Continue" 'gud-cont))
+    (define-key menu [start]
+      (rdebug-menu-item common-map "Start the debugger" 'rdebug))
 
     (define-key menu [placeholder] nil)
 

      (define-key menu [view] (cons "View" submenu)))

    (define-key map [menu-bar debugger view output]
      '(menu-item "Output" rdebug-display-output-buffer))

    (define-key map [menu-bar debugger view watch]
      '(menu-item "Watch" rdebug-display-watch-buffer))

    (define-key map [menu-bar debugger view stack]
      '(menu-item "Stack trace" rdebug-display-stack-buffer))

    (define-key map [menu-bar debugger view shell]
      '(menu-item "Debugger Shell" rdebug-display-cmd-buffer))

    (define-key map [menu-bar debugger view variables]
      '(menu-item "Variables" rdebug-display-variables-buffer))

    (define-key map [menu-bar debugger view breakpoints]
      '(menu-item "Breakpoints" rdebug-display-breakpoints-buffer))
    menu))




;; -- General, for all secondary buffers.


(defun rdebug-menu-item (common-map name cmd &rest args)
  "Return a menu item entry with the correct key bindings.

A command can be bound to a number of different key sequences. If
the rdebug common map contains a binding it is displayed in the
menu. (The common map typically contains function key bindings.)"
  (let ((key-binding-list (where-is-internal cmd (list common-map)))
        (hint '()))
    (if key-binding-list
        (setq hint (list :key-sequence (car key-binding-list))))
    (append (list 'menu-item name cmd)
            hint
            args)))


;; Note, we re-populate the menus of the different minor and major
;; modes. The reason is that Emacs caches the key bindings, which
;; means that wrong ones are shown when buffers are changed.
