]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.guile/scm-section-script.scm
2a751dde197eebfb5930e080731c93eef3bcb090
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.guile / scm-section-script.scm
1 ;; Copyright (C) 2010-2016 Free Software Foundation, Inc.
2 ;;
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 ;;
8 ;; This program is distributed in the hope that it will be useful,
9 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ;; GNU General Public License for more details.
12 ;;
13 ;; You should have received a copy of the GNU General Public License
14 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 ;; This file is part of the GDB testsuite.
17
18 (use-modules (gdb) (gdb printing))
19
20 (define (make-pp_ss-printer val)
21 (make-pretty-printer-worker
22 #f
23 (lambda (printer)
24 (let ((a (value-field val "a"))
25 (b (value-field val "b")))
26 (format #f "a=<~A> b=<~A>" a b)))
27 #f))
28
29 (define (get-type-for-printing val)
30 "Return type of val, stripping away typedefs, etc."
31 (let ((type (value-type val)))
32 (if (= (type-code type) TYPE_CODE_REF)
33 (set! type (type-target type)))
34 (type-strip-typedefs (type-unqualified type))))
35
36 (define (make-pretty-printer-dict)
37 (let ((dict (make-hash-table)))
38 (hash-set! dict "struct ss" make-pp_ss-printer)
39 (hash-set! dict "ss" make-pp_ss-printer)
40 dict))
41
42 (define *pretty-printer*
43 (make-pretty-printer
44 "pretty-printer-test"
45 (let ((pretty-printers-dict (make-pretty-printer-dict)))
46 (lambda (matcher val)
47 "Look-up and return a pretty-printer that can print val."
48 (let ((type (get-type-for-printing val)))
49 (let ((typename (type-tag type)))
50 (if typename
51 (let ((printer-maker (hash-ref pretty-printers-dict typename)))
52 (and printer-maker (printer-maker val)))
53 #f)))))))
54
55 (append-pretty-printer! #f *pretty-printer*)