Home | History | Annotate | Line # | Download | only in gdb.guile
scm-frame-args.scm revision 1.8
      1  1.8  christos ;; Copyright (C) 2014-2023 Free Software Foundation, Inc.
      2  1.1  christos ;;
      3  1.1  christos ;; This program is free software; you can redistribute it and/or modify
      4  1.1  christos ;; it under the terms of the GNU General Public License as published by
      5  1.1  christos ;; the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos ;; (at your option) any later version.
      7  1.1  christos ;;
      8  1.1  christos ;; This program is distributed in the hope that it will be useful,
      9  1.1  christos ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos ;; GNU General Public License for more details.
     12  1.1  christos ;;
     13  1.1  christos ;; You should have received a copy of the GNU General Public License
     14  1.1  christos ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos (use-modules (gdb) (gdb printing))
     17  1.1  christos 
     18  1.1  christos (define (make-pp_s-printer val)
     19  1.1  christos   (make-pretty-printer-worker
     20  1.1  christos    #f
     21  1.1  christos    (lambda (printer)
     22  1.1  christos      (let ((m (value-field val "m")))
     23  1.1  christos        (format #f "m=<~A>" m)))
     24  1.1  christos    #f))
     25  1.1  christos 
     26  1.1  christos (define (make-pp_ss-printer val)
     27  1.1  christos   (make-pretty-printer-worker
     28  1.1  christos    #f
     29  1.1  christos    (lambda (printer) "super struct")
     30  1.1  christos    (lambda (printer)
     31  1.1  christos      (make-iterator val
     32  1.1  christos 		    (make-field-iterator (value-type val))
     33  1.1  christos 		    (lambda (iter)
     34  1.1  christos 		      (let ((field (iterator-next!
     35  1.1  christos 				    (iterator-progress iter))))
     36  1.1  christos 			(if (end-of-iteration? field)
     37  1.1  christos 			    field
     38  1.1  christos 			    (let ((name (field-name field)))
     39  1.1  christos 			      (cons name (value-field val name))))))))))
     40  1.1  christos 
     41  1.1  christos (define (get-type-for-printing val)
     42  1.1  christos   "Return type of val, stripping away typedefs, etc."
     43  1.1  christos   (let ((type (value-type val)))
     44  1.1  christos     (if (= (type-code type) TYPE_CODE_REF)
     45  1.1  christos 	(set! type (type-target type)))
     46  1.1  christos     (type-strip-typedefs (type-unqualified type))))
     47  1.1  christos 
     48  1.1  christos (define (make-pretty-printer-dict)
     49  1.1  christos   (let ((dict (make-hash-table)))
     50  1.1  christos     (hash-set! dict "struct s" make-pp_s-printer)
     51  1.1  christos     (hash-set! dict "s" make-pp_s-printer)
     52  1.1  christos     (hash-set! dict "struct ss" make-pp_ss-printer)
     53  1.1  christos     (hash-set! dict "ss" make-pp_ss-printer)
     54  1.1  christos     dict))
     55  1.1  christos 
     56  1.1  christos (define *pretty-printer*
     57  1.1  christos  (make-pretty-printer
     58  1.1  christos   "pretty-printer-test"
     59  1.1  christos   (let ((pretty-printers-dict (make-pretty-printer-dict)))
     60  1.1  christos     (lambda (matcher val)
     61  1.1  christos       "Look-up and return a pretty-printer that can print val."
     62  1.1  christos       (let ((type (get-type-for-printing val)))
     63  1.1  christos 	(let ((typename (type-tag type)))
     64  1.1  christos 	  (if typename
     65  1.1  christos 	      (let ((printer-maker (hash-ref pretty-printers-dict typename)))
     66  1.1  christos 		(and printer-maker (printer-maker val)))
     67  1.1  christos 	      #f)))))))
     68  1.1  christos 
     69  1.1  christos (append-pretty-printer! #f *pretty-printer*)
     70