1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 20:30:28 +02:00

better RTL debugging

* libguile/frames.c (scm_frame_source, scm_frame_instruction_pointer):
  Fix to work with RTL programs.

* module/system/vm/debug.scm (find-debug-context): Allow for the
  possibility of there being no ELF image.
  (find-program-debug-info, find-program-arities)
  (program-minimum-arity, find-program-docstring)
  (find-program-properties, find-source-for-addr)
  (find-program-die, find-program-sources): Don't bail if we couldn't
  get the debug context.

* module/system/vm/frame.scm (frame-next-source)
  (frame-call-representation): Allow RTL programs.

* module/system/vm/program.scm (program-arguments-alist): Placeholder
  implementation for RTL programs.
  (program-arguments-alists): Don't bail if we couldn't get the
  arities.
This commit is contained in:
Andy Wingo 2013-10-04 19:55:12 +02:00
parent fea115c33f
commit f8fb13ef8c
4 changed files with 70 additions and 50 deletions

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2001, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. /* Copyright (C) 2001, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
@ -110,7 +110,7 @@ SCM_DEFINE (scm_frame_source, "frame-source", 1, 0, 0,
proc = scm_frame_procedure (frame); proc = scm_frame_procedure (frame);
if (SCM_PROGRAM_P (proc)) if (SCM_PROGRAM_P (proc) || SCM_RTL_PROGRAM_P (proc))
return scm_program_source (scm_frame_procedure (frame), return scm_program_source (scm_frame_procedure (frame),
scm_frame_instruction_pointer (frame), scm_frame_instruction_pointer (frame),
SCM_UNDEFINED); SCM_UNDEFINED);
@ -260,6 +260,10 @@ SCM_DEFINE (scm_frame_instruction_pointer, "frame-instruction-pointer", 1, 0, 0,
SCM_VALIDATE_VM_FRAME (1, frame); SCM_VALIDATE_VM_FRAME (1, frame);
program = scm_frame_procedure (frame); program = scm_frame_procedure (frame);
if (SCM_RTL_PROGRAM_P (program))
return scm_from_ptrdiff_t (SCM_VM_FRAME_IP (frame) -
(scm_t_uint8 *) SCM_RTL_PROGRAM_CODE (program));
if (!SCM_PROGRAM_P (program)) if (!SCM_PROGRAM_P (program))
return SCM_INUM0; return SCM_INUM0;

View file

@ -155,8 +155,11 @@ offset from the beginning of the ELF image in 32-bit units."
(define (find-debug-context addr) (define (find-debug-context addr)
"Find and return the debugging context corresponding to the ELF image "Find and return the debugging context corresponding to the ELF image
containing the address @var{addr}. @var{addr} is an integer." containing the address @var{addr}. @var{addr} is an integer. If no ELF
(debug-context-from-image (find-mapped-elf-image addr))) image is found, return @code{#f}. It's possible for an RTL program not
to have an ELF image if the program was defined in as a stub in C."
(and=> (find-mapped-elf-image addr)
debug-context-from-image))
(define (find-elf-symbol elf text-offset) (define (find-elf-symbol elf text-offset)
"Search the symbol table of @var{elf} for the ELF symbol containing "Search the symbol table of @var{elf} for the ELF symbol containing
@ -189,10 +192,11 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
"Find and return the @code{<program-debug-info>} containing "Find and return the @code{<program-debug-info>} containing
@var{addr}, or @code{#f}." @var{addr}, or @code{#f}."
(cond (cond
((find-elf-symbol (debug-context-elf context) ((and context
(find-elf-symbol (debug-context-elf context)
(- addr (- addr
(debug-context-base context) (debug-context-base context)
(debug-context-text-base context))) (debug-context-text-base context))))
=> (lambda (sym) => (lambda (sym)
(make-program-debug-info context (make-program-debug-info context
(and=> (elf-symbol-name sym) (and=> (elf-symbol-name sym)
@ -343,7 +347,8 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
(define* (find-program-arities addr #:optional (define* (find-program-arities addr #:optional
(context (find-debug-context addr))) (context (find-debug-context addr)))
(and=> (and=>
(elf-section-by-name (debug-context-elf context) ".guile.arities") (and context
(elf-section-by-name (debug-context-elf context) ".guile.arities"))
(lambda (sec) (lambda (sec)
(let* ((base (elf-section-offset sec)) (let* ((base (elf-section-offset sec))
(first (find-first-arity context base addr))) (first (find-first-arity context base addr)))
@ -357,7 +362,8 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
(define* (program-minimum-arity addr #:optional (define* (program-minimum-arity addr #:optional
(context (find-debug-context addr))) (context (find-debug-context addr)))
(and=> (and=>
(elf-section-by-name (debug-context-elf context) ".guile.arities") (and context
(elf-section-by-name (debug-context-elf context) ".guile.arities"))
(lambda (sec) (lambda (sec)
(let* ((base (elf-section-offset sec)) (let* ((base (elf-section-offset sec))
(first (find-first-arity context base addr))) (first (find-first-arity context base addr)))
@ -370,7 +376,8 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
(define* (find-program-docstring addr #:optional (define* (find-program-docstring addr #:optional
(context (find-debug-context addr))) (context (find-debug-context addr)))
(and=> (and=>
(elf-section-by-name (debug-context-elf context) ".guile.docstrs") (and context
(elf-section-by-name (debug-context-elf context) ".guile.docstrs"))
(lambda (sec) (lambda (sec)
;; struct docstr { ;; struct docstr {
;; uint32_t pc; ;; uint32_t pc;
@ -409,7 +416,8 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
(maybe-acons 'documentation docstring props)))) (maybe-acons 'documentation docstring props))))
(add-name-and-docstring (add-name-and-docstring
(cond (cond
((elf-section-by-name (debug-context-elf context) ".guile.procprops") ((and context
(elf-section-by-name (debug-context-elf context) ".guile.procprops"))
=> (lambda (sec) => (lambda (sec)
;; struct procprop { ;; struct procprop {
;; uint32_t pc; ;; uint32_t pc;
@ -466,12 +474,13 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
(define* (find-source-for-addr addr #:optional (define* (find-source-for-addr addr #:optional
(context (find-debug-context addr)) (context (find-debug-context addr))
#:key exact?) #:key exact?)
(and=>
(and context
(false-if-exception
(elf->dwarf-context (debug-context-elf context))))
(lambda (dwarf-ctx)
(let* ((base (debug-context-base context)) (let* ((base (debug-context-base context))
(pc (- addr base))) (pc (- addr base)))
(and=>
(false-if-exception
(elf->dwarf-context (debug-context-elf context)))
(lambda (dwarf-ctx)
(or-map (lambda (die) (or-map (lambda (die)
(and=> (and=>
(die-line-prog die) (die-line-prog die)
@ -486,17 +495,18 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
(define* (find-program-die addr #:optional (define* (find-program-die addr #:optional
(context (find-debug-context addr))) (context (find-debug-context addr)))
(and=> (false-if-exception (and=> (and context
(elf->dwarf-context (debug-context-elf context))) (false-if-exception
(elf->dwarf-context (debug-context-elf context))))
(lambda (dwarf-ctx) (lambda (dwarf-ctx)
(find-die-by-pc (read-die-roots dwarf-ctx) (find-die-by-pc (read-die-roots dwarf-ctx)
(- addr (debug-context-base context)))))) (- addr (debug-context-base context))))))
(define* (find-program-sources addr #:optional (define* (find-program-sources addr #:optional
(context (find-debug-context addr))) (context (find-debug-context addr)))
(and=> (cond
(find-program-die addr context) ((find-program-die addr context)
(lambda (die) => (lambda (die)
(let* ((base (debug-context-base context)) (let* ((base (debug-context-base context))
(low-pc (die-ref die 'low-pc)) (low-pc (die-ref die 'low-pc))
(high-pc (die-high-pc die)) (high-pc (die-high-pc die))
@ -516,4 +526,5 @@ section of the ELF image. Returns an ELF symbol, or @code{#f}."
(lp (cons (make-source/dwarf (+ pc base) file line col) (lp (cons (make-source/dwarf (+ pc base) file line col)
sources)) sources))
(reverse sources)))))) (reverse sources))))))
(else '())))))) (else '())))))
(else '())))

View file

@ -1,6 +1,6 @@
;;; Guile VM frame functions ;;; Guile VM frame functions
;;; Copyright (C) 2001, 2005, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. ;;; Copyright (C) 2001, 2005, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
;;; ;;;
;;; This library is free software; you can redistribute it and/or ;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public ;;; modify it under the terms of the GNU Lesser General Public
@ -73,7 +73,7 @@
(define (frame-next-source frame) (define (frame-next-source frame)
(let ((proc (frame-procedure frame))) (let ((proc (frame-procedure frame)))
(if (program? proc) (if (or (program? proc) (rtl-program? proc))
(program-source proc (program-source proc
(frame-instruction-pointer frame) (frame-instruction-pointer frame)
(program-sources-pre-retire proc)) (program-sources-pre-retire proc))
@ -100,7 +100,7 @@
(cons (cons
(or (false-if-exception (procedure-name p)) p) (or (false-if-exception (procedure-name p)) p)
(cond (cond
((and (program? p) ((and (or (program? p) (rtl-program? p))
(program-arguments-alist p (frame-instruction-pointer frame))) (program-arguments-alist p (frame-instruction-pointer frame)))
;; case 1 ;; case 1
=> (lambda (arguments) => (lambda (arguments)

View file

@ -291,9 +291,14 @@
;; the name "program-arguments" is taken by features.c... ;; the name "program-arguments" is taken by features.c...
(define* (program-arguments-alist prog #:optional ip) (define* (program-arguments-alist prog #:optional ip)
"Returns the signature of the given procedure in the form of an association list." "Returns the signature of the given procedure in the form of an association list."
(if (rtl-program? prog)
(or-map (lambda (arity)
(and #t
(arity-arguments-alist arity)))
(or (find-program-arities (rtl-program-code prog)) '()))
(let ((arity (program-arity prog ip))) (let ((arity (program-arity prog ip)))
(and arity (and arity
(arity->arguments-alist prog arity)))) (arity->arguments-alist prog arity)))))
(define* (program-lambda-list prog #:optional ip) (define* (program-lambda-list prog #:optional ip)
"Returns the signature of the given procedure in the form of an argument list." "Returns the signature of the given procedure in the form of an argument list."
@ -322,7 +327,7 @@
(cond (cond
((rtl-program? prog) ((rtl-program? prog)
(map arity-arguments-alist (map arity-arguments-alist
(find-program-arities (rtl-program-code prog)))) (or (find-program-arities (rtl-program-code prog)) '())))
((program? prog) ((program? prog)
(map (lambda (arity) (arity->arguments-alist prog arity)) (map (lambda (arity) (arity->arguments-alist prog arity))
(or (program-arities prog) '()))) (or (program-arities prog) '())))