Changeset 13386
- Timestamp:
- Jan 13, 2010, 2:51:18 PM (15 years ago)
- File:
-
- 1 edited
-
branches/working-0711/ccl/library/core-files.lisp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/working-0711/ccl/library/core-files.lisp
r13179 r13386 96 96 (when *current-core* 97 97 (close-core)) 98 (let* ((sections (read elf-sections pathname))98 (let* ((sections (read-sections pathname)) 99 99 (core (make-core-info :pathname pathname :sections sections))) 100 100 (ecase method … … 110 110 111 111 ;; Kinda stupid to call external program for this... 112 (defun read elf-sections (pathname)112 (defun read-sections (pathname) 113 113 (flet ((split (line start end) 114 114 (loop while (setq start (position-if-not #'whitespacep line :start start :end end)) … … 122 122 (let* ((file (native-translated-namestring pathname)) 123 123 (string (with-output-to-string (output) 124 (ccl:run-program "readelf" `("--sections" ,file) :output output))) 124 #+readelf (ccl:run-program "readelf" `("--sections" "--wide" ,file) :output output) 125 #-readelf (ccl:run-program "objdump" `("-h" "-w" ,file) :output output))) 126 (header-pos (or #+readelf (position #\[ string) 127 #-readelf (search "Idx Name" string) 128 (error "Cannot parse: ~%~a" string))) 125 129 (sections (loop 126 for start = (1+ (position #\newline string 127 :start (1+ (position #\newline string 128 :start (position #\[ string))))) 129 then next 130 for next = (1+ (position #\newline string 131 :start (1+ (position #\newline string :start start)))) 132 while (eql #\space (aref string next)) 130 for start = (1+ (position #\newline string :start header-pos)) then (1+ end) 131 for end = (or (position #\newline string :start start) (length string)) 132 while (and (< start end) (eql #\space (aref string start))) 133 133 nconc 134 (destructuring-bind (number name type address filepos size &optional ent-size flags link info align) 135 (split string start next) 136 (assert (and (eql (char number 0) #\[) (eql (char number (1- (length number))) #\]))) 137 (setq number (read-from-string number :start 1 :end (1- (length number)))) 138 (when (eql number 0) 139 (shiftf align info link flags ent-size size filepos address type name "")) 140 (setq address (parse-integer address :radix 16)) 141 (setq filepos (parse-integer filepos :radix 16)) 142 (setq size (parse-integer size :radix 16)) 143 (setq ent-size (parse-integer ent-size :radix 16)) 144 (unless (eql size 0) 145 (assert (and (equal link "0") (equal info "0") (equal align "1"))) 146 (list (list address filepos size)))))) 134 (multiple-value-bind (name address filepos size) 135 #+readelf 136 (destructuring-bind (number name type address filepos size &rest flags) 137 (split string start end) 138 (declare (ignore flags)) 139 (assert (and (eql (char number 0) #\[) (eql (char number (1- (length number))) #\]))) 140 (setq number (read-from-string number :start 1 :end (1- (length number)))) 141 (when (eql number 0) 142 (shiftf size filepos address type)) 143 (values name address filepos size)) 144 #-readelf 145 (destructuring-bind (number name size address lma filepos &rest flags) 146 (split string start end) 147 (declare (ignore lma flags)) 148 (parse-integer number :radix 10) ;; error checking only 149 (values name address filepos size)) 150 (unless (or (equal name "") (eql (char name 0) #\.)) 151 (setq address (parse-integer address :radix 16)) 152 (setq filepos (parse-integer filepos :radix 16)) 153 (setq size (parse-integer size :radix 16)) 154 (unless (eql size 0) 155 (list (list address filepos size))))))) 147 156 (sections (cons (list most-positive-fixnum 0 0) sections));; hack for loop below 148 157 (sections (sort sections #'< :key #'car));; sort by address … … 161 170 (setq cur-address address cur-filepos filepos cur-end (+ address size))))))) 162 171 (coerce sections 'vector)))) 172 163 173 164 174 (declaim (inline core-ivector-readb core-ivector-readw core-ivector-readl core-ivector-readq
Note:
See TracChangeset
for help on using the changeset viewer.
