This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Question: finding out a function return type


> Date: Fri, 28 Apr 2000 18:08:03 +0200 (MET DST)
> From: Fredrik Warg <warg@ce.chalmers.se>
> To: gcc@gcc.gnu.org

> What I want to do is to get the return type of each function/method
> (actually it is enough to know if the return type is void or
> something else).

First, fire up emacs, then type M-x gdb, then cc1plus, or cc1...  then
run the compiler.  Set a breakpoint on finish_function or some other
place that deals with functions, then run, then find a tree that
should have a function, then do a p decl, and then a pt.  It will come
out on the screen.  From there you can wander around the various
fields to confirm what one you might guess is the right one...

To help you wander, and because macros don't appear in gdb usually,
you might fine the below helpful.  It will add a menu item for
shortcuts for a few of the macros, adding more is easy enough.

If you did this in this case, you would find TREE_TYPE (TREE_TYPE
(fndecl)) or TREE_TYPE (fntype) would have the field your interested
in.  I checked the documentation, and I was surprised, this actually
isn't documented, does seem like a flaw.


And Welcome to gcc.


(defun cxx-xx (arg)
  (gud-set-buffer)
  (save-excursion
    (set-buffer gud-comint-buffer)
    (goto-char (point-max))
    (insert arg)))

(defun cxx-dn (arg)
  (interactive "p")
  (cxx-xx ".decl.name"))
(defun cxx-tn (arg)
  (interactive "p")
  (cxx-xx ".type.name"))
(defun cxx-dan (arg)
  (interactive "p")
  (cxx-xx ".decl.assembler_name"))
(defun cxx-dvi (arg)
  (interactive "p")
  (cxx-xx ".decl.vindex"))
(defun cxx-tt (arg)
  (interactive "p")
  (cxx-xx ".common.type"))
(defun cxx-tcode (arg)
  (interactive "p")
  (cxx-xx ".common.code"))
(defun cxx-tchain (arg)
  (interactive "p")
  (cxx-xx ".common.chain"))
(defun cxx-tvalue (arg)
  (interactive "p")
  (cxx-xx ".list.value"))
(defun cxx-fnaddr (arg)
  (interactive "p")
  (cxx-xx ".exp.operands[1].common.chain.common.chain.list.value"))
(defun cxx-taddr (arg)
  (interactive "p")
  (cxx-xx ".common.addressable_flag"))
(defun cxx-cnvr (arg)
  (interactive "p")
  (cxx-tls arg)
  (cxx-xx ".type_flags.needs_virtual_reinit"))
(defun cxx-thc (arg)
  (interactive "p")
  (cxx-xx ".type.lang_flag_1"))
(defun cxx-tflds (arg)
  (interactive "p")
  (cxx-xx ".type.values"))
(defun cxx-mval (arg)
  (interactive "p")
  (cxx-xx ".type.maxval"))
(defun cxx-tls (arg)
  (interactive "p")
  (cxx-xx ".type.lang_specific"))
(defun cxx-pmftype (arg)
  (interactive "p")
  (cxx-tflds arg)
  (cxx-tchain arg)
  (cxx-tchain arg)
  (cxx-tt arg)
  (cxx-tflds arg)
  (cxx-tt arg))
(defun cxx-cvs (arg)
  (interactive "p")
  (cxx-tls arg)
  (cxx-xx ".vsize"))
(defun cxx-cvbc (arg)
  (interactive "p")
  (cxx-tls arg)
  (cxx-xx ".vbases"))
(defun cxx-vflds (arg)
  (interactive "p")
  (cxx-tls arg)
  (cxx-xx ".vfields"))
(defun cxx-vfld (arg)
  (interactive "p")
  (cxx-tvfld arg))
(defun cxx-tvfld (arg)
  (interactive "p")
  (cxx-xx ".type.minval"))
(defun cxx-tb (arg)
  (interactive "p")
  (cxx-xx ".type.binfo"))
(defun cxx-bic (arg)
  (interactive "p")
  (cxx-vec 0))
(defun cxx-bo (arg)
  (interactive "p")
  (cxx-vec 1))
(defun cxx-bvtbl (arg)
  (interactive "p")
  (cxx-vec 2))
(defun cxx-bv (arg)
  (interactive "p")
  (cxx-vec 3))
(defun cxx-bb (arg)
  (interactive "p")
  (cxx-vec 4))
(defun cxx-bvptr (arg)
  (interactive "p")
  (cxx-vec 5))
(defun cxx-bt (arg)
  (interactive "p")
  (cxx-tt arg))
(defun cxx-vec (arg)
  (interactive "p")
  (cxx-xx (concat ".vec.a[" (int-to-string arg) "]")))
(defun cxx-dte (arg)
  (interactive "p")
  (cxx-xx ".decl.lang_flag_2"))
(defun cxx-di (arg)
  (interactive "p")
  (cxx-xx ".decl.inline_flag"))
(defun cxx-tp (arg)
  (interactive "p")
  (cxx-xx ".common.public_flag"))
(defun cxx-cid (arg)
  (interactive "p")
  (cxx-xx ".common.public_flag"))

(defun gdb-old-keys ()
  (modify-syntax-entry 60 "(>")
  (modify-syntax-entry 62 ")<")

  ;; Create the C++ shorts menu item.
  (setq gud-mode-map (current-local-map))
  (define-key gud-mode-map [menu-bar cxx-shorts]
    (cons "C++ shorts" (make-sparse-keymap "C++ shorts")))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-vec]
    '("TREE_VEC ()" . cxx-vec))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-bt]
    '("BINFO_TYPE ()" . cxx-bt))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-bb]
    '("BINFO_BASETYPES ()" . cxx-bb))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-bic]
    '("BINFO_INHERITANCE_CHAIN ()" . cxx-bic))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-bo]
    '("BINFO_OFFSET ()" . cxx-bo))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-bvtbl]
    '("BINFO_VTABLE ()" . cxx-bvtbl))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-bv]
    '("BINFO_VIRTUALS ()" . cxx-bv))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-bvptr]
    '("BINFO_VPTR_FIELD ()" . cxx-bvptr))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tb]
    '("TYPE_BINFO ()" . cxx-tb))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tvfld]
    '("TYPE_VFIELD ()" . cxx-tvfld))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-vfld]
    '("CLASSTYPE_VFIELD ()" . cxx-vfld))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-vflds]
    '("CLASSTYPE_VFIELDS ()" . cxx-vflds))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-cvbc]
    '("CLASSTYPE_VBASECLASSES ()" . cxx-cvbc))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-cvs]
    '("CLASSTYPE_VSIZE ()" . cxx-cvs))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-pmftype]
    '("TYPE_PTRMEMFUNC_FN_TYPE ()" . cxx-pmftype))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tm]
    '("TYPE_METHODS ()" . cxx-mval))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tls]
    '("TYPE_LANG_SPECIFIC ()" . cxx-tls))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-mval]
    '("TYPE_MAX_VALUE ()" . cxx-mval))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tmb]
    '("TYPE_METHOD_BASETYPE ()" . cxx-mval))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tob]
    '("TYPE_OFFSET_BASETYPE ()" . cxx-mval))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tflds]
    '("TYPE_FIELDS ()" . cxx-tflds))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-fnaddr]
    '("FNADDR_FROM_VTABLE_ENTRY ()" . cxx-fnaddr))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-cnvr]
    '("CLASSTYPE_NEEDS_VIRTUAL_REINIT ()" . cxx-cnvr))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-thc]
    '("TYPE_HAS_CONSTRUCTOR ()" . cxx-thc))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-dn]
    '("DECL_NAME ()" . cxx-dn))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tn]
    '("TYPE_NAME ()" . cxx-tn))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-dan]
    '("DECL_ASSEMBLER_NAME ()" . cxx-dan))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-dvi]
    '("DECL_VINDEX ()" . cxx-dvi))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tt]
    '("TREE_TYPE ()" . cxx-tt))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tcode]
    '("TREE_CODE ()" . cxx-tcode))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-taddr]
    '("TREE_ADDRESSABLE ()" . cxx-taddr))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tchain]
    '("TREE_CHAIN ()" . cxx-tchain))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tvalue]
    '("TREE_VALUE ()" . cxx-tvalue))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-dte]
    '("DECL_THIS_EXTERN ()" . cxx-dte))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-di]
    '("DECL_INLINE ()" . cxx-di))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-tp]
    '("TREE_PUBLIC ()" . cxx-tp))
  (define-key gud-mode-map [menu-bar cxx-shorts cxx-cid]
    '("CLASSTYPE_CID ()" . cxx-cid))

  ;; Create the gdb menu item.
  (define-key gud-mode-map [menu-bar gdb]
    (cons "Gdb" (make-sparse-keymap "Gdb")))
  (define-key gud-mode-map [menu-bar gdb gud-break]
    '("set breakpoint" . gud-break))
  (define-key gud-mode-map [menu-bar gdb gud-tbreak]
    '("set temp break" . gud-tbreak))
  (define-key gud-mode-map [menu-bar gdb gud-remove]
    '("remove breakpoint" . gud-remove))
  (define-key gud-mode-map [menu-bar gdb gud-step]
    '("step" . gud-step))
  (define-key gud-mode-map [menu-bar gdb gud-next]
    '("next" . gud-next))
  (define-key gud-mode-map [menu-bar gdb gud-cont]
    '("continue" . gud-cont))
  (define-key gud-mode-map [menu-bar gdb gud-up]
    '("up stack" . gud-up))
  (define-key gud-mode-map [menu-bar gdb gud-down]
    '("down stack" . gud-down))
  (define-key gud-mode-map [menu-bar gdb gud-finish]
    '("finish" . gud-finish))
  (define-key gud-mode-map [menu-bar gdb gud-print]
    '("print C exp a point" . gud-print))

  (mapcar (function (lambda (binding)
                      (define-key gud-mode-map (car binding) (cdr binding))))
          '(("\M-n" . gud-next)
            ("\M-u" . gud-up)
            ("\M-d" . gud-down)
            ("\M-c" . gud-cont))))
(if emacs19
    (progn
      (global-set-key (quote [stop]) 'gud-break)
      (global-set-key (quote [C-stop]) 'gud-tbreak)
      ;; Break key on Sun
      (global-set-key (quote [f11]) 'gud-break)
      (global-set-key (quote [C-f11]) 'gud-tbreak)
      (setq gdb-mode-hook (list 'gdb-old-keys))
      ;;	+-----+-----+-----+-----+
      ;;	|     |     |     |     |
      ;;	+-----+-----+-----+-----+
      ;;	|     |     |     |     |
      ;;	+-----+-----+-----+-----+
      ;;	|     |     |     |     |
      ;;	+-----+-----+-----+-----+
      ;;	|     |up   |fini |     |
      ;;	+-----+-----+-----+     +
      ;;	|     |step |next |     |
      ;;	+-----+-----+-----+-----+
      ;;	|     |down |cont |     |
      ;;	+-----+-----+-----+     +
      ;;	|           |     |     |
      ;;	+-----+-----+-----+-----+
      (add-hook 'gdb-mode-hook '(lambda nil
				  (local-set-key [C-right] 'gud-next)
				  (local-set-key [C-f31] 'gud-step)
				  (local-set-key [C-up] 'gud-up)
				  (local-set-key [C-down] 'gud-down)
				  (local-set-key [C-f29] 'gud-finish)
				  (local-set-key [C-f35] 'gud-cont)))))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]